]> granicus.if.org Git - clang/commitdiff
[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

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

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

index 038f9eb87cd0f840f8a33e7656aa64fad04f5d30..27815f30aead89e8945cfd83018152c5370a2931 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 06aa633fe9638acd32d22e78a04b0674da42ded5..0c10262a31df74c8afda32b4bbc1fbe0ff65f3ae 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;
+}