[PATCH] D23320: [analyzer] Fixed crash in CloneDetector in function calls.
Raphael Isemann via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 9 07:34:18 PDT 2016
teemperor created this revision.
teemperor added reviewers: v.g.vassilev, NoQ, zaks.anna.
teemperor added subscribers: cfe-commits, vsk.
StmtDataCollector currently crashes on function calls because they don't have a callee. This patch fixes this.
https://reviews.llvm.org/D23320
Files:
lib/Analysis/CloneDetection.cpp
test/Analysis/copypaste/call.cpp
Index: test/Analysis/copypaste/call.cpp
===================================================================
--- test/Analysis/copypaste/call.cpp
+++ test/Analysis/copypaste/call.cpp
@@ -22,3 +22,15 @@
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;
+}
Index: lib/Analysis/CloneDetection.cpp
===================================================================
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -318,8 +318,11 @@
})
//--- 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()); })
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23320.67345.patch
Type: text/x-patch
Size: 1185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160809/6bf426b1/attachment.bin>
More information about the cfe-commits
mailing list