[cfe-commits] r100429 - in /cfe/trunk: lib/Checker/Environment.cpp test/Analysis/inline4.c
Zhongxing Xu
xuzhongxing at gmail.com
Mon Apr 5 06:16:29 PDT 2010
Author: zhongxingxu
Date: Mon Apr 5 08:16:29 2010
New Revision: 100429
URL: http://llvm.org/viewvc/llvm-project?rev=100429&view=rev
Log:
Always assume block-level expressions in the caller are alive when analyzing
the callee.
Added:
cfe/trunk/test/Analysis/inline4.c
Modified:
cfe/trunk/lib/Checker/Environment.cpp
Modified: cfe/trunk/lib/Checker/Environment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/Environment.cpp?rev=100429&r1=100428&r2=100429&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/Environment.cpp (original)
+++ cfe/trunk/lib/Checker/Environment.cpp Mon Apr 5 08:16:29 2010
@@ -96,6 +96,19 @@
};
} // end anonymous namespace
+static bool isBlockExprInCallers(const Stmt *E, const LocationContext *LC) {
+ const LocationContext *ParentLC = LC->getParent();
+ while (ParentLC) {
+ CFG &C = *ParentLC->getCFG();
+ if (C.isBlkExpr(E))
+ return true;
+ ParentLC = ParentLC->getParent();
+ }
+
+ return false;
+}
+
+
// RemoveDeadBindings:
// - Remove subexpression bindings.
// - Remove dead block expression bindings.
@@ -122,13 +135,27 @@
I != E; ++I) {
const Stmt *BlkExpr = I.getKey();
+ const SVal &X = I.getData();
+
+ // Block-level expressions in callers are assumed always live.
+ if (isBlockExprInCallers(BlkExpr, SymReaper.getLocationContext())) {
+ NewEnv.ExprBindings = F.Add(NewEnv.ExprBindings, BlkExpr, X);
+
+ if (isa<loc::MemRegionVal>(X)) {
+ const MemRegion* R = cast<loc::MemRegionVal>(X).getRegion();
+ DRoots.push_back(R);
+ }
+
+ // Mark all symbols in the block expr's value live.
+ MarkLiveCallback cb(SymReaper);
+ ST->scanReachableSymbols(X, cb);
+ continue;
+ }
// Not a block-level expression?
if (!C.isBlkExpr(BlkExpr))
continue;
- const SVal &X = I.getData();
-
if (SymReaper.isLive(S, BlkExpr)) {
// Copy the binding to the new map.
NewEnv.ExprBindings = F.Add(NewEnv.ExprBindings, BlkExpr, X);
Added: cfe/trunk/test/Analysis/inline4.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inline4.c?rev=100429&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/inline4.c (added)
+++ cfe/trunk/test/Analysis/inline4.c Mon Apr 5 08:16:29 2010
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -analyze -inline-call -analyzer-store region -analyze-function f -verify %s
+
+int g(int a) {
+ return a;
+}
+
+int f(int a) {
+ // Do not remove block-level expression bindings of caller when analyzing
+ // in the callee.
+ if (1 && g(a)) // The binding of '1 && g(a)' which is an UndefinedVal
+ // carries important information.
+ return 1;
+ return 0;
+}
More information about the cfe-commits
mailing list