|
| 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 with |
| 8 | +; 'nomerge' manually added to ubsantraps. |
| 9 | +; |
| 10 | +; ModuleID = '../clang/test/CodeGen/ubsan-trap-merge.c' |
| 11 | +source_filename = "../clang/test/CodeGen/ubsan-trap-merge.c" |
| 12 | +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" |
| 13 | +target triple = "x86_64-unknown-linux-gnu" |
| 14 | + |
| 15 | +; Function Attrs: nounwind uwtable |
| 16 | +define dso_local range(i32 -2147483523, -2147483648) i32 @f(i32 noundef %x) local_unnamed_addr #0 { |
| 17 | +; CHECK-LABEL: f: |
| 18 | +; CHECK: # %bb.0: # %entry |
| 19 | +; CHECK-NEXT: addl $125, %edi |
| 20 | +; CHECK-NEXT: jo .LBB0_1 |
| 21 | +; CHECK-NEXT: # %bb.2: # %cont |
| 22 | +; CHECK-NEXT: movl %edi, %eax |
| 23 | +; CHECK-NEXT: retq |
| 24 | +; CHECK-NEXT: .LBB0_1: # %trap |
| 25 | +; CHECK-NEXT: ud1l 2(%eax), %eax |
| 26 | +entry: |
| 27 | + %0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 125), !nosanitize !5 |
| 28 | + %1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5 |
| 29 | + br i1 %1, label %trap, label %cont, !nosanitize !5 |
| 30 | + |
| 31 | +trap: ; preds = %entry |
| 32 | + tail call void @llvm.ubsantrap(i8 2) #4, !nosanitize !5 |
| 33 | + unreachable, !nosanitize !5 |
| 34 | + |
| 35 | +cont: ; preds = %entry |
| 36 | + %2 = extractvalue { i32, i1 } %0, 0, !nosanitize !5 |
| 37 | + ret i32 %2 |
| 38 | +} |
| 39 | + |
| 40 | +; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) |
| 41 | +declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #1 |
| 42 | + |
| 43 | +; Function Attrs: cold noreturn nounwind |
| 44 | +declare void @llvm.ubsantrap(i8 immarg) #2 |
| 45 | + |
| 46 | +; Function Attrs: nounwind uwtable |
| 47 | +define dso_local range(i32 -2147483521, -2147483648) i32 @g(i32 noundef %x) local_unnamed_addr #0 { |
| 48 | +; CHECK-LABEL: g: |
| 49 | +; CHECK: # %bb.0: # %entry |
| 50 | +; CHECK-NEXT: addl $127, %edi |
| 51 | +; CHECK-NEXT: jo .LBB1_1 |
| 52 | +; CHECK-NEXT: # %bb.2: # %cont |
| 53 | +; CHECK-NEXT: movl %edi, %eax |
| 54 | +; CHECK-NEXT: retq |
| 55 | +; CHECK-NEXT: .LBB1_1: # %trap |
| 56 | +; CHECK-NEXT: ud1l 2(%eax), %eax |
| 57 | +entry: |
| 58 | + %0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 127), !nosanitize !5 |
| 59 | + %1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5 |
| 60 | + br i1 %1, label %trap, label %cont, !nosanitize !5 |
| 61 | + |
| 62 | +trap: ; preds = %entry |
| 63 | + tail call void @llvm.ubsantrap(i8 2) #4, !nosanitize !5 |
| 64 | + unreachable, !nosanitize !5 |
| 65 | + |
| 66 | +cont: ; preds = %entry |
| 67 | + %2 = extractvalue { i32, i1 } %0, 0, !nosanitize !5 |
| 68 | + ret i32 %2 |
| 69 | +} |
| 70 | + |
| 71 | +; Function Attrs: nounwind uwtable |
| 72 | +define dso_local range(i32 -2147483521, -2147483648) i32 @h(i32 noundef %x, i32 noundef %y) local_unnamed_addr #0 { |
| 73 | +; CHECK-LABEL: h: |
| 74 | +; CHECK: # %bb.0: # %entry |
| 75 | +; CHECK-NEXT: addl $127, %edi |
| 76 | +; CHECK-NEXT: jo .LBB2_3 |
| 77 | +; CHECK-NEXT: # %bb.1: # %cont |
| 78 | +; CHECK-NEXT: addl $129, %esi |
| 79 | +; CHECK-NEXT: jo .LBB2_4 |
| 80 | +; CHECK-NEXT: # %bb.2: # %cont2 |
| 81 | +; CHECK-NEXT: cmpl %esi, %edi |
| 82 | +; CHECK-NEXT: cmovll %edi, %esi |
| 83 | +; CHECK-NEXT: movl %esi, %eax |
| 84 | +; CHECK-NEXT: retq |
| 85 | +; CHECK-NEXT: .LBB2_3: # %trap |
| 86 | +; CHECK-NEXT: ud1l 2(%eax), %eax |
| 87 | +; CHECK-NEXT: .LBB2_4: # %trap1 |
| 88 | +; CHECK-NEXT: ud1l 4(%eax), %eax |
| 89 | +entry: |
| 90 | + %0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 127), !nosanitize !5 |
| 91 | + %1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5 |
| 92 | + br i1 %1, label %trap, label %cont, !nosanitize !5 |
| 93 | + |
| 94 | +trap: ; preds = %entry |
| 95 | + tail call void @llvm.ubsantrap(i8 2) #4, !nosanitize !5 |
| 96 | + unreachable, !nosanitize !5 |
| 97 | + |
| 98 | +cont: ; preds = %entry |
| 99 | + %2 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %y, i32 129), !nosanitize !5 |
| 100 | + %3 = extractvalue { i32, i1 } %2, 1, !nosanitize !5 |
| 101 | + br i1 %3, label %trap1, label %cont2, !nosanitize !5 |
| 102 | + |
| 103 | +trap1: ; preds = %cont |
| 104 | + tail call void @llvm.ubsantrap(i8 4) #4, !nosanitize !5 |
| 105 | + unreachable, !nosanitize !5 |
| 106 | + |
| 107 | +cont2: ; preds = %cont |
| 108 | + %4 = extractvalue { i32, i1 } %2, 0, !nosanitize !5 |
| 109 | + %5 = extractvalue { i32, i1 } %0, 0, !nosanitize !5 |
| 110 | + %cond = tail call i32 @llvm.smin.i32(i32 %5, i32 %4) |
| 111 | + ret i32 %cond |
| 112 | +} |
| 113 | + |
| 114 | +; Function Attrs: nounwind uwtable |
| 115 | +define dso_local noundef i32 @m(i32 noundef %x, i32 noundef %y) local_unnamed_addr #0 { |
| 116 | +; CHECK-LABEL: m: |
| 117 | +; CHECK: # %bb.0: # %entry |
| 118 | +; CHECK-NEXT: addl $125, %edi |
| 119 | +; CHECK-NEXT: jo .LBB3_4 |
| 120 | +; CHECK-NEXT: # %bb.1: # %f.exit |
| 121 | +; CHECK-NEXT: addl $127, %esi |
| 122 | +; CHECK-NEXT: jo .LBB3_5 |
| 123 | +; CHECK-NEXT: # %bb.2: # %g.exit |
| 124 | +; CHECK-NEXT: addl %esi, %edi |
| 125 | +; CHECK-NEXT: jo .LBB3_6 |
| 126 | +; CHECK-NEXT: # %bb.3: # %cont |
| 127 | +; CHECK-NEXT: movl %edi, %eax |
| 128 | +; CHECK-NEXT: retq |
| 129 | +; CHECK-NEXT: .LBB3_4: # %trap.i |
| 130 | +; CHECK-NEXT: ud1l 2(%eax), %eax |
| 131 | +; CHECK-NEXT: .LBB3_5: # %trap.i2 |
| 132 | +; CHECK-NEXT: ud1l 2(%eax), %eax |
| 133 | +; CHECK-NEXT: .LBB3_6: # %trap |
| 134 | +; CHECK-NEXT: ud1l 2(%eax), %eax |
| 135 | +entry: |
| 136 | + %0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %x, i32 125), !nosanitize !5 |
| 137 | + %1 = extractvalue { i32, i1 } %0, 1, !nosanitize !5 |
| 138 | + br i1 %1, label %trap.i, label %f.exit, !nosanitize !5 |
| 139 | + |
| 140 | +trap.i: ; preds = %entry |
| 141 | + tail call void @llvm.ubsantrap(i8 2) #4, !nosanitize !5 |
| 142 | + unreachable, !nosanitize !5 |
| 143 | + |
| 144 | +f.exit: ; preds = %entry |
| 145 | + %2 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %y, i32 127), !nosanitize !5 |
| 146 | + %3 = extractvalue { i32, i1 } %2, 1, !nosanitize !5 |
| 147 | + br i1 %3, label %trap.i2, label %g.exit, !nosanitize !5 |
| 148 | + |
| 149 | +trap.i2: ; preds = %f.exit |
| 150 | + tail call void @llvm.ubsantrap(i8 2) #4, !nosanitize !5 |
| 151 | + unreachable, !nosanitize !5 |
| 152 | + |
| 153 | +g.exit: ; preds = %f.exit |
| 154 | + %4 = extractvalue { i32, i1 } %0, 0, !nosanitize !5 |
| 155 | + %5 = extractvalue { i32, i1 } %2, 0, !nosanitize !5 |
| 156 | + %6 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %4, i32 %5), !nosanitize !5 |
| 157 | + %7 = extractvalue { i32, i1 } %6, 1, !nosanitize !5 |
| 158 | + br i1 %7, label %trap, label %cont, !nosanitize !5 |
| 159 | + |
| 160 | +trap: ; preds = %g.exit |
| 161 | + tail call void @llvm.ubsantrap(i8 2) #4, !nosanitize !5 |
| 162 | + unreachable, !nosanitize !5 |
| 163 | + |
| 164 | +cont: ; preds = %g.exit |
| 165 | + %8 = extractvalue { i32, i1 } %6, 0, !nosanitize !5 |
| 166 | + ret i32 %8 |
| 167 | +} |
| 168 | + |
| 169 | +; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) |
| 170 | +declare i32 @llvm.smin.i32(i32, i32) #3 |
| 171 | + |
| 172 | +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" } |
| 173 | +attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) } |
| 174 | +attributes #2 = { cold noreturn nounwind } |
| 175 | +attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } |
| 176 | +attributes #4 = { nomerge noreturn nounwind } |
| 177 | + |
| 178 | +!llvm.module.flags = !{!0, !1, !2, !3} |
| 179 | +!llvm.ident = !{!4} |
| 180 | + |
| 181 | +!0 = !{i32 1, !"wchar_size", i32 4} |
| 182 | +!1 = !{i32 8, !"PIC Level", i32 2} |
| 183 | +!2 = !{i32 7, !"PIE Level", i32 2} |
| 184 | +!3 = !{i32 7, !"uwtable", i32 2} |
| 185 | +!4 = !{!"clang version 20.0.0git (https://github.com/llvm/llvm-project.git fe3c23b439b9a2d00442d9bc6a4ca86f73066a3d)"} |
| 186 | +!5 = !{} |
0 commit comments