Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] 'unused-but-set-variable' warning should not apply to __block…
… objective-c pointers The __block Objective-C pointers can be set but not used due to a commonly used lifetime extension pattern in Objective-C. Differential Revision: https://reviews.llvm.org/D112850
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %clang_cc1 -triple x86_64-apple-macos11 -fsyntax-only -fobjc-arc -fblocks -verify -Wunused-but-set-variable -Wno-objc-root-class %s | ||
|
||
typedef struct dispatch_queue_s *dispatch_queue_t; | ||
|
||
typedef void (^dispatch_block_t)(void); | ||
|
||
void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); | ||
|
||
extern __attribute__((visibility("default"))) struct dispatch_queue_s _dispatch_main_q; | ||
|
||
id getFoo(); | ||
|
||
@protocol P | ||
|
||
@end | ||
|
||
@interface I | ||
|
||
@end | ||
|
||
void test() { | ||
// no diagnostics | ||
__block id x = getFoo(); | ||
__block id<P> y = x; | ||
__block I *z = (I *)x; | ||
// diagnose non-block variables | ||
id x2 = getFoo(); // expected-warning {{variable 'x2' set but not used}} | ||
dispatch_async(&_dispatch_main_q, ^{ | ||
x = ((void *)0); | ||
y = x; | ||
z = ((void *)0); | ||
}); | ||
x2 = getFoo(); | ||
} |