[cfe-commits] r150207 - in /cfe/trunk: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp test/Analysis/inline-not-supported.c
Ted Kremenek
kremenek at apple.com
Thu Feb 9 13:59:52 PST 2012
Author: kremenek
Date: Thu Feb 9 15:59:52 2012
New Revision: 150207
URL: http://llvm.org/viewvc/llvm-project?rev=150207&view=rev
Log:
[analyzer] Proactively avoid inlining vararg functions and blocks until we properly support them.
Added:
cfe/trunk/test/Analysis/inline-not-supported.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=150207&r1=150206&r2=150207&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Thu Feb 9 15:59:52 2012
@@ -309,6 +309,30 @@
}
+// For now, skip inlining variadic functions.
+// We also don't inline blocks.
+static bool shouldInlineCall(const CallExpr *CE, ExprEngine &Eng) {
+ if (!Eng.getAnalysisManager().shouldInlineCall())
+ return false;
+ QualType callee = CE->getCallee()->getType();
+ const FunctionProtoType *FT = 0;
+ if (const PointerType *PT = callee->getAs<PointerType>())
+ FT = dyn_cast<FunctionProtoType>(PT->getPointeeType());
+ else if (const BlockPointerType *BT = callee->getAs<BlockPointerType>()) {
+ // FIXME: inline blocks.
+ // FT = dyn_cast<FunctionProtoType>(BT->getPointeeType());
+ (void) BT;
+ return false;
+ }
+
+ // If we have no prototype, assume the function is okay.
+ if (!FT)
+ return true;
+
+ // Skip inlining of variadic functions.
+ return !FT->isVariadic();
+}
+
void ExprEngine::VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred,
ExplodedNodeSet &dst) {
// Perform the previsit of the CallExpr.
@@ -325,7 +349,7 @@
: Eng(eng), CE(ce) {}
virtual void expandGraph(ExplodedNodeSet &Dst, ExplodedNode *Pred) {
// Should we inline the call?
- if (Eng.getAnalysisManager().shouldInlineCall() &&
+ if (shouldInlineCall(CE, Eng) &&
Eng.InlineCall(Dst, CE, Pred)) {
return;
}
Added: cfe/trunk/test/Analysis/inline-not-supported.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inline-not-supported.c?rev=150207&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/inline-not-supported.c (added)
+++ cfe/trunk/test/Analysis/inline-not-supported.c Thu Feb 9 15:59:52 2012
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fblocks -analyze -analyzer-checker=core -analyzer-inline-call -analyzer-store region -verify %s
+
+// For now, don't inline varargs.
+void foo(int *x, ...) {
+ *x = 1;
+}
+
+void bar() {
+ foo(0, 2); // no-warning
+}
+
+// For now, don't inline vararg blocks.
+void (^baz)(int *x, ...) = ^(int *x, ...) { *x = 1; };
+
+void taz() {
+ baz(0, 2); // no-warning
+}
+
+// For now, don't inline blocks.
+void (^qux)(int *p) = ^(int *p) { *p = 1; };
+void test_qux() {
+ qux(0); // no-warning
+}
+
+
+void test_analyzer_is_running() {
+ int *p = 0;
+ *p = 0xDEADBEEF; // expected-warning {{null}}
+}
More information about the cfe-commits
mailing list