r176577 - [analyzer] Pass the correct Expr to the bug reporter visitors when dealing with CompoundLiteralExpr

Anna Zaks ganna at apple.com
Wed Mar 6 12:26:03 PST 2013


Author: zaks
Date: Wed Mar  6 14:26:02 2013
New Revision: 176577

URL: http://llvm.org/viewvc/llvm-project?rev=176577&view=rev
Log:
[analyzer] Pass the correct Expr to the bug reporter visitors when dealing with CompoundLiteralExpr

This allows us to trigger the IDC visitor in the added test case.

Added:
    cfe/trunk/test/Analysis/inlining/inline-defensive-checks.m
Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp?rev=176577&r1=176576&r2=176577&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp Wed Mar  6 14:26:02 2013
@@ -57,10 +57,11 @@ void AttrNonNullChecker::checkPreCall(co
     if (!DV)
       continue;
 
+    const Expr *ArgE = Call.getArgExpr(idx);
+    
     if (!DV->getAs<Loc>()) {
       // If the argument is a union type, we want to handle a potential
       // transparent_union GCC extension.
-      const Expr *ArgE = Call.getArgExpr(idx);
       if (!ArgE)
         continue;
 
@@ -77,7 +78,13 @@ void AttrNonNullChecker::checkPreCall(co
         DV = V.getAs<DefinedSVal>();
         assert(++CSV_I == CSV->end());
         if (!DV)
-          continue;        
+          continue;
+        // Retrieve the corresponding expression.
+        if (const CompoundLiteralExpr *CE = dyn_cast<CompoundLiteralExpr>(ArgE))
+          if (const InitListExpr *IE =
+                dyn_cast<InitListExpr>(CE->getInitializer()))
+             ArgE = dyn_cast<Expr>(*(IE->begin()));
+
       } else {
         // FIXME: Handle LazyCompoundVals?
         continue;
@@ -106,7 +113,7 @@ void AttrNonNullChecker::checkPreCall(co
 
         // Highlight the range of the argument that was null.
         R->addRange(Call.getArgSourceRange(idx));
-        if (const Expr *ArgE = Call.getArgExpr(idx))
+        if (ArgE)
           bugreporter::trackNullOrUndefValue(errorNode, ArgE, *R);
         // Emit the bug report.
         C.emitReport(R);

Added: cfe/trunk/test/Analysis/inlining/inline-defensive-checks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/inline-defensive-checks.m?rev=176577&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/inlining/inline-defensive-checks.m (added)
+++ cfe/trunk/test/Analysis/inlining/inline-defensive-checks.m Wed Mar  6 14:26:02 2013
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config suppress-inlined-defensive-checks=true -verify %s
+
+typedef signed char BOOL;
+typedef struct objc_class *Class;
+typedef struct objc_object {
+  Class isa;
+} *id;
+ at protocol NSObject  - (BOOL)isEqual:(id)object; @end
+ at interface NSObject <NSObject> {}
++(id)alloc;
++(id)new;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+- (Class)class;
+-(id)retain;
+ at end
+
+// expected-no-diagnostics
+// Check that inline defensive checks is triggered for null expressions
+// within CompoundLiteralExpr.
+typedef union {
+  struct dispatch_object_s *_do;
+  struct dispatch_source_s *_ds;
+} dispatch_object_t __attribute__((__transparent_union__));
+typedef struct dispatch_source_s *dispatch_source_t;
+
+extern __attribute__((visibility("default"))) __attribute__((__nonnull__)) __attribute__((__nothrow__))
+void
+dispatch_resume(dispatch_object_t object);
+
+ at interface AppDelegate : NSObject {
+ at protected
+	dispatch_source_t p;
+}
+ at end
+ at implementation AppDelegate
+- (void)updateDeleteTimer {
+	if (p != ((void*)0))
+		;
+}
+- (void)createAndStartDeleteTimer {
+  [self updateDeleteTimer];
+  dispatch_resume(p); // no warning
+}
+ at end





More information about the cfe-commits mailing list