[PATCH] DataFlowSanitizer: Make unreachable BBs verify under the args ABI.
Peter Collingbourne
peter at pcc.me.uk
Wed Aug 7 17:26:08 PDT 2013
Hi eugenis,
http://llvm-reviews.chandlerc.com/D1316
Files:
lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
test/Instrumentation/DataFlowSanitizer/args-unreachable-bb.ll
Index: lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -410,6 +410,23 @@
std::copy(df_begin(&(*i)->getEntryBlock()), df_end(&(*i)->getEntryBlock()),
std::back_inserter(BBList));
+ // Unused basic blocks will not be instrumented. This is okay, because
+ // they are unreachable. But we need to modify any return instructions in
+ // these BBs to return a value of the correct type in order to pass the
+ // verifier. This is easier than just deleting them because they may be
+ // referenced by phi nodes (and each other).
+ Type *RetTy = (*i)->getReturnType();
+ if (!RetTy->isVoidTy()) {
+ SmallPtrSet<BasicBlock *, 4> BBSet;
+ BBSet.insert(BBList.begin(), BBList.end());
+ for (Function::iterator bi = (*i)->begin(), be = (*i)->end(); bi != be;
+ ++bi) {
+ if (!BBSet.count(&*bi))
+ if (ReturnInst *RI = dyn_cast<ReturnInst>(bi->getTerminator()))
+ RI->setOperand(0, UndefValue::get(RetTy));
+ }
+ }
+
for (llvm::SmallVector<BasicBlock *, 4>::iterator i = BBList.begin(),
e = BBList.end();
i != e; ++i) {
Index: test/Instrumentation/DataFlowSanitizer/args-unreachable-bb.ll
===================================================================
--- /dev/null
+++ test/Instrumentation/DataFlowSanitizer/args-unreachable-bb.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -dfsan -verify -dfsan-args-abi -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+define i8 @unreachable_bb() {
+ ; CHECK: @unreachable_bb
+ ; CHECK: ret { i8, i16 } { i8 1, i16 0 }
+ ; CHECK: bb2:
+ ; CHECK: ret { i8, i16 } undef
+ ret i8 1
+
+bb2:
+ ret i8 2
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1316.1.patch
Type: text/x-patch
Size: 2033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130807/c2db2611/attachment.bin>
More information about the llvm-commits
mailing list