r326755 - [analyzer] [quickfix] Prevent a crash in NamedDecl::getName()
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 5 16:18:21 PST 2018
Author: george.karpenkov
Date: Mon Mar 5 16:18:21 2018
New Revision: 326755
URL: http://llvm.org/viewvc/llvm-project?rev=326755&view=rev
Log:
[analyzer] [quickfix] Prevent a crash in NamedDecl::getName()
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
cfe/trunk/test/gcdasyncsemaphorechecker_test.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp?rev=326755&r1=326754&r2=326755&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp Mon Mar 5 16:18:21 2018
@@ -88,9 +88,11 @@ void GCDAsyncSemaphoreChecker::checkASTC
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"));
Modified: cfe/trunk/test/gcdasyncsemaphorechecker_test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/gcdasyncsemaphorechecker_test.m?rev=326755&r1=326754&r2=326755&view=diff
==============================================================================
--- cfe/trunk/test/gcdasyncsemaphorechecker_test.m (original)
+++ cfe/trunk/test/gcdasyncsemaphorechecker_test.m Mon Mar 5 16:18:21 2018
@@ -1,5 +1,14 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.osx.GCDAsyncSemaphore %s -fblocks -verify
-//
+typedef signed char BOOL;
+ at protocol NSObject - (BOOL)isEqual:(id)object; @end
+ at interface NSObject <NSObject> {}
++(id)alloc;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+-(id)retain;
+ at 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}}
}
+ at interface Test1 : NSObject
+-(void)use_method_warn;
+-(void)testNoWarn;
+ at end
+
+ at 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);
+}
+ at end
More information about the cfe-commits
mailing list