summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-09-13 18:18:37 +0000
committerTed Kremenek <kremenek@apple.com>2012-09-13 18:18:37 +0000
commite5c0a9bad4023b33fe5f8fcc8bb6a74e5c75caec (patch)
tree086160c004943f902e7d5dca0d3f54b8510a384a /clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
parent3effe81bf7075c894710a279280961c6c028cf57 (diff)
downloadbcm5719-llvm-e5c0a9bad4023b33fe5f8fcc8bb6a74e5c75caec.tar.gz
bcm5719-llvm-e5c0a9bad4023b33fe5f8fcc8bb6a74e5c75caec.zip
When warning about unsafe uses of dispatch_once, specially handle the
crazy case where dispatch_once gets redefined as a macro that calls _dispatch_once (which calls the real dispatch_once). Users want to see the warning in their own code. Fixes <rdar://problem/11617767> llvm-svn: 163816
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
index cfdb55df730..97bb80c9e19 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
@@ -70,6 +70,16 @@ void MacOSXAPIChecker::CheckDispatchOnce(CheckerContext &C, const CallExpr *CE,
BT_dispatchOnce.reset(new BugType("Improper use of 'dispatch_once'",
"Mac OS X API"));
+ // Handle _dispatch_once, which in some versions of the OS X SDK that
+ // dispatch_once is a macro that wraps a call to _dispatch_once, which
+ // then calls the real dispatch_once. Users do not care; they just
+ // want the warning at the top-level call.
+ if (CE->getLocStart().isMacroID()) {
+ StringRef TrimmedFName = FName.ltrim("_");
+ if (TrimmedFName != FName)
+ FName = TrimmedFName;
+ }
+
SmallString<256> S;
llvm::raw_svector_ostream os(S);
os << "Call to '" << FName << "' uses";
@@ -99,7 +109,9 @@ void MacOSXAPIChecker::checkPreStmt(const CallExpr *CE,
SubChecker SC =
llvm::StringSwitch<SubChecker>(Name)
- .Cases("dispatch_once", "dispatch_once_f",
+ .Cases("dispatch_once",
+ "_dispatch_once",
+ "dispatch_once_f",
&MacOSXAPIChecker::CheckDispatchOnce)
.Default(NULL);
OpenPOWER on IntegriCloud