[cfe-commits] r90516 - in /cfe/trunk: include/clang/Analysis/PathSensitive/AnalysisContext.h include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/AnalysisContext.cpp
Ted Kremenek
kremenek at apple.com
Thu Dec 3 18:03:51 PST 2009
Author: kremenek
Date: Thu Dec 3 20:03:51 2009
New Revision: 90516
URL: http://llvm.org/viewvc/llvm-project?rev=90516&view=rev
Log:
Allow BlockInvocationContext to wrap either a BlockDecl* or a BlockDataRegion*, giving us choice in our degree of context-sensitivity.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
cfe/trunk/lib/Analysis/AnalysisContext.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h?rev=90516&r1=90515&r2=90516&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h Thu Dec 3 20:03:51 2009
@@ -15,9 +15,10 @@
#ifndef LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H
#define LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H
-#include "clang/AST/Stmt.h"
+#include "clang/AST/Decl.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Allocator.h"
@@ -30,6 +31,7 @@
class ParentMap;
class ImplicitParamDecl;
class LocationContextManager;
+class BlockDataRegion;
/// AnalysisContext contains the context data for the function or method under
/// analysis.
@@ -177,21 +179,36 @@
};
class BlockInvocationContext : public LocationContext {
- const BlockDecl *BD;
+ llvm::PointerUnion<const BlockDataRegion *, const BlockDecl *> Data;
friend class LocationContextManager;
+
+ BlockInvocationContext(AnalysisContext *ctx, const LocationContext *parent,
+ const BlockDataRegion *br)
+ : LocationContext(Block, ctx, parent), Data(br) {}
+
BlockInvocationContext(AnalysisContext *ctx, const LocationContext *parent,
const BlockDecl *bd)
- : LocationContext(Block, ctx, parent), BD(bd) {}
+ : LocationContext(Block, ctx, parent), Data(bd) {}
public:
~BlockInvocationContext() {}
- const BlockDecl *getBlockDecl() const { return BD; }
+ const BlockDataRegion *getBlockRegion() const {
+ return Data.is<const BlockDataRegion*>() ?
+ Data.get<const BlockDataRegion*>() : 0;
+ }
+
+ const BlockDecl *getBlockDecl() const;
void Profile(llvm::FoldingSetNodeID &ID);
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
+ const LocationContext *parent, const BlockDataRegion *br){
+ ProfileCommon(ID, Block, ctx, parent, br);
+ }
+
+ static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
const LocationContext *parent, const BlockDecl *bd) {
ProfileCommon(ID, Block, ctx, parent, bd);
}
@@ -216,7 +233,7 @@
const BlockInvocationContext *
getBlockInvocation(AnalysisContext *ctx, const LocationContext *parent,
- const BlockDecl *BD);
+ const BlockDataRegion *BR);
/// Discard all previously created LocationContext objects.
void clear();
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h?rev=90516&r1=90515&r2=90516&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Thu Dec 3 20:03:51 2009
@@ -340,6 +340,8 @@
const BlockTextRegion *getCodeRegion() const { return BC; }
+ const BlockDecl *getDecl() const { return BC->getDecl(); }
+
class referenced_vars_iterator {
const MemRegion * const *R;
public:
Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=90516&r1=90515&r2=90516&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Thu Dec 3 20:03:51 2009
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Analysis/PathSensitive/AnalysisContext.h"
+#include "clang/Analysis/PathSensitive/MemRegion.h"
#include "clang/Analysis/Analyses/LiveVariables.h"
#include "clang/Analysis/CFG.h"
#include "clang/AST/Decl.h"
@@ -80,6 +81,12 @@
return AC;
}
+const BlockDecl *BlockInvocationContext::getBlockDecl() const {
+ return Data.is<const BlockDataRegion*>() ?
+ Data.get<const BlockDataRegion*>()->getDecl()
+ : Data.get<const BlockDecl*>();
+}
+
//===----------------------------------------------------------------------===//
// FoldingSet profiling.
//===----------------------------------------------------------------------===//
@@ -104,7 +111,11 @@
}
void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, getAnalysisContext(), getParent(), BD);
+ if (const BlockDataRegion *BR = getBlockRegion())
+ Profile(ID, getAnalysisContext(), getParent(), BR);
+ else
+ Profile(ID, getAnalysisContext(), getParent(),
+ Data.get<const BlockDecl*>());
}
//===----------------------------------------------------------------------===//
@@ -146,8 +157,10 @@
const BlockInvocationContext *
LocationContextManager::getBlockInvocation(AnalysisContext *ctx,
const LocationContext *parent,
- const BlockDecl *BD) {
- return getLocationContext<BlockInvocationContext, BlockDecl>(ctx, parent, BD);
+ const BlockDataRegion *BR) {
+ return getLocationContext<BlockInvocationContext, BlockDataRegion>(ctx,
+ parent,
+ BR);
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list