Skip to content

Commit 040c39d

Browse files
committed
[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.
1 parent d5abaaf commit 040c39d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,8 @@ RegionStoreManager::getBindingForFieldOrElementCommon(RegionBindingsConstRef B,
19511951
if (hasSymbolicIndex)
19521952
return UnknownVal();
19531953

1954-
if (!hasPartialLazyBinding)
1954+
// Additionally allow introspection of a block's internal layout.
1955+
if (!hasPartialLazyBinding && !isa<BlockDataRegion>(R->getBaseRegion()))
19551956
return UndefinedVal();
19561957
}
19571958

clang/test/Analysis/blocks.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ - (id)initWithFormat:(NSString *)format arguments:(va_list)argList __attribute__
4747
aslclient asl_open(const char *ident, const char *facility, uint32_t opts);
4848
int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __attribute__((__format__ (__printf__, 4, 5)));
4949

50+
struct Block_layout {
51+
int flags;
52+
};
53+
5054
//===----------------------------------------------------------------------===//
5155
// Begin actual test cases.
5256
//===----------------------------------------------------------------------===//
@@ -241,3 +245,8 @@ void call_block_with_fewer_arguments() {
241245
b(); // expected-warning {{Block taking 1 argument is called with fewer (0)}}
242246
}
243247
#endif
248+
249+
int getBlockFlags() {
250+
int x = 0;
251+
return ((struct Block_layout *)^{ (void)x; })->flags; // no-warning
252+
}

0 commit comments

Comments
 (0)