[test][CodeGen] Don't miss lifetime markers in lifetime tests

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D129789
This commit is contained in:
Vitaly Buka 2022-07-14 10:57:07 -07:00
parent d4f84df0a0
commit a2e01bdcc2
2 changed files with 25 additions and 36 deletions

View File

@ -1,23 +1,21 @@
// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=O0 // RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" -check-prefixes=CHECK
// RUN: %clang -S -emit-llvm -o - -O1 %s | FileCheck %s -check-prefix=O1 // RUN: %clang -S -emit-llvm -o - -O1 %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" -check-prefixes=CHECK,LIFETIME
// RUN: %clang -S -emit-llvm -o - -O2 %s | FileCheck %s -check-prefix=O2 // RUN: %clang -S -emit-llvm -o - -O2 %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" -check-prefixes=CHECK,LIFETIME
// RUN: %clang -S -emit-llvm -o - -O3 %s | FileCheck %s -check-prefix=O3 // RUN: %clang -S -emit-llvm -o - -O3 %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" -check-prefixes=CHECK,LIFETIME
extern void use(char *a); extern void use(char *a);
// CHECK-LABEL: @helper_no_markers
__attribute__((always_inline)) void helper_no_markers(void) { __attribute__((always_inline)) void helper_no_markers(void) {
char a; char a;
// LIFETIME: call void @llvm.lifetime.start.p0(i64 1,
use(&a); use(&a);
// LIFETIME: call void @llvm.lifetime.end.p0(i64 1,
} }
// CHECK-LABEL: @lifetime_test
void lifetime_test(void) { void lifetime_test(void) {
// O0: lifetime_test // LIFETIME: call void @llvm.lifetime.start.p0(i64 1,
// O1: lifetime_test
// O2: lifetime_test
// O3: lifetime_test
// O0-NOT: @llvm.lifetime.start
// O1: @llvm.lifetime.start
// O2: @llvm.lifetime.start
// O3: @llvm.lifetime.start
helper_no_markers(); helper_no_markers();
// LIFETIME: call void @llvm.lifetime.end.p0(i64 1,
} }

View File

@ -1,27 +1,27 @@
// RUN: %clang_cc1 -no-opaque-pointers -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s -check-prefixes=CHECK,O2 // RUN: %clang_cc1 -no-opaque-pointers -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK,O2
// RUN: %clang_cc1 -no-opaque-pointers -S -emit-llvm -o - -O2 -disable-lifetime-markers %s \ // RUN: %clang_cc1 -no-opaque-pointers -S -emit-llvm -o - -O2 -disable-lifetime-markers %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK
// RUN: | FileCheck %s -check-prefixes=CHECK,O0 // RUN: %clang_cc1 -no-opaque-pointers -S -emit-llvm -o - -O0 %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK
// RUN: %clang_cc1 -no-opaque-pointers -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefixes=CHECK,O0
extern int bar(char *A, int n); extern int bar(char *A, int n);
// CHECK-LABEL: @foo // CHECK-LABEL: @foo
// O0-NOT: @llvm.lifetime.start
int foo (int n) { int foo (int n) {
if (n) { if (n) {
// O2: @llvm.lifetime.start // O2: call void @llvm.lifetime.start.p0i8(i64 100,
char A[100]; char A[100];
return bar(A, 1); return bar(A, 1);
// O2: call void @llvm.lifetime.end.p0i8(i64 100,
} else { } else {
// O2: @llvm.lifetime.start // O2: call void @llvm.lifetime.start.p0i8(i64 100,
char A[100]; char A[100];
return bar(A, 2); return bar(A, 2);
// O2: call void @llvm.lifetime.end.p0i8(i64 100,
} }
} }
// CHECK-LABEL: @no_goto_bypass // CHECK-LABEL: @no_goto_bypass
void no_goto_bypass(void) { void no_goto_bypass(void) {
// O2: @llvm.lifetime.start.p0i8(i64 1 // O2: call void @llvm.lifetime.start.p0i8(i64 1,
char x; char x;
l1: l1:
bar(&x, 1); bar(&x, 1);
@ -29,14 +29,11 @@ l1:
bar(y, 5); bar(y, 5);
goto l1; goto l1;
// Infinite loop // Infinite loop
// O2-NOT: @llvm.lifetime.end.p0i8(
} }
// CHECK-LABEL: @goto_bypass // CHECK-LABEL: @goto_bypass
void goto_bypass(void) { void goto_bypass(void) {
{ {
// O2-NOT: @llvm.lifetime.start.p0i8(i64 1
// O2-NOT: @llvm.lifetime.end.p0i8(i64 1
char x; char x;
l1: l1:
bar(&x, 1); bar(&x, 1);
@ -48,16 +45,16 @@ void goto_bypass(void) {
void no_switch_bypass(int n) { void no_switch_bypass(int n) {
switch (n) { switch (n) {
case 1: { case 1: {
// O2: @llvm.lifetime.start.p0i8(i64 1 // O2: call void @llvm.lifetime.start.p0i8(i64 1,
// O2: @llvm.lifetime.end.p0i8(i64 1 // O2: call void @llvm.lifetime.end.p0i8(i64 1,
char x; char x;
bar(&x, 1); bar(&x, 1);
break; break;
} }
case 2: case 2:
n = n; n = n;
// O2: @llvm.lifetime.start.p0i8(i64 5 // O2: call void @llvm.lifetime.start.p0i8(i64 5,
// O2: @llvm.lifetime.end.p0i8(i64 5 // O2: call void @llvm.lifetime.end.p0i8(i64 5,
char y[5]; char y[5];
bar(y, 5); bar(y, 5);
break; break;
@ -69,8 +66,6 @@ void switch_bypass(int n) {
switch (n) { switch (n) {
case 1: case 1:
n = n; n = n;
// O2-NOT: @llvm.lifetime.start.p0i8(i64 1
// O2-NOT: @llvm.lifetime.end.p0i8(i64 1
char x; char x;
bar(&x, 1); bar(&x, 1);
break; break;
@ -83,23 +78,18 @@ void switch_bypass(int n) {
// CHECK-LABEL: @indirect_jump // CHECK-LABEL: @indirect_jump
void indirect_jump(int n) { void indirect_jump(int n) {
char x; char x;
// O2-NOT: @llvm.lifetime
void *T[] = {&&L}; void *T[] = {&&L};
goto *T[n]; goto *T[n];
L: L:
bar(&x, 1); bar(&x, 1);
} }
// O2-LABEL: @jump_backward_over_declaration(
// O2: %[[p:.*]] = alloca i32*
// O2: %[[v0:.*]] = bitcast i32** %[[p]] to i8*
// O2: call void @llvm.lifetime.start.p0i8(i64 {{.*}}, i8* %[[v0]])
// O2-NOT: call void @llvm.lifetime.start.p0i8(
extern void foo2(int p); extern void foo2(int p);
// O2-LABEL: @jump_backward_over_declaration(
int jump_backward_over_declaration(int a) { int jump_backward_over_declaration(int a) {
int *p = 0; int *p = 0;
// O2: call void @llvm.lifetime.start.p0i8(i64 8,
label1: label1:
if (p) { if (p) {
foo2(*p); foo2(*p);
@ -112,4 +102,5 @@ label1:
goto label1; goto label1;
} }
return -1; return -1;
// O2: call void @llvm.lifetime.end.p0i8(i64 8,
} }