llvm.org GIT mirror llvm / 987e30d
[dfsan] Add explicit zero extensions for shadow parameters in function wrappers. In the case where dfsan provides a custom wrapper for a function, shadow parameters are added for each parameter of the function. These parameters are i16s. For targets which do not consider this a legal type, the lack of sign extension information would cause LLVM to generate anyexts around their usage with phi variables and calling convention logic. Address this by introducing zero exts for each shadow parameter. Reviewers: pcc, slthakur Differential Revision: https://reviews.llvm.org/D33349 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311087 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Dardis 2 years ago
4 changed file(s) with 77 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
14691469 }
14701470
14711471 i = CS.arg_begin();
1472 const unsigned ShadowArgStart = Args.size();
14721473 for (unsigned n = FT->getNumParams(); n != 0; ++i, --n)
14731474 Args.push_back(DFSF.getShadow(*i));
14741475
15031504 CallInst *CustomCI = IRB.CreateCall(CustomF, Args);
15041505 CustomCI->setCallingConv(CI->getCallingConv());
15051506 CustomCI->setAttributes(CI->getAttributes());
1507
1508 // Update the parameter attributes of the custom call instruction to
1509 // zero extend the shadow parameters. This is required for targets
1510 // which consider ShadowTy an illegal type.
1511 for (unsigned n = 0; n < FT->getNumParams(); n++) {
1512 const unsigned ArgNo = ShadowArgStart + n;
1513 if (CustomCI->getArgOperand(ArgNo)->getType() == DFSF.DFS.ShadowTy)
1514 CustomCI->addParamAttr(ArgNo, Attribute::ZExt);
1515 }
15061516
15071517 if (!FT->getReturnType()->isVoidTy()) {
15081518 LoadInst *LabelLoad = IRB.CreateLoad(DFSF.LabelReturnAlloca);
0 fun:dfsan_get_label=uninstrumented
1 fun:dfsan_get_label=custom
2
3 fun:k2=uninstrumented
4 fun:k2=custom
5
6 fun:k4=uninstrumented
7 fun:k4=custom
4646 ; CHECK: %[[LABELVA1:.*]] = alloca [2 x i16]
4747 ; CHECK: %[[LABELRETURN:.*]] = alloca i16
4848
49 ; CHECK: call void @__dfsw_custom1(i32 1, i32 2, i16 0, i16 0)
49 ; CHECK: call void @__dfsw_custom1(i32 1, i32 2, i16 zeroext 0, i16 zeroext 0)
5050 call void @custom1(i32 1, i32 2)
5151
52 ; CHECK: call i32 @__dfsw_custom2(i32 1, i32 2, i16 0, i16 0, i16* %[[LABELRETURN]])
52 ; CHECK: call i32 @__dfsw_custom2(i32 1, i32 2, i16 zeroext 0, i16 zeroext 0, i16* %[[LABELRETURN]])
5353 call i32 @custom2(i32 1, i32 2)
5454
55 ; CHECK: call void @__dfsw_customcb({{.*}} @"dfst0$customcb", i8* bitcast ({{.*}} @"dfs$cb" to i8*), i16 0)
55 ; CHECK: call void @__dfsw_customcb({{.*}} @"dfst0$customcb", i8* bitcast ({{.*}} @"dfs$cb" to i8*), i16 zeroext 0)
5656 call void @customcb(i32 (i32)* @cb)
5757
5858 ; CHECK: %[[LABELVA1_0:.*]] = getelementptr inbounds [2 x i16], [2 x i16]* %[[LABELVA1]], i32 0, i32 0
6060 ; CHECK: %[[LABELVA1_1:.*]] = getelementptr inbounds [2 x i16], [2 x i16]* %[[LABELVA1]], i32 0, i32 1
6161 ; CHECK: store i16 %{{.*}}, i16* %[[LABELVA1_1]]
6262 ; CHECK: %[[LABELVA1_0A:.*]] = getelementptr inbounds [2 x i16], [2 x i16]* %[[LABELVA1]], i32 0, i32 0
63 ; CHECK: call void (i32, i16, i16*, ...) @__dfsw_custom3(i32 1, i16 0, i16* %[[LABELVA1_0A]], i32 2, i32 %{{.*}})
63 ; CHECK: call void (i32, i16, i16*, ...) @__dfsw_custom3(i32 1, i16 zeroext 0, i16* %[[LABELVA1_0A]], i32 2, i32 %{{.*}})
6464 call void (i32, ...) @custom3(i32 1, i32 2, i32 %x)
6565
6666 ; CHECK: %[[LABELVA2_0:.*]] = getelementptr inbounds [2 x i16], [2 x i16]* %[[LABELVA2]], i32 0, i32 0
6767 ; CHECK: %[[LABELVA2_0A:.*]] = getelementptr inbounds [2 x i16], [2 x i16]* %[[LABELVA2]], i32 0, i32 0
68 ; CHECK: call i32 (i32, i16, i16*, i16*, ...) @__dfsw_custom4(i32 1, i16 0, i16* %[[LABELVA2_0A]], i16* %[[LABELRETURN]], i32 2, i32 3)
68 ; CHECK: call i32 (i32, i16, i16*, i16*, ...) @__dfsw_custom4(i32 1, i16 zeroext 0, i16* %[[LABELVA2_0A]], i16* %[[LABELRETURN]], i32 2, i32 3)
6969 call i32 (i32, ...) @custom4(i32 1, i32 2, i32 3)
7070
7171 ret void
0 ; RUN: opt -mtriple=x86_64-unknown-linux-gnu < %s -dfsan -S --dfsan-abilist=%S/Inputs/shadow-args-abilist.txt | FileCheck %s
1
2 ; REQUIRES: x86-registered-target
3
4 ; Test that the custom abi marks shadow parameters as zero extended.
5
6 define i32 @m() {
7 entry:
8 %call = call zeroext i16 @dfsan_get_label(i64 signext 56)
9 %conv = zext i16 %call to i32
10 ret i32 %conv
11 }
12
13 ; CHECK-LABEL: @"dfs$m"
14 ; CHECK: %{{.*}} = call zeroext i16 @__dfsw_dfsan_get_label(i64 signext 56, i16 zeroext 0, i16* %{{.*}})
15
16 define i32 @k() {
17 entry:
18 %call = call zeroext i16 @k2(i64 signext 56, i64 signext 67)
19 %conv = zext i16 %call to i32
20 ret i32 %conv
21 }
22
23 ; CHECK-LABEL: @"dfs$k"
24 ; CHECK: %{{.*}} = call zeroext i16 @__dfsw_k2(i64 signext 56, i64 signext 67, i16 zeroext {{.*}}, i16 zeroext {{.*}}, i16* %{{.*}})
25
26 define i32 @k3() {
27 entry:
28 %call = call zeroext i16 @k4(i64 signext 56, i64 signext 67, i64 signext 78, i64 signext 89)
29 %conv = zext i16 %call to i32
30 ret i32 %conv
31 }
32
33 ; CHECK-LABEL: @"dfs$k3"
34 ; CHECK: %{{.*}} = call zeroext i16 @__dfsw_k4(i64 signext 56, i64 signext 67, i64 signext 78, i64 signext 89, i16 zeroext {{.*}}, i16 zeroext {{.*}}, i16 zeroext {{.*}}, i16 zeroext {{.*}}, i16* %{{.*}})
35
36 declare zeroext i16 @dfsan_get_label(i64 signext)
37
38 ; CHECK-LABEL: @"dfsw$dfsan_get_label"
39 ; CHECK: %{{.*}} = call i16 @__dfsw_dfsan_get_label(i64 %0, i16 zeroext %1, i16* %{{.*}})
40
41 declare zeroext i16 @k2(i64 signext, i64 signext)
42 ; CHECK-LABEL: @"dfsw$k2"
43 ; CHECK: %{{.*}} = call i16 @__dfsw_k2(i64 %{{.*}}, i64 %{{.*}}, i16 zeroext %{{.*}}, i16 zeroext %{{.*}}, i16* %{{.*}})
44
45 declare zeroext i16 @k4(i64 signext, i64 signext, i64 signext, i64 signext)
46
47 ; CHECK-LABEL: @"dfsw$k4"
48 ; CHECK: %{{.*}} = call i16 @__dfsw_k4(i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}}, i16 zeroext %{{.*}}, i16 zeroext %{{.*}}, i16 zeroext %{{.*}}, i16 zeroext %{{.*}}, i16* %{{.*}})
49
50
51 ; CHECK: declare zeroext i16 @__dfsw_dfsan_get_label(i64 signext, i16, i16*)
52 ; CHECK: declare zeroext i16 @__dfsw_k2(i64 signext, i64 signext, i16, i16, i16*)
53 ; CHECK: declare zeroext i16 @__dfsw_k4(i64 signext, i64 signext, i64 signext, i64 signext, i16, i16, i16, i16, i16*)