[clang] 040c39d - [analyzer] Fix false positive on introspection of a block's internal layout.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 6 13:24:32 PST 2019


Author: Artem Dergachev
Date: 2019-12-06T13:24:20-08:00
New Revision: 040c39d50fb9c60de9020caf86e1a1fccfd6f861

URL: https://github.com/llvm/llvm-project/commit/040c39d50fb9c60de9020caf86e1a1fccfd6f861
DIFF: https://github.com/llvm/llvm-project/commit/040c39d50fb9c60de9020caf86e1a1fccfd6f861.diff

LOG: [analyzer] Fix false positive on introspection of a block's internal layout.

When implementation of the block runtime is available, we should not
warn that block layout fields are uninitialized simply because they're
on the stack.

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Core/RegionStore.cpp
    clang/test/Analysis/blocks.m

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 5d2ef59e2d66..4797f564a837 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1951,7 +1951,8 @@ RegionStoreManager::getBindingForFieldOrElementCommon(RegionBindingsConstRef B,
     if (hasSymbolicIndex)
       return UnknownVal();
 
-    if (!hasPartialLazyBinding)
+    // Additionally allow introspection of a block's internal layout.
+    if (!hasPartialLazyBinding && !isa<BlockDataRegion>(R->getBaseRegion()))
       return UndefinedVal();
   }
 

diff  --git a/clang/test/Analysis/blocks.m b/clang/test/Analysis/blocks.m
index 98d0f8a2ebaa..a21a605ffa61 100644
--- a/clang/test/Analysis/blocks.m
+++ b/clang/test/Analysis/blocks.m
@@ -47,6 +47,10 @@ - (id)initWithFormat:(NSString *)format arguments:(va_list)argList __attribute__
 aslclient asl_open(const char *ident, const char *facility, uint32_t opts);
 int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __attribute__((__format__ (__printf__, 4, 5)));
 
+struct Block_layout {
+  int flags;
+};
+
 //===----------------------------------------------------------------------===//
 // Begin actual test cases.
 //===----------------------------------------------------------------------===//
@@ -241,3 +245,8 @@ void call_block_with_fewer_arguments() {
   b(); // expected-warning {{Block taking 1 argument is called with fewer (0)}}
 }
 #endif
+
+int getBlockFlags() {
+  int x = 0;
+  return ((struct Block_layout *)^{ (void)x; })->flags; // no-warning
+}


        


More information about the cfe-commits mailing list