diff options
| author | George Karpenkov <ekarpenkov@apple.com> | 2018-03-06 00:18:21 +0000 |
|---|---|---|
| committer | George Karpenkov <ekarpenkov@apple.com> | 2018-03-06 00:18:21 +0000 |
| commit | 15e814f687e42c3bc41e6454c86087eb3373d39f (patch) | |
| tree | f3173d34e4b5e47d81c8a8f3c9cd61ec46c1ca03 | |
| parent | 39e54cb7b750b6d95214299bae309b5e07e23835 (diff) | |
| download | bcm5719-llvm-15e814f687e42c3bc41e6454c86087eb3373d39f.tar.gz bcm5719-llvm-15e814f687e42c3bc41e6454c86087eb3373d39f.zip | |
[analyzer] [quickfix] Prevent a crash in NamedDecl::getName()
llvm-svn: 326755
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp | 6 | ||||
| -rw-r--r-- | clang/test/gcdasyncsemaphorechecker_test.m | 36 |
2 files changed, 39 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp index 48e9e1e7625..23ef032bb05 100644 --- a/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp @@ -88,9 +88,11 @@ void GCDAsyncSemaphoreChecker::checkASTCodeBody(const Decl *D, BugReporter &BR) const { // The pattern is very common in tests, and it is OK to use it there. - if (const auto* ND = dyn_cast<NamedDecl>(D)) - if (ND->getName().startswith("test")) + if (const auto* ND = dyn_cast<NamedDecl>(D)) { + std::string DeclName = ND->getNameAsString(); + if (StringRef(DeclName).startswith("test")) return; + } const char *SemaphoreBinding = "semaphore_name"; auto SemaphoreCreateM = callExpr(callsName("dispatch_semaphore_create")); diff --git a/clang/test/gcdasyncsemaphorechecker_test.m b/clang/test/gcdasyncsemaphorechecker_test.m index e65ae3d7feb..a82545a3b6a 100644 --- a/clang/test/gcdasyncsemaphorechecker_test.m +++ b/clang/test/gcdasyncsemaphorechecker_test.m @@ -1,5 +1,14 @@ // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.osx.GCDAsyncSemaphore %s -fblocks -verify -// +typedef signed char BOOL; +@protocol NSObject - (BOOL)isEqual:(id)object; @end +@interface NSObject <NSObject> {} ++(id)alloc; +-(id)init; +-(id)autorelease; +-(id)copy; +-(id)retain; +@end + typedef int dispatch_semaphore_t; typedef void (^block_t)(); @@ -166,4 +175,29 @@ void warn_with_cast() { dispatch_semaphore_wait((int)sema, 100); // expected-warning{{Possible semaphore performance anti-pattern}} } +@interface Test1 : NSObject +-(void)use_method_warn; +-(void)testNoWarn; +@end + +@implementation Test1 + +-(void)use_method_warn { + dispatch_semaphore_t sema = dispatch_semaphore_create(0); + + func(^{ + dispatch_semaphore_signal(sema); + }); + dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore performance anti-pattern}} +} + +-(void)testNoWarn { + dispatch_semaphore_t sema = dispatch_semaphore_create(0); + + func(^{ + dispatch_semaphore_signal(sema); + }); + dispatch_semaphore_wait(sema, 100); +} +@end |

