Specifically for: !tbaa, !tbaa.struct, !annotation, !srcloc, !nosanitize.
The goal is to avoid test brittleness caused by hardcoded values.
Differential Revision: https://reviews.llvm.org/D123273
--- /dev/null
+// 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];
+}
--- /dev/null
+// 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];
+}
--- /dev/null
+// 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);
+}
--- /dev/null
+// 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);
+}
--- /dev/null
+// 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();
+}
--- /dev/null
+// 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();
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+## 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
--- /dev/null
+## 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
--- /dev/null
+## 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
--- /dev/null
+## 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
--- /dev/null
+## 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
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):