Fixed for PR#16672: http://llvm.org/bugs/show_bug.cgi?id=16672.
Do not include functions with externally available linkage in the list of
valid function targets. These functions are not emitted into the executable.
llvm-svn: 189030
diff --git a/safecode/lib/InsertPoolChecks/CFIChecks.cpp b/safecode/lib/InsertPoolChecks/CFIChecks.cpp
index 2f6e5a0..5c7114d 100644
--- a/safecode/lib/InsertPoolChecks/CFIChecks.cpp
+++ b/safecode/lib/InsertPoolChecks/CFIChecks.cpp
@@ -103,8 +103,19 @@
for (CallGraphNode::iterator ei = ExternalNode->begin();
ei != ExternalNode->end(); ++ei) {
if (Function * Target = ei->second->getFunction()) {
- if (Target->isIntrinsic())
+ //
+ // Do not include intrinsic functions or functions that do not get
+ // emitted into the executable in the list of targets.
+ //
+ if ((Target->isIntrinsic()) ||
+ (Target->hasAvailableExternallyLinkage())) {
continue;
+ }
+
+ //
+ // Do not include functions with available externally linkage. These
+ // functions are never emitted into the final executable.
+ //
Targets.push_back (ConstantExpr::getZExtOrBitCast (Target,
VoidPtrType));
}
@@ -125,6 +136,15 @@
}
//
+ // Do not include intrinsic functions or functions that do not get
+ // emitted into the final exeutable as targets.
+ //
+ if ((Target->isIntrinsic()) ||
+ (Target->hasAvailableExternallyLinkage())) {
+ continue;
+ }
+
+ //
// Add the target to the set of targets. Cast it to a void pointer
// first.
//
diff --git a/safecode/lib/InsertPoolChecks/CompleteChecks.cpp b/safecode/lib/InsertPoolChecks/CompleteChecks.cpp
index 37060b7..8d78f56 100644
--- a/safecode/lib/InsertPoolChecks/CompleteChecks.cpp
+++ b/safecode/lib/InsertPoolChecks/CompleteChecks.cpp
@@ -505,8 +505,15 @@
for (CallGraphNode::iterator ei = ExternalNode->begin();
ei != ExternalNode->end(); ++ei) {
if (Function * Target = ei->second->getFunction()) {
- if (!(Target->isIntrinsic()))
- Targets.push_back (Target);
+ //
+ // Do not include intrinsics or functions that do not get emitted
+ // into the executable.
+ //
+ if ((Target->isIntrinsic()) ||
+ (Target->hasAvailableExternallyLinkage())) {
+ continue;
+ }
+ Targets.push_back (Target);
}
}
} else {
@@ -514,8 +521,10 @@
// Get the function target out of the node.
//
if (Function * Target = CalleeNode->getFunction()) {
- if (!(Target->isIntrinsic()))
+ if ((!Target->isIntrinsic()) ||
+ (!Target->hasAvailableExternallyLinkage())) {
Targets.push_back (Target);
+ }
}
}
}
diff --git a/safecode/test/regression/extavail.cpp b/safecode/test/regression/extavail.cpp
new file mode 100644
index 0000000..10ce117
--- /dev/null
+++ b/safecode/test/regression/extavail.cpp
@@ -0,0 +1,25 @@
+//
+// RUN: clang -S -emit-llvm -O2 -fmemsafety %s -o - 2>&1 | grep TargetList 2>&1 | grep internal | grep -v _ZNSaIcEC1Ev
+//
+// This is a test case for PR#16672:
+// http://llvm.org/bugs/show_bug.cgi?id=16672
+//
+// We check to see that functions marked as externally available are not
+// included in the list of CFI targets
+//
+
+#include <string>
+#include <map>
+#include <iostream>
+
+using namespace std;
+int main(int argc,char** argv){
+ map<string,int> themap;
+ string test(argv[0]);
+
+ themap["key1"]=1;
+ cout << test << endl;
+
+ return 0;
+}
+