[analyzer] Fix a crash in CloneDetector when calling functions by pointers.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 10 Aug 2016 16:25:16 +0000 (16:25 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 10 Aug 2016 16:25:16 +0000 (16:25 +0000)
CallExpr may have a null direct callee when the callee function is not
known in compile-time. Do not try to take callee name in this case.

Patch by Raphael Isemann!

Differential Revision: https://reviews.llvm.org/D23320

llvm-svn: 278238

clang/lib/Analysis/CloneDetection.cpp
clang/test/Analysis/copypaste/call.cpp

index 038f9eb..27815f3 100644 (file)
@@ -249,8 +249,11 @@ public:
   })
 
   //--- Calls --------------------------------------------------------------//
-  DEF_ADD_DATA(CallExpr,
-               { addData(S->getDirectCallee()->getQualifiedNameAsString()); })
+  DEF_ADD_DATA(CallExpr, {
+    // Function pointers don't have a callee and we just skip hashing it.
+    if (S->getDirectCallee())
+      addData(S->getDirectCallee()->getQualifiedNameAsString());
+  })
 
   //--- Exceptions ---------------------------------------------------------//
   DEF_ADD_DATA(CXXCatchStmt, { addData(S->getCaughtType()); })
index 06aa633..0c10262 100644 (file)
@@ -22,3 +22,15 @@ bool foo2(int x) {
     return b();
   return true;
 }
+
+// Test that we don't crash on function pointer calls
+
+bool (*funcPtr)(int);
+
+bool fooPtr1(int x) {
+  if (x > 0)
+    return false;
+  else if (x < 0)
+    return funcPtr(1);
+  return true;
+}