UninitializedValues.h revision e0dbda136444b2f3550a421f4436d438230c732f
1//===- UninitializedValues.h - unintialized values analysis ----*- C++ --*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides the interface for the Unintialized Values analysis,
11// a flow-sensitive analysis that detects when variable values are unintialized.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_UNITVALS_H
16#define LLVM_CLANG_UNITVALS_H
17
18#include "clang/Analysis/Support/BlkExprDeclBitVector.h"
19#include "clang/Analysis/FlowSensitive/DataflowValues.h"
20
21namespace clang {
22
23  class BlockVarDecl;
24  class Expr;
25  class DeclRefExpr;
26  class VarDecl;
27
28/// UninitializedValues_ValueTypes - Utility class to wrap type declarations
29///   for dataflow values and dataflow analysis state for the
30///   Unitialized Values analysis.
31class UninitializedValues_ValueTypes {
32public:
33
34  struct ObserverTy;
35
36  struct AnalysisDataTy : public StmtDeclBitVector_Types::AnalysisDataTy {
37    AnalysisDataTy() : Observer(NULL), FullUninitTaint(true) {}
38    virtual ~AnalysisDataTy() {};
39
40    ObserverTy* Observer;
41    bool FullUninitTaint;
42  };
43
44  typedef StmtDeclBitVector_Types::ValTy ValTy;
45
46  //===--------------------------------------------------------------------===//
47  // ObserverTy - Observer for querying DeclRefExprs that use an uninitalized
48  //   value.
49  //===--------------------------------------------------------------------===//
50
51  struct ObserverTy {
52    virtual ~ObserverTy();
53    virtual void ObserveDeclRefExpr(ValTy& Val, AnalysisDataTy& AD,
54                                    DeclRefExpr* DR, VarDecl* VD) = 0;
55  };
56};
57
58/// UninitializedValues - Objects of this class encapsulate dataflow analysis
59///  information regarding what variable declarations in a function are
60///  potentially unintialized.
61class UninitializedValues :
62  public DataflowValues<UninitializedValues_ValueTypes> {
63public:
64  typedef UninitializedValues_ValueTypes::ObserverTy ObserverTy;
65
66  UninitializedValues(CFG &cfg) { getAnalysisData().setCFG(cfg); }
67
68  /// IntializeValues - Create initial dataflow values and meta data for
69  ///  a given CFG.  This is intended to be called by the dataflow solver.
70  void InitializeValues(const CFG& cfg);
71};
72
73} // end namespace clang
74#endif
75