Skip to content

Commit e1e7db6

Browse files
committed
Separate ubsan-trap-merge.ll and ubsan-trap-nomerge.ll test cases per https://github.com/llvm/llvm-project/pull/117657/files
1 parent 0536132 commit e1e7db6

File tree

2 files changed

+193
-13
lines changed

2 files changed

+193
-13
lines changed

llvm/test/MC/X86/ubsan-trap-merge.ll

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
22
; RUN: llc -O3 -mtriple x86_64 -filetype asm -o - %s | FileCheck %s
33
;
4-
; This tests that the nomerge attribute for ubsantrap works correctly i.e.,
5-
; they are lowered to separate ud1 instructions.
4+
; This test shows that ubsantrap can, in the absence of nomerge, be merged by
5+
; the backend into a single ud1 instruction (thus making debugging difficult).
66
;
7-
; The LLVM IR was generated from clang/test/CodeGen/ubsan-trap-merge.c
7+
; The LLVM IR was generated from clang/test/CodeGen/ubsan-trap-merge.c with
8+
; 'nomerge' manually removed from ubsantraps.
89
;
910
; ModuleID = '../clang/test/CodeGen/ubsan-trap-merge.c'
1011
source_filename = "../clang/test/CodeGen/ubsan-trap-merge.c"
@@ -75,16 +76,14 @@ define dso_local range(i32 -2147483521, -2147483648) i32 @h(i32 noundef %x, i32
7576
; CHECK-NEXT: jo .LBB2_3
7677
; CHECK-NEXT: # %bb.1: # %cont
7778
; CHECK-NEXT: addl $129, %esi
78-
; CHECK-NEXT: jo .LBB2_4
79+
; CHECK-NEXT: jo .LBB2_3
7980
; CHECK-NEXT: # %bb.2: # %cont2
8081
; CHECK-NEXT: cmpl %esi, %edi
8182
; CHECK-NEXT: cmovll %edi, %esi
8283
; CHECK-NEXT: movl %esi, %eax
8384
; CHECK-NEXT: retq
8485
; CHECK-NEXT: .LBB2_3: # %trap
8586
; CHECK-NEXT: ud1l (%eax), %eax
86-
; CHECK-NEXT: .LBB2_4: # %trap1
87-
; CHECK-NEXT: ud1l (%eax), %eax
8887
entry:
8988
%0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 127), !nosanitize !5
9089
%1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5
@@ -118,19 +117,15 @@ define dso_local noundef i32 @m(i32 noundef %x, i32 noundef %y) local_unnamed_ad
118117
; CHECK-NEXT: jo .LBB3_4
119118
; CHECK-NEXT: # %bb.1: # %f.exit
120119
; CHECK-NEXT: addl $127, %esi
121-
; CHECK-NEXT: jo .LBB3_5
120+
; CHECK-NEXT: jo .LBB3_4
122121
; CHECK-NEXT: # %bb.2: # %g.exit
123122
; CHECK-NEXT: addl %esi, %edi
124-
; CHECK-NEXT: jo .LBB3_6
123+
; CHECK-NEXT: jo .LBB3_4
125124
; CHECK-NEXT: # %bb.3: # %cont
126125
; CHECK-NEXT: movl %edi, %eax
127126
; CHECK-NEXT: retq
128127
; CHECK-NEXT: .LBB3_4: # %trap.i
129128
; CHECK-NEXT: ud1l (%eax), %eax
130-
; CHECK-NEXT: .LBB3_5: # %trap.i2
131-
; CHECK-NEXT: ud1l (%eax), %eax
132-
; CHECK-NEXT: .LBB3_6: # %trap
133-
; CHECK-NEXT: ud1l (%eax), %eax
134129
entry:
135130
%0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 125), !nosanitize !5
136131
%1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5
@@ -172,7 +167,7 @@ attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-mat
172167
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
173168
attributes #2 = { cold noreturn nounwind }
174169
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
175-
attributes #4 = { nomerge noreturn nounwind }
170+
attributes #4 = { noreturn nounwind }
176171

