diff --git a/clang/test/utils/update_cc_test_checks/Inputs/annotation-id.c b/clang/test/utils/update_cc_test_checks/Inputs/annotation-id.c new file mode 100644 index 00000000000000..49c7c58375db51 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/annotation-id.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -ftrivial-auto-var-init=zero -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +void foo_ptr_to_scalar() { + unsigned long long* a[100]; +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/annotation-id.expected b/clang/test/utils/update_cc_test_checks/Inputs/annotation-id.expected new file mode 100644 index 00000000000000..d28469eb920dc0 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/annotation-id.expected @@ -0,0 +1,17 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -ftrivial-auto-var-init=zero -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: @foo_ptr_to_scalar( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[A:%.*]] = alloca [100 x i64*], align 16 +// CHECK-NEXT: [[TMP0:%.*]] = bitcast [100 x i64*]* [[A]] to i8* +// CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 800, i8* [[TMP0]]) #[[ATTR3:[0-9]+]] +// CHECK-NEXT: [[TMP1:%.*]] = bitcast [100 x i64*]* [[A]] to i8* +// CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 16 [[TMP1]], i8 0, i64 800, i1 false), !annotation [[ANNT2:![0-9]+]] +// CHECK-NEXT: [[TMP2:%.*]] = bitcast [100 x i64*]* [[A]] to i8* +// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 800, i8* [[TMP2]]) #[[ATTR3]] +// CHECK-NEXT: ret void +// +void foo_ptr_to_scalar() { + unsigned long long* a[100]; +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/nosanitize-id.c b/clang/test/utils/update_cc_test_checks/Inputs/nosanitize-id.c new file mode 100644 index 00000000000000..d136a861b42149 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/nosanitize-id.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsanitize=shift-exponent,shift-base -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +void foo(int* c, int* shamt) { + *c = 1 << (*c << *shamt); +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/nosanitize-id.expected b/clang/test/utils/update_cc_test_checks/Inputs/nosanitize-id.expected new file mode 100644 index 00000000000000..e8e1c74e46bc66 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/nosanitize-id.expected @@ -0,0 +1,55 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -fsanitize=shift-exponent,shift-base -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: @foo( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[C_ADDR:%.*]] = alloca i32*, align 8 +// CHECK-NEXT: [[SHAMT_ADDR:%.*]] = alloca i32*, align 8 +// CHECK-NEXT: store i32* [[C:%.*]], i32** [[C_ADDR]], align 8, !tbaa [[TBAA2:![0-9]+]] +// CHECK-NEXT: store i32* [[SHAMT:%.*]], i32** [[SHAMT_ADDR]], align 8, !tbaa [[TBAA2]] +// CHECK-NEXT: [[TMP0:%.*]] = load i32*, i32** [[C_ADDR]], align 8, !tbaa [[TBAA2]] +// CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4, !tbaa [[TBAA6:![0-9]+]] +// CHECK-NEXT: [[TMP2:%.*]] = load i32*, i32** [[SHAMT_ADDR]], align 8, !tbaa [[TBAA2]] +// CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4, !tbaa [[TBAA6]] +// CHECK-NEXT: [[TMP4:%.*]] = icmp ule i32 [[TMP3]], 31, !nosanitize [[NOSAN8:![0-9]+]] +// CHECK-NEXT: br i1 [[TMP4]], label [[CHECK:%.*]], label [[CONT:%.*]], !nosanitize [[NOSAN8]] +// CHECK: check: +// CHECK-NEXT: [[SHL_ZEROS:%.*]] = sub nuw nsw i32 31, [[TMP3]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: [[SHL_CHECK:%.*]] = lshr i32 [[TMP1]], [[SHL_ZEROS]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[SHL_CHECK]], 0, !nosanitize [[NOSAN8]] +// CHECK-NEXT: br label [[CONT]], !nosanitize [[NOSAN8]] +// CHECK: cont: +// CHECK-NEXT: [[TMP6:%.*]] = phi i1 [ true, [[ENTRY:%.*]] ], [ [[TMP5]], [[CHECK]] ], !nosanitize [[NOSAN8]] +// CHECK-NEXT: [[TMP7:%.*]] = and i1 [[TMP4]], [[TMP6]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: br i1 [[TMP7]], label [[CONT1:%.*]], label [[HANDLER_SHIFT_OUT_OF_BOUNDS:%.*]], !prof [[PROF9:![0-9]+]], !nosanitize [[NOSAN8]] +// CHECK: handler.shift_out_of_bounds: +// CHECK-NEXT: [[TMP8:%.*]] = zext i32 [[TMP1]] to i64, !nosanitize [[NOSAN8]] +// CHECK-NEXT: [[TMP9:%.*]] = zext i32 [[TMP3]] to i64, !nosanitize [[NOSAN8]] +// CHECK-NEXT: call void @__ubsan_handle_shift_out_of_bounds_abort(i8* bitcast ({ { [124 x i8]*, i32, i32 }, { i16, i16, [6 x i8] }*, { i16, i16, [6 x i8] }* }* @[[GLOB1:[0-9]+]] to i8*), i64 [[TMP8]], i64 [[TMP9]]) #[[ATTR2:[0-9]+]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: unreachable, !nosanitize [[NOSAN8]] +// CHECK: cont1: +// CHECK-NEXT: [[SHL:%.*]] = shl i32 [[TMP1]], [[TMP3]] +// CHECK-NEXT: [[TMP10:%.*]] = icmp ule i32 [[SHL]], 31, !nosanitize [[NOSAN8]] +// CHECK-NEXT: br i1 [[TMP10]], label [[CHECK2:%.*]], label [[CONT5:%.*]], !nosanitize [[NOSAN8]] +// CHECK: check2: +// CHECK-NEXT: [[SHL_ZEROS3:%.*]] = sub nuw nsw i32 31, [[SHL]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: [[SHL_CHECK4:%.*]] = lshr i32 1, [[SHL_ZEROS3]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: [[TMP11:%.*]] = icmp eq i32 [[SHL_CHECK4]], 0, !nosanitize [[NOSAN8]] +// CHECK-NEXT: br label [[CONT5]], !nosanitize [[NOSAN8]] +// CHECK: cont5: +// CHECK-NEXT: [[TMP12:%.*]] = phi i1 [ true, [[CONT1]] ], [ [[TMP11]], [[CHECK2]] ], !nosanitize [[NOSAN8]] +// CHECK-NEXT: [[TMP13:%.*]] = and i1 [[TMP10]], [[TMP12]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: br i1 [[TMP13]], label [[CONT7:%.*]], label [[HANDLER_SHIFT_OUT_OF_BOUNDS6:%.*]], !prof [[PROF9]], !nosanitize [[NOSAN8]] +// CHECK: handler.shift_out_of_bounds6: +// CHECK-NEXT: [[TMP14:%.*]] = zext i32 [[SHL]] to i64, !nosanitize [[NOSAN8]] +// CHECK-NEXT: call void @__ubsan_handle_shift_out_of_bounds_abort(i8* bitcast ({ { [124 x i8]*, i32, i32 }, { i16, i16, [6 x i8] }*, { i16, i16, [6 x i8] }* }* @[[GLOB2:[0-9]+]] to i8*), i64 1, i64 [[TMP14]]) #[[ATTR2]], !nosanitize [[NOSAN8]] +// CHECK-NEXT: unreachable, !nosanitize [[NOSAN8]] +// CHECK: cont7: +// CHECK-NEXT: [[SHL8:%.*]] = shl i32 1, [[SHL]] +// CHECK-NEXT: [[TMP15:%.*]] = load i32*, i32** [[C_ADDR]], align 8, !tbaa [[TBAA2]] +// CHECK-NEXT: store i32 [[SHL8]], i32* [[TMP15]], align 4, !tbaa [[TBAA6]] +// CHECK-NEXT: ret void +// +void foo(int* c, int* shamt) { + *c = 1 << (*c << *shamt); +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/srcloc-id.c b/clang/test/utils/update_cc_test_checks/Inputs/srcloc-id.c new file mode 100644 index 00000000000000..aac86db47349a8 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/srcloc-id.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s +__attribute__((error("oh no"))) void foo(void); + +void bar(void) { + foo(); +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/srcloc-id.expected b/clang/test/utils/update_cc_test_checks/Inputs/srcloc-id.expected new file mode 100644 index 00000000000000..a304012713d3c6 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/srcloc-id.expected @@ -0,0 +1,12 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s +__attribute__((error("oh no"))) void foo(void); + +// CHECK-LABEL: @bar( +// CHECK-NEXT: entry: +// CHECK-NEXT: call void @foo(), !srcloc [[SRCLOC2:![0-9]+]] +// CHECK-NEXT: ret void +// +void bar(void) { + foo(); +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/tbaa-id.c b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-id.c new file mode 100644 index 00000000000000..28a111cf14a9c0 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-id.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +void foo(unsigned **ptr) { + *ptr = 0; +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/tbaa-id.expected b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-id.expected new file mode 100644 index 00000000000000..0eb4fc4d721f39 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-id.expected @@ -0,0 +1,14 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -O1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: @foo( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[PTR_ADDR:%.*]] = alloca i32**, align 8 +// CHECK-NEXT: store i32** [[PTR:%.*]], i32*** [[PTR_ADDR]], align 8, !tbaa [[TBAA2:![0-9]+]] +// CHECK-NEXT: [[TMP0:%.*]] = load i32**, i32*** [[PTR_ADDR]], align 8, !tbaa [[TBAA2]] +// CHECK-NEXT: store i32* null, i32** [[TMP0]], align 8, !tbaa [[TBAA2]] +// CHECK-NEXT: ret void +// +void foo(unsigned **ptr) { + *ptr = 0; +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/tbaa-struct-id.c b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-struct-id.c new file mode 100644 index 00000000000000..c3043ffd110f4a --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-struct-id.c @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -flegacy-pass-manager -triple arm64-apple-iphoneos -Oz -mllvm -enable-constraint-elimination=true -fpass-by-value-is-noalias -emit-llvm -o - %s | FileCheck %s + +typedef struct { + void *a; + void *b; + void *c; + void *d; + void *e; +} Foo; + +static void bar(Foo f) { + if (f.b) + __builtin_trap(); +} + +static int baz(Foo f) { + bar(f); + return *(int *)f.a; +} + +int barbar(Foo arg) { + int a, b; + a = baz(arg); + return a - b; +} diff --git a/clang/test/utils/update_cc_test_checks/Inputs/tbaa-struct-id.expected b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-struct-id.expected new file mode 100644 index 00000000000000..aa4106d69984a2 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/Inputs/tbaa-struct-id.expected @@ -0,0 +1,38 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -flegacy-pass-manager -triple arm64-apple-iphoneos -Oz -mllvm -enable-constraint-elimination=true -fpass-by-value-is-noalias -emit-llvm -o - %s | FileCheck %s + +typedef struct { + void *a; + void *b; + void *c; + void *d; + void *e; +} Foo; + +static void bar(Foo f) { + if (f.b) + __builtin_trap(); +} + +static int baz(Foo f) { + bar(f); + return *(int *)f.a; +} + +// CHECK-LABEL: @barbar( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[BYVAL_TEMP_SROA_3_0__SROA_IDX4:%.*]] = getelementptr inbounds [[STRUCT_FOO:%.*]], %struct.Foo* [[ARG:%.*]], i64 0, i32 1 +// CHECK-NEXT: [[BYVAL_TEMP_SROA_3_0_COPYLOAD:%.*]] = load i8*, i8** [[BYVAL_TEMP_SROA_3_0__SROA_IDX4]], align 8, !tbaa.struct [[TBAAST6:![0-9]+]] +// CHECK-NEXT: [[TOBOOL_NOT_I_I:%.*]] = icmp eq i8* [[BYVAL_TEMP_SROA_3_0_COPYLOAD]], null +// CHECK-NEXT: br i1 [[TOBOOL_NOT_I_I]], label [[BAZ_EXIT:%.*]], label [[IF_THEN_I_I:%.*]] +// CHECK: if.then.i.i: +// CHECK-NEXT: tail call void @llvm.trap() #[[ATTR2:[0-9]+]], !noalias !11 +// CHECK-NEXT: unreachable +// CHECK: baz.exit: +// CHECK-NEXT: ret i32 undef +// +int barbar(Foo arg) { + int a, b; + a = baz(arg); + return a - b; +} diff --git a/clang/test/utils/update_cc_test_checks/annotation-id.test b/clang/test/utils/update_cc_test_checks/annotation-id.test new file mode 100644 index 00000000000000..b3c3d4ed0717ef --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/annotation-id.test @@ -0,0 +1,7 @@ +## Test that CHECK lines are generated before the definion and not the declaration + +# RUN: cp %S/Inputs/annotation-id.c %t.c && %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/annotation-id.expected %t.c +## Check that re-running update_cc_test_checks doesn't change the output +# RUN: %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/annotation-id.expected %t.c diff --git a/clang/test/utils/update_cc_test_checks/nosanitize-id.test b/clang/test/utils/update_cc_test_checks/nosanitize-id.test new file mode 100644 index 00000000000000..c48653494a5962 --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/nosanitize-id.test @@ -0,0 +1,7 @@ +## Test that CHECK lines are generated before the definion and not the declaration + +# RUN: cp %S/Inputs/nosanitize-id.c %t.c && %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/nosanitize-id.expected %t.c +## Check that re-running update_cc_test_checks doesn't change the output +# RUN: %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/nosanitize-id.expected %t.c diff --git a/clang/test/utils/update_cc_test_checks/srcloc-id.test b/clang/test/utils/update_cc_test_checks/srcloc-id.test new file mode 100644 index 00000000000000..0bdc25c70e61bf --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/srcloc-id.test @@ -0,0 +1,7 @@ +## Test that CHECK lines are generated before the definion and not the declaration + +# RUN: cp %S/Inputs/srcloc-id.c %t.c && %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/srcloc-id.expected %t.c +## Check that re-running update_cc_test_checks doesn't change the output +# RUN: %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/srcloc-id.expected %t.c diff --git a/clang/test/utils/update_cc_test_checks/tbaa-id.test b/clang/test/utils/update_cc_test_checks/tbaa-id.test new file mode 100644 index 00000000000000..7f9efa37fd1e1e --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/tbaa-id.test @@ -0,0 +1,7 @@ +## Test that CHECK lines are generated before the definion and not the declaration + +# RUN: cp %S/Inputs/tbaa-id.c %t.c && %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/tbaa-id.expected %t.c +## Check that re-running update_cc_test_checks doesn't change the output +# RUN: %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/tbaa-id.expected %t.c diff --git a/clang/test/utils/update_cc_test_checks/tbaa-struct-id.test b/clang/test/utils/update_cc_test_checks/tbaa-struct-id.test new file mode 100644 index 00000000000000..802f74b39f080b --- /dev/null +++ b/clang/test/utils/update_cc_test_checks/tbaa-struct-id.test @@ -0,0 +1,7 @@ +## Test that CHECK lines are generated before the definion and not the declaration + +# RUN: cp %S/Inputs/tbaa-struct-id.c %t.c && %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/tbaa-struct-id.expected %t.c +## Check that re-running update_cc_test_checks doesn't change the output +# RUN: %update_cc_test_checks %t.c +# RUN: diff -u %S/Inputs/tbaa-struct-id.expected %t.c diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index e5db6fb403af97..5c16ff6fd94e89 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -616,11 +616,15 @@ def __init__(self, check_prefix, check_key, ir_prefix, global_ir_prefix, global_ NamelessValue(r'GLOB' , '@' , None , r'@' , r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+' , True) , NamelessValue(r'DBG' , '!' , r'!dbg ' , None , None , r'![0-9]+' , None , False) , NamelessValue(r'PROF' , '!' , r'!prof ' , None , None , r'![0-9]+' , None , False) , - NamelessValue(r'TBAA' , '!' , r'!tbaa ' , None , None , r'![0-9]+' , None , False) , NamelessValue(r'RNG' , '!' , r'!range ' , None , None , r'![0-9]+' , None , False) , NamelessValue(r'LOOP' , '!' , r'!llvm.loop ' , None , None , r'![0-9]+' , None , False) , NamelessValue(r'META' , '!' , r'metadata ' , None , None , r'![0-9]+' , None , False) , NamelessValue(r'META' , '!' , None , r'' , r'![0-9]+' , None , r'(?:distinct |)!.*' , False) , + NamelessValue(r'TBAA' , '!' , r'!tbaa ' , None , None , r'![0-9]+' , None , False) , + NamelessValue(r'TBAAST' , '!' , r'!tbaa.struct ', None , None , r'![0-9]+' , None , False) , + NamelessValue(r'ANNT' , '!' , r'!annotation ' , None , None , r'![0-9]+' , None , False) , + NamelessValue(r'SRCLOC' , '!' , r'!srcloc ' , None , None , r'![0-9]+' , None , False) , + NamelessValue(r'NOSAN' , '!' , r'!nosanitize ' , None , None , r'![0-9]+' , None , False) , ] def createOrRegexp(old, new):