[PATCH] D42789: [dfsan] Correctly copy attributes to variadic custom wrapper
Yunjong Jeong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 18 00:42:15 PST 2018
blukat29 updated this revision to Diff 134826.
blukat29 retitled this revision from "[dfsan] Correctly copy attributes when calling variadic custom wrapper" to "[dfsan] Correctly copy attributes to variadic custom wrapper".
blukat29 edited the summary of this revision.
blukat29 added a reviewer: dneilson.
blukat29 added a comment.
Rebased to revision 325456.
https://reviews.llvm.org/D42789
Files:
lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
test/Instrumentation/DataFlowSanitizer/Inputs/custom-abilist.txt
test/Instrumentation/DataFlowSanitizer/custom-attrs.ll
Index: test/Instrumentation/DataFlowSanitizer/custom-attrs.ll
===================================================================
--- test/Instrumentation/DataFlowSanitizer/custom-attrs.ll
+++ test/Instrumentation/DataFlowSanitizer/custom-attrs.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -dfsan -dfsan-args-abi -dfsan-abilist=%S/Inputs/custom-abilist.txt -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f() {
+ ; CHECK: call signext i32 {{.*}} @__dfsw_sprintf(i8* align 1 undef, i8* align 2 undef, i16 zeroext 0, i16 zeroext 0, i16* %{{.*}}, i16* %{{.*}}) #[[ATTR:[0-9]+]]
+ ; CHECK: call signext i32 {{.*}} @__dfsw_sprintf(i8* align 1 undef, i8* align 2 undef, i16 zeroext 0, i16 zeroext 0, i16* %{{.*}}, i16* %{{.*}}, i8* align 4 undef, i8* align 8 undef) #[[ATTR]]
+ ; attributes #[[ATTR]] = { nounwind }
+ call signext i32 (i8*, i8*, ...) @sprintf(i8* align 1 undef, i8* align 2 undef) #1
+ call signext i32 (i8*, i8*, ...) @sprintf(i8* align 1 undef, i8* align 2 undef, i8* align 4 undef, i8* align 8 undef) #1
+ ret void
+}
+
+declare i32 @sprintf(i8*, i8*, ...)
+attributes #1 = { nounwind }
Index: test/Instrumentation/DataFlowSanitizer/Inputs/custom-abilist.txt
===================================================================
--- test/Instrumentation/DataFlowSanitizer/Inputs/custom-abilist.txt
+++ test/Instrumentation/DataFlowSanitizer/Inputs/custom-abilist.txt
@@ -0,0 +1,2 @@
+fun:sprintf=custom
+fun:sprintf=uninstrumented
Index: lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -1531,7 +1531,33 @@
CallInst *CustomCI = IRB.CreateCall(CustomF, Args);
CustomCI->setCallingConv(CI->getCallingConv());
- CustomCI->setAttributes(CI->getAttributes());
+
+ if (FT->isVarArg()) {
+ AttributeList OldAttrs = CI->getAttributes();
+ SmallVector<AttributeSet, 8> ArgAttrs;
+ const unsigned NonVarArgCount = FT->getNumParams();
+ const unsigned ShadowArgCount =
+ CustomFT->getNumParams() - NonVarArgCount;
+
+ // Copy non-vararg attributes.
+ for (unsigned n = 0; n < NonVarArgCount; n++) {
+ ArgAttrs.push_back(OldAttrs.getParamAttributes(n));
+ }
+ // Skip label parameters.
+ for (unsigned n = 0; n < ShadowArgCount; n++) {
+ ArgAttrs.push_back(AttributeSet());
+ }
+ // Copy vararg attributes.
+ for (unsigned n = NonVarArgCount; n < CS.arg_size(); n++) {
+ ArgAttrs.push_back(OldAttrs.getParamAttributes(n));
+ }
+
+ CustomCI->setAttributes(AttributeList::get(
+ F->getContext(), OldAttrs.getFnAttributes(),
+ OldAttrs.getRetAttributes(), ArgAttrs));
+ } else {
+ CustomCI->setAttributes(CI->getAttributes());
+ }
// Update the parameter attributes of the custom call instruction to
// zero extend the shadow parameters. This is required for targets
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42789.134826.patch
Type: text/x-patch
Size: 3219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180218/cea04e03/attachment.bin>
More information about the llvm-commits
mailing list