File tree Expand file tree Collapse file tree 7 files changed +21
-13
lines changed
Instrumentation/ThreadSanitizer Expand file tree Collapse file tree 7 files changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -2046,7 +2046,8 @@ example:
2046
2046
attributes.
2047
2047
``naked``
2048
2048
This attribute disables prologue / epilogue emission for the
2049
- function. This can have very system-specific consequences.
2049
+ function. This can have very system-specific consequences. The arguments of
2050
+ a ``naked`` function can not be referenced through IR values.
2050
2051
``"no-inline-line-tables"``
2051
2052
When this attribute is set to true, the inliner discards source locations
2052
2053
when inlining code and instead uses the source location of the call site.
Original file line number Diff line number Diff line change @@ -2777,6 +2777,10 @@ void Verifier::visitFunction(const Function &F) {
2777
2777
Check (!Attrs.hasAttrSomewhere (Attribute::ElementType),
2778
2778
" Attribute 'elementtype' can only be applied to a callsite." , &F);
2779
2779
2780
+ if (Attrs.hasFnAttr (Attribute::Naked))
2781
+ for (const Argument &Arg : F.args ())
2782
+ Check (Arg.use_empty (), " cannot use argument of naked function" , &Arg);
2783
+
2780
2784
// Check that this function meets the restrictions on this calling convention.
2781
2785
// Sometimes varargs is used for perfectly forwarding thunks, so some of these
2782
2786
// restrictions can be lifted.
Original file line number Diff line number Diff line change @@ -98,12 +98,12 @@ define void @SwiftErrorCall(ptr swifterror) sanitize_thread {
98
98
ret void
99
99
}
100
100
101
- ; CHECK-LABEL: @NakedTest(ptr %a )
102
- ; CHECK-NEXT: call void @foo()
103
- ; CHECK-NEXT: %tmp1 = load i32, ptr %a, align 4
104
- ; CHECK-NEXT: ret i32 %tmp1
105
- define i32 @NakedTest (ptr %a ) naked sanitize_thread {
106
- call void @foo ()
101
+ ; CHECK-LABEL: @NakedTest()
102
+ ; CHECK-NEXT: %a = call ptr @foo()
103
+ ; CHECK-NEXT: %tmp1 = load i32, ptr %a, align 4
104
+ ; CHECK-NEXT: ret i32 %tmp1
105
+ define i32 @NakedTest () naked sanitize_thread {
106
+ %a = call ptr @foo ()
107
107
%tmp1 = load i32 , ptr %a , align 4
108
108
ret i32 %tmp1
109
109
}
Original file line number Diff line number Diff line change @@ -1048,10 +1048,8 @@ define internal void @naked(ptr dereferenceable(4) %a) naked {
1048
1048
; CHECK: Function Attrs: naked
1049
1049
; CHECK-LABEL: define {{[^@]+}}@naked
1050
1050
; CHECK-SAME: (ptr noundef nonnull dereferenceable(4) [[A:%.*]]) #[[ATTR11:[0-9]+]] {
1051
- ; CHECK-NEXT: call void @use_i32_ptr(ptr nocapture nofree noundef nonnull [[A]])
1052
1051
; CHECK-NEXT: ret void
1053
1052
;
1054
- call void @use_i32_ptr (ptr %a )
1055
1053
ret void
1056
1054
}
1057
1055
; Avoid nonnull as we do not touch optnone
Original file line number Diff line number Diff line change @@ -81,6 +81,6 @@ attributes #0 = {
81
81
82
82
; attributes to drop
83
83
attributes #1 = {
84
- alignstack =16 convergent inaccessiblememonly inaccessiblemem_or_argmemonly naked
84
+ alignstack =16 convergent inaccessiblememonly inaccessiblemem_or_argmemonly
85
85
noreturn readonly argmemonly returns_twice speculatable "thunk"
86
86
}
Original file line number Diff line number Diff line change @@ -1079,15 +1079,12 @@ define internal void @control(ptr dereferenceable(4) %a) {
1079
1079
define internal void @naked (ptr dereferenceable (4 ) %a ) naked {
1080
1080
; FNATTRS-LABEL: define internal void @naked(
1081
1081
; FNATTRS-SAME: ptr dereferenceable(4) [[A:%.*]]) #[[ATTR10:[0-9]+]] {
1082
- ; FNATTRS-NEXT: call void @use_i32_ptr(ptr [[A]])
1083
1082
; FNATTRS-NEXT: ret void
1084
1083
;
1085
1084
; ATTRIBUTOR-LABEL: define internal void @naked(
1086
1085
; ATTRIBUTOR-SAME: ptr nonnull dereferenceable(4) [[A:%.*]]) #[[ATTR11:[0-9]+]] {
1087
- ; ATTRIBUTOR-NEXT: call void @use_i32_ptr(ptr [[A]])
1088
1086
; ATTRIBUTOR-NEXT: ret void
1089
1087
;
1090
- call void @use_i32_ptr (ptr %a )
1091
1088
ret void
1092
1089
}
1093
1090
; Avoid nonnull as we do not touch optnone
Original file line number Diff line number Diff line change
1
+ ; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
2
+
3
+ ; CHECK: cannot use argument of naked function
4
+ define void @test (ptr %ptr ) naked {
5
+ getelementptr i8 , ptr %ptr , i64 1
6
+ call void @llvm.trap ()
7
+ unreachable
8
+ }
You can’t perform that action at this time.
0 commit comments