]> granicus.if.org Git - clang/commitdiff
Teach the CStringChecker and PthreadLockChecker about non-identifier
authorDouglas Gregor <dgregor@apple.com>
Mon, 1 Nov 2010 23:16:05 +0000 (23:16 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 1 Nov 2010 23:16:05 +0000 (23:16 +0000)
declaration names, from Jim Goodnow II!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117970 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/CStringChecker.cpp
lib/Checker/PthreadLockChecker.cpp
test/Analysis/operator-calls.cpp [new file with mode: 0644]

index d61fdd437d6edd69d52fd1eeced971d6a150eb52..966d04f6e13d1bb9f54045c320b62cb329eb17c4 100644 (file)
@@ -905,7 +905,10 @@ bool CStringChecker::EvalCallExpr(CheckerContext &C, const CallExpr *CE) {
     return false;
 
   // Get the name of the callee. If it's a builtin, strip off the prefix.
-  llvm::StringRef Name = FD->getName();
+  IdentifierInfo *II = FD->getIdentifier();
+  if (!II)   // if no identifier, not a simple C function
+    return false;
+  llvm::StringRef Name = II->getName();
   if (Name.startswith("__builtin_"))
     Name = Name.substr(10);
 
index 74e266c3edfcf02e53dbc57a72a764c8f7740896..c4bd3641382f097174a07623b742fb1572fbad1c 100644 (file)
@@ -65,7 +65,10 @@ void PthreadLockChecker::PostVisitCallExpr(CheckerContext &C,
   if (!R)
     return;
   
-  llvm::StringRef FName = R->getDecl()->getName();
+  IdentifierInfo *II = R->getDecl()->getIdentifier();
+  if (!II)   // if no identifier, not a simple C function
+    return;
+  llvm::StringRef FName = II->getName();
   
   if (FName == "pthread_mutex_lock") {
     if (CE->getNumArgs() != 1)
diff --git a/test/Analysis/operator-calls.cpp b/test/Analysis/operator-calls.cpp
new file mode 100644 (file)
index 0000000..1b8b629
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem  -analyzer-experimental-checks -verify %s
+struct X0 { };
+bool operator==(const X0&, const X0&);
+
+// PR7287
+struct test { int a[2]; };
+
+void t2() {
+  test p = {{1,2}};
+  test q;
+  q = p;
+}
+
+bool PR7287(X0 a, X0 b) {
+  return a == b;
+}