[llvm-branch-commits] [cfe-branch] r294050 - Merging r293043:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Feb 3 13:45:29 PST 2017


Author: hans
Date: Fri Feb  3 15:45:29 2017
New Revision: 294050

URL: http://llvm.org/viewvc/llvm-project?rev=294050&view=rev
Log:
Merging r293043:
------------------------------------------------------------------------
r293043 | dergachev | 2017-01-25 02:21:45 -0800 (Wed, 25 Jan 2017) | 12 lines

[analyzer] Fix MacOSXAPIChecker fp with static locals seen from nested blocks.

This is an attempt to avoid new false positives caused by the reverted r292800,
however the scope of the fix is significantly reduced - some variables are still
in incorrect memory spaces.

Relevant test cases added.

rdar://problem/30105546
rdar://problem/30156693
Differential revision: https://reviews.llvm.org/D28946

------------------------------------------------------------------------

Added:
    cfe/branches/release_40/test/Analysis/null-deref-static.m
      - copied unchanged from r293043, cfe/trunk/test/Analysis/null-deref-static.m
Modified:
    cfe/branches/release_40/   (props changed)
    cfe/branches/release_40/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
    cfe/branches/release_40/lib/StaticAnalyzer/Core/MemRegion.cpp
    cfe/branches/release_40/lib/StaticAnalyzer/Core/RegionStore.cpp
    cfe/branches/release_40/test/Analysis/dispatch-once.m

Propchange: cfe/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Feb  3 15:45:29 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:291850,291853,291865,291871,291877,291879,291881,291907,291955,291963-291964,292032,292052,292183,292194,292247,292265,292497,292555,292558-292559,292561,292590,292800,292847,292874,292991,293134,293360,293369,293596,293678,293787
+/cfe/trunk:291850,291853,291865,291871,291877,291879,291881,291907,291955,291963-291964,292032,292052,292183,292194,292247,292265,292497,292555,292558-292559,292561,292590,292800,292847,292874,292991,293043,293134,293360,293369,293596,293678,293787
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_40/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp?rev=294050&r1=294049&r2=294050&view=diff
==============================================================================
--- cfe/branches/release_40/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp (original)
+++ cfe/branches/release_40/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp Fri Feb  3 15:45:29 2017
@@ -94,11 +94,18 @@ void MacOSXAPIChecker::CheckDispatchOnce
   bool SuggestStatic = false;
   os << "Call to '" << FName << "' uses";
   if (const VarRegion *VR = dyn_cast<VarRegion>(RB)) {
+    const VarDecl *VD = VR->getDecl();
+    // FIXME: These should have correct memory space and thus should be filtered
+    // out earlier. This branch only fires when we're looking from a block,
+    // which we analyze as a top-level declaration, onto a static local
+    // in a function that contains the block.
+    if (VD->isStaticLocal())
+      return;
     // We filtered out globals earlier, so it must be a local variable
     // or a block variable which is under UnknownSpaceRegion.
     if (VR != R)
       os << " memory within";
-    if (VR->getDecl()->hasAttr<BlocksAttr>())
+    if (VD->hasAttr<BlocksAttr>())
       os << " the block variable '";
     else
       os << " the local variable '";

Modified: cfe/branches/release_40/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=294050&r1=294049&r2=294050&view=diff
==============================================================================
--- cfe/branches/release_40/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/branches/release_40/lib/StaticAnalyzer/Core/MemRegion.cpp Fri Feb  3 15:45:29 2017
@@ -816,9 +816,11 @@ const VarRegion* MemRegionManager::getVa
 
     const StackFrameContext *STC = V.get<const StackFrameContext*>();
 
-    if (!STC)
+    if (!STC) {
+      // FIXME: Assign a more sensible memory space to static locals
+      // we see from within blocks that we analyze as top-level declarations.
       sReg = getUnknownRegion();
-    else {
+    } else {
       if (D->hasLocalStorage()) {
         sReg = isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)
                ? static_cast<const MemRegion*>(getStackArgumentsRegion(STC))

Modified: cfe/branches/release_40/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=294050&r1=294049&r2=294050&view=diff
==============================================================================
--- cfe/branches/release_40/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/branches/release_40/lib/StaticAnalyzer/Core/RegionStore.cpp Fri Feb  3 15:45:29 2017
@@ -1849,6 +1849,8 @@ SVal RegionStoreManager::getBindingForVa
 
     // Function-scoped static variables are default-initialized to 0; if they
     // have an initializer, it would have been processed by now.
+    // FIXME: This is only true when we're starting analysis from main().
+    // We're losing a lot of coverage here.
     if (isa<StaticGlobalSpaceRegion>(MS))
       return svalBuilder.makeZeroVal(T);
 

Modified: cfe/branches/release_40/test/Analysis/dispatch-once.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/test/Analysis/dispatch-once.m?rev=294050&r1=294049&r2=294050&view=diff
==============================================================================
--- cfe/branches/release_40/test/Analysis/dispatch-once.m (original)
+++ cfe/branches/release_40/test/Analysis/dispatch-once.m Fri Feb  3 15:45:29 2017
@@ -107,3 +107,10 @@ void test_block_var_from_outside_block()
   };
   dispatch_once(&once, ^{}); // expected-warning{{Call to 'dispatch_once' uses the block variable 'once' for the predicate value.}}
 }
+
+void test_static_var_from_outside_block() {
+  static dispatch_once_t once;
+  ^{
+    dispatch_once(&once, ^{}); // no-warning
+  };
+}




More information about the llvm-branch-commits mailing list