r278238 - [analyzer] Fix a crash in CloneDetector when calling functions by pointers.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 10 09:25:16 PDT 2016


Author: dergachev
Date: Wed Aug 10 11:25:16 2016
New Revision: 278238

URL: http://llvm.org/viewvc/llvm-project?rev=278238&view=rev
Log:
[analyzer] Fix a crash in CloneDetector when calling functions by pointers.

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

Modified:
    cfe/trunk/lib/Analysis/CloneDetection.cpp
    cfe/trunk/test/Analysis/copypaste/call.cpp

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=278238&r1=278237&r2=278238&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Wed Aug 10 11:25:16 2016
@@ -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()); })

Modified: cfe/trunk/test/Analysis/copypaste/call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/copypaste/call.cpp?rev=278238&r1=278237&r2=278238&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/copypaste/call.cpp (original)
+++ cfe/trunk/test/Analysis/copypaste/call.cpp Wed Aug 10 11:25:16 2016
@@ -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;
+}




More information about the cfe-commits mailing list