177172
!llvm.module.flags = !{!0, !1, !2, !3}
178173
!llvm.ident = !{!4}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -O3 -mtriple x86_64 -filetype asm -o - %s | FileCheck %s
3+
;
4+
; This tests that the nomerge attribute for ubsantrap works correctly i.e.,
5+
; they are lowered to separate ud1 instructions.
6+
;
7+
; The LLVM IR was generated from clang/test/CodeGen/ubsan-trap-merge.c.
8+
;
9+
; ModuleID = '../clang/test/CodeGen/ubsan-trap-merge.c'
10+
source_filename = "../clang/test/CodeGen/ubsan-trap-merge.c"
11+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
12+
target triple = "x86_64-unknown-linux-gnu"
13+
14+
; Function Attrs: nounwind uwtable
15+
define dso_local range(i32 -2147483523, -2147483648) i32 @f(i32 noundef %x) local_unnamed_addr #0 {
16+
; CHECK-LABEL: f:
17+
; CHECK: # %bb.0: # %entry
18+
; CHECK-NEXT: addl $125, %edi
19+
; CHECK-NEXT: jo .LBB0_1
20+
; CHECK-NEXT: # %bb.2: # %cont
21+
; CHECK-NEXT: movl %edi, %eax
22+
; CHECK-NEXT: retq
23+
; CHECK-NEXT: .LBB0_1: # %trap
24+
; CHECK-NEXT: ud1l (%eax), %eax
25+
entry:
26+
%0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 125), !nosanitize !5
27+
%1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5
28+
br i1 %1, label %trap, label %cont, !nosanitize !5
29+
30+
trap: ; preds = %entry
31+
tail call void @llvm.ubsantrap(i8 0) #4, !nosanitize !5
32+
unreachable, !nosanitize !5
33+
34+
cont: ; preds = %entry
35+
%2 = extractvalue { i32, i1 } %0, 0, !nosanitize !5
36+
ret i32 %2
37+
}
38+
39+
; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
40+
declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #1
41+
42+
; Function Attrs: cold noreturn nounwind
43+
declare void @llvm.ubsantrap(i8 immarg) #2
44+
45+
; Function Attrs: nounwind uwtable
46+
define dso_local range(i32 -2147483521, -2147483648) i32 @g(i32 noundef %x) local_unnamed_addr #0 {
47+
; CHECK-LABEL: g:
48+
; CHECK: # %bb.0: # %entry
49+
; CHECK-NEXT: addl $127, %edi
50+
; CHECK-NEXT: jo .LBB1_1
51+
; CHECK-NEXT: # %bb.2: # %cont
52+
; CHECK-NEXT: movl %edi, %eax
53+
; CHECK-NEXT: retq
54+
; CHECK-NEXT: .LBB1_1: # %trap
55+
; CHECK-NEXT: ud1l (%eax), %eax
56+
entry:
57+
%0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 127), !nosanitize !5
58+
%1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5
59+
br i1 %1, label %trap, label %cont, !nosanitize !5
60+
61+
trap: ; preds = %entry
62+
tail call void @llvm.ubsantrap(i8 0) #4, !nosanitize !5
63+
unreachable, !nosanitize !5
64+
65+
cont: ; preds = %entry
66+
%2 = extractvalue { i32, i1 } %0, 0, !nosanitize !5
67+
ret i32 %2
68+
}
69+
70+
; Function Attrs: nounwind uwtable
71+
define dso_local range(i32 -2147483521, -2147483648) i32 @h(i32 noundef %x, i32 noundef %y) local_unnamed_addr #0 {
72+
; CHECK-LABEL: h:
73+
; CHECK: # %bb.0: # %entry
74+
; CHECK-NEXT: addl $127, %edi
75+
; CHECK-NEXT: jo .LBB2_3
76+
; CHECK-NEXT: # %bb.1: # %cont
77+
; CHECK-NEXT: addl $129, %esi
78+
; CHECK-NEXT: jo .LBB2_4
79+
; CHECK-NEXT: # %bb.2: # %cont2
80+
; CHECK-NEXT: cmpl %esi, %edi
81+
; CHECK-NEXT: cmovll %edi, %esi
82+
; CHECK-NEXT: movl %esi, %eax
83+
; CHECK-NEXT: retq
84+
; CHECK-NEXT: .LBB2_3: # %trap
85+
; CHECK-NEXT: ud1l (%eax), %eax
86+
; CHECK-NEXT: .LBB2_4: # %trap1
87+
; CHECK-NEXT: ud1l (%eax), %eax
88+
entry:
89+
%0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 127), !nosanitize !5
90+
%1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5
91+
br i1 %1, label %trap, label %cont, !nosanitize !5
92+
93+
trap: ; preds = %entry
94+
tail call void @llvm.ubsantrap(i8 0) #4, !nosanitize !5
95+
unreachable, !nosanitize !5
96+
97+
cont: ; preds = %entry
98+
%2 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %y, i32 129), !nosanitize !5
99+
%3 = extractvalue { i32, i1 } %2, 1, !nosanitize !5
100+
br i1 %3, label %trap1, label %cont2, !nosanitize !5
101+
102+
trap1: ; preds = %cont
103+
tail call void @llvm.ubsantrap(i8 0) #4, !nosanitize !5
104+
unreachable, !nosanitize !5
105+
106+
cont2: ; preds = %cont
107+
%4 = extractvalue { i32, i1 } %2, 0, !nosanitize !5
108+
%5 = extractvalue { i32, i1 } %0, 0, !nosanitize !5
109+
%cond = tail call i32 @llvm.smin.i32(i32 %5, i32 %4)
110+
ret i32 %cond
111+
}
112+
113+
; Function Attrs: nounwind uwtable
114+
define dso_local noundef i32 @m(i32 noundef %x, i32 noundef %y) local_unnamed_addr #0 {
115+
; CHECK-LABEL: m:
116+
; CHECK: # %bb.0: # %entry
117+
; CHECK-NEXT: addl $125, %edi
118+
; CHECK-NEXT: jo .LBB3_4
119+
; CHECK-NEXT: # %bb.1: # %f.exit
120+
; CHECK-NEXT: addl $127, %esi
121+
; CHECK-NEXT: jo .LBB3_5
122+
; CHECK-NEXT: # %bb.2: # %g.exit
123+
; CHECK-NEXT: addl %esi, %edi
124+
; CHECK-NEXT: jo .LBB3_6
125+
; CHECK-NEXT: # %bb.3: # %cont
126+
; CHECK-NEXT: movl %edi, %eax
127+
; CHECK-NEXT: retq
128+
; CHECK-NEXT: .LBB3_4: # %trap.i
129+
; CHECK-NEXT: ud1l (%eax), %eax
130+
; CHECK-NEXT: .LBB3_5: # %trap.i2
131+
; CHECK-NEXT: ud1l (%eax), %eax
132+
; CHECK-NEXT: .LBB3_6: # %trap
133+
; CHECK-NEXT: ud1l (%eax), %eax
134+
entry:
135+
%0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 125), !nosanitize !5
136+
%1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5
137+
br i1 %1, label %trap.i, label %f.exit, !nosanitize !5
138+
139+
trap.i: ; preds = %entry
140+
tail call void @llvm.ubsantrap(i8 0) #4, !nosanitize !5
141+
unreachable, !nosanitize !5
142+
143+
f.exit: ; preds = %entry
144+
%2 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %y, i32 127), !nosanitize !5
145+
%3 = extractvalue { i32, i1 } %2, 1, !nosanitize !5
146+
br i1 %3, label %trap.i2, label %g.exit, !nosanitize !5
147+
148+
trap.i2: ; preds = %f.exit
149+
tail call void @llvm.ubsantrap(i8 0) #4, !nosanitize !5
150+
unreachable, !nosanitize !5
151+
152+
g.exit: ; preds = %f.exit
153+
%4 = extractvalue { i32, i1 } %0, 0, !nosanitize !5
154+
%5 = extractvalue { i32, i1 } %2, 0, !nosanitize !5
155+
%6 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %4, i32 %5), !nosanitize !5
156+
%7 = extractvalue { i32, i1 } %6, 1, !nosanitize !5
157+
br i1 %7, label %trap, label %cont, !nosanitize !5
158+
159+
trap: ; preds = %g.exit
160+
tail call void @llvm.ubsantrap(i8 0) #4, !nosanitize !5
161+
unreachable, !nosanitize !5
162+
163+
cont: ; preds = %g.exit
164+
%8 = extractvalue { i32, i1 } %6, 0, !nosanitize !5
165+
ret i32 %8
166+
}
167+
168+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
169+
declare i32 @llvm.smin.i32(i32, i32) #3
170+
171+
attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
172+
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
173+
attributes #2 = { cold noreturn nounwind }
174+
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
175+
attributes #4 = { nomerge noreturn nounwind }
176+
177+
!llvm.module.flags = !{!0, !1, !2, !3}
178+
!llvm.ident = !{!4}
179+
180+
!0 = !{i32 1, !"wchar_size", i32 4}
181+
!1 = !{i32 8, !"PIC Level", i32 2}
182+
!2 = !{i32 7, !"PIE Level", i32 2}
183+
!3 = !{i32 7, !"uwtable", i32 2}
184+
!4 = !{!"clang version 20.0.0git (https://github.com/thurstond/llvm-project.git fe3c23b439b9a2d00442d9bc6a4ca86f73066a3d)"}
185+
!5 = !{}

0 commit comments

Comments
 (0)