[cfe-commits] r91412 - in /cfe/trunk: lib/Analysis/CheckDeadStores.cpp test/Analysis/dead-stores.cpp
Ted Kremenek
kremenek at apple.com
Mon Dec 14 20:12:13 PST 2009
Author: kremenek
Date: Mon Dec 14 22:12:12 2009
New Revision: 91412
URL: http://llvm.org/viewvc/llvm-project?rev=91412&view=rev
Log:
Until we can make the dead stores checker smarter, dont' emit dead store warnings for C++ objects (whose constructors/destructors have possible side-effects).
Modified:
cfe/trunk/lib/Analysis/CheckDeadStores.cpp
cfe/trunk/test/Analysis/dead-stores.cpp
Modified: cfe/trunk/lib/Analysis/CheckDeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckDeadStores.cpp?rev=91412&r1=91411&r2=91412&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Mon Dec 14 22:12:12 2009
@@ -186,6 +186,10 @@
if (V->hasLocalStorage())
if (Expr* E = V->getInit()) {
+ // Don't warn on C++ objects (yet) until we can show that their
+ // constructors/destructors don't have side effects.
+ if (isa<CXXConstructExpr>(E))
+ return;
// A dead initialization is a variable that is dead after it
// is initialized. We don't flag warnings for those variables
// marked 'unused'.
Modified: cfe/trunk/test/Analysis/dead-stores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.cpp?rev=91412&r1=91411&r2=91412&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.cpp (original)
+++ cfe/trunk/test/Analysis/dead-stores.cpp Mon Dec 14 22:12:12 2009
@@ -4,6 +4,10 @@
// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -warn-dead-stores -verify %s
// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -warn-dead-stores -verify %s
+//===----------------------------------------------------------------------===//
+// Basic dead store checking (but in C++ mode).
+//===----------------------------------------------------------------------===//
+
int j;
void f1() {
int x = 4;
@@ -17,3 +21,19 @@
break;
}
}
+
+//===----------------------------------------------------------------------===//
+// Dead store checking involving constructors.
+//===----------------------------------------------------------------------===//
+
+class Test1 {
+ int &x;
+public:
+ Test1(int &y) : x(y) {}
+ ~Test1() { ++x; }
+};
+
+int test_ctor_1(int x) {
+ { Test1 a(x); } // no-warning
+ return x;
+}
More information about the cfe-commits
mailing list