aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2013-09-06 22:47:05 +0000
committerManman Ren <manman.ren@gmail.com>2013-09-06 22:47:05 +0000
commit0b3d39235aaed8bc66ccffb3942bf7b5f185329c (patch)
tree4a200b460151ea6d88f92af581743b3567357909
parent1307103dffa81494e284b17c6ecfe4c3ed9cb6ce (diff)
downloadexternal_llvm-0b3d39235aaed8bc66ccffb3942bf7b5f185329c.zip
external_llvm-0b3d39235aaed8bc66ccffb3942bf7b5f185329c.tar.gz
external_llvm-0b3d39235aaed8bc66ccffb3942bf7b5f185329c.tar.bz2
TBAA: add isTBAAVtableAccess to MDNode so clients can call the function
instead of having its own implementation. The implementation of isTBAAVtableAccess is in TypeBasedAliasAnalysis.cpp since it is related to the format of TBAA metadata. The path for struct-path tbaa will be exercised by test/Instrumentation/ThreadSanitizer/read_from_global.ll, vptr_read.ll, and vptr_update.ll when struct-path tbaa is on by default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190216 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/IR/Metadata.h3
-rw-r--r--lib/Analysis/TypeBasedAliasAnalysis.cpp19
-rw-r--r--lib/Transforms/Instrumentation/ThreadSanitizer.cpp8
3 files changed, 24 insertions, 6 deletions
diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h
index acd84d7..49eb895 100644
--- a/include/llvm/IR/Metadata.h
+++ b/include/llvm/IR/Metadata.h
@@ -161,6 +161,9 @@ public:
return V->getValueID() == MDNodeVal;
}
+ /// Check whether MDNode is a vtable access.
+ bool isTBAAVtableAccess() const;
+
/// Methods for metadata merging.
static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);
static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);
diff --git a/lib/Analysis/TypeBasedAliasAnalysis.cpp b/lib/Analysis/TypeBasedAliasAnalysis.cpp
index bbf3c3a..ac3965f 100644
--- a/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -458,6 +458,25 @@ TypeBasedAliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
return AliasAnalysis::getModRefInfo(CS1, CS2);
}
+bool MDNode::isTBAAVtableAccess() const {
+ if (!EnableStructPathTBAA) {
+ if (getNumOperands() < 1) return false;
+ if (MDString *Tag1 = dyn_cast<MDString>(getOperand(0))) {
+ if (Tag1->getString() == "vtable pointer") return true;
+ }
+ return false;
+ }
+
+ // For struct-path aware TBAA, we use the access type of the tag.
+ if (getNumOperands() < 2) return false;
+ MDNode *Tag = cast_or_null<MDNode>(getOperand(1));
+ if (!Tag) return false;
+ if (MDString *Tag1 = dyn_cast<MDString>(Tag->getOperand(0))) {
+ if (Tag1->getString() == "vtable pointer") return true;
+ }
+ return false;
+}
+
MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) {
if (!A || !B)
return NULL;
diff --git a/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
index e19ceba..2c8a7c4 100644
--- a/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ b/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -240,12 +240,8 @@ bool ThreadSanitizer::doInitialization(Module &M) {
}
static bool isVtableAccess(Instruction *I) {
- if (MDNode *Tag = I->getMetadata(LLVMContext::MD_tbaa)) {
- if (Tag->getNumOperands() < 1) return false;
- if (MDString *Tag1 = dyn_cast<MDString>(Tag->getOperand(0))) {
- if (Tag1->getString() == "vtable pointer") return true;
- }
- }
+ if (MDNode *Tag = I->getMetadata(LLVMContext::MD_tbaa))
+ return Tag->isTBAAVtableAccess();
return false;
}