Fangrui Song 6b3351792c [test] Add {{.*}} to make tests immune to dso_local/dso_preemptable/(none) differences
For a definition (of most linkage types), dso_local is set for ELF -fno-pic/-fpie
and COFF, but not for Mach-O.  This nuance causes unneeded binary format differences.

This patch replaces (function) `define ` with `define{{.*}} `,
(variable/constant/alias) `= ` with `={{.*}} `, or inserts appropriate `{{.*}} `
if there is an explicit linkage.

* Clang will set dso_local for Mach-O, which is currently implied by TargetMachine.cpp. This will make COFF/Mach-O and executable ELF similar.
* Eventually I hope we can make dso_local the textual LLVM IR default (write explicit "dso_preemptable" when applicable) and -fpic ELF will be similar to everything else. This patch helps move toward that goal.
2020-12-30 20:52:01 -08:00

62 lines
2.1 KiB
C

// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ftrapv %s -emit-llvm -o - | FileCheck %s
unsigned int ui, uj, uk;
int i, j, k;
// CHECK-LABEL: define{{.*}} void @test0()
void test0() {
// -ftrapv doesn't affect unsigned arithmetic.
// CHECK: [[T1:%.*]] = load i32, i32* @uj
// CHECK-NEXT: [[T2:%.*]] = load i32, i32* @uk
// CHECK-NEXT: [[T3:%.*]] = add i32 [[T1]], [[T2]]
// CHECK-NEXT: store i32 [[T3]], i32* @ui
ui = uj + uk;
// CHECK: [[T1:%.*]] = load i32, i32* @j
// CHECK-NEXT: [[T2:%.*]] = load i32, i32* @k
// CHECK-NEXT: [[T3:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 [[T2]])
// CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T3]], 0
// CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T3]], 1
// CHECK-NEXT: [[T6:%.*]] = xor i1 [[T5]], true
// CHECK-NEXT: br i1 [[T6]]
// CHECK: call void @llvm.ubsantrap(i8 0)
i = j + k;
}
// CHECK-LABEL: define{{.*}} void @test1()
void test1() {
extern void opaque(int);
opaque(i++);
// CHECK: [[T1:%.*]] = load i32, i32* @i
// CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
// CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
// CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
// CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
// CHECK-NEXT: br i1 [[T5]]
// CHECK: call void @llvm.ubsantrap(i8 0)
}
// CHECK-LABEL: define{{.*}} void @test2()
void test2() {
extern void opaque(int);
opaque(++i);
// CHECK: [[T1:%.*]] = load i32, i32* @i
// CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
// CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
// CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
// CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
// CHECK-NEXT: br i1 [[T5]]
// CHECK: call void @llvm.ubsantrap(i8 0)
}
// CHECK-LABEL: define{{.*}} void @test3(
void test3(int a, int b, float c, float d) {
// CHECK-NOT: @llvm.trap
(void)(a / b);
(void)(a % b);
(void)(c / d);
// CHECK: }
}