[clang] a181819 - [NFC][clang] Add a CHECK lines to tests checking offsetof-like expressions

Alex Richardson via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 28 09:58:05 PDT 2021


Author: Alex Richardson
Date: 2021-09-28T17:57:36+01:00
New Revision: a18181931f991b04caea297e723db415756f09a0

URL: https://github.com/llvm/llvm-project/commit/a18181931f991b04caea297e723db415756f09a0
DIFF: https://github.com/llvm/llvm-project/commit/a18181931f991b04caea297e723db415756f09a0.diff

LOG: [NFC][clang] Add a CHECK lines to tests checking offsetof-like expressions

I am looking at constant-folding changes that could affect these tests, so
check that it emits the expected global value instead of just checking
that it doesn't crash.

Added: 
    

Modified: 
    clang/test/CodeGen/2005-01-02-ConstantInits.c
    clang/test/CodeGenCXX/2005-01-03-StaticInitializers.cpp
    clang/test/CodeGenCXX/2008-05-07-CrazyOffsetOf.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGen/2005-01-02-ConstantInits.c b/clang/test/CodeGen/2005-01-02-ConstantInits.c
index d85f5198650d..fca10041dec8 100644
--- a/clang/test/CodeGen/2005-01-02-ConstantInits.c
+++ b/clang/test/CodeGen/2005-01-02-ConstantInits.c
@@ -1,10 +1,24 @@
-// RUN: %clang_cc1 %s -emit-llvm -o -
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-globals --global-value-regex "@.+"
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux %s -emit-llvm -o - | FileCheck %s
 
 // This tests all kinds of hard cases with initializers and
 // array subscripts.  This corresponds to PR487.
 
 struct X { int a[2]; };
 
+//.
+// CHECK: @test.i23 = internal global i32 4, align 4
+// CHECK: @i = global i32 4, align 4
+// CHECK: @Arr = global [100 x i32] zeroinitializer, align 16
+// CHECK: @foo2.X = internal global i32* bitcast (i8* getelementptr (i8, i8* bitcast ([100 x i32]* @Arr to i8*), i64 196) to i32*), align 8
+// CHECK: @foo2.i23 = internal global i32 0, align 4
+//.
+// CHECK-LABEL: define {{[^@]+}}@test
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* @test.i23, align 4
+// CHECK-NEXT:    ret i32 [[TMP0]]
+//
 int test() {
   static int i23 = (int) &(((struct X *)0)->a[1]);
   return i23;
@@ -14,11 +28,40 @@ int i = (int) &( ((struct X *)0) -> a[1]);
 
 int Arr[100];
 
+// CHECK-LABEL: define {{[^@]+}}@foo
+// CHECK-SAME: (i32 [[I:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[I_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    store i32 [[I]], i32* [[I_ADDR]], align 4
+// CHECK-NEXT:    [[CALL:%.*]] = call i32 (i32*, ...) bitcast (i32 (...)* @bar to i32 (i32*, ...)*)(i32* getelementptr inbounds ([100 x i32], [100 x i32]* @Arr, i64 0, i64 49))
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[I_ADDR]], align 4
+// CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP0]] to i64
+// CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [100 x i32], [100 x i32]* @Arr, i64 0, i64 [[IDXPROM]]
+// CHECK-NEXT:    [[CALL1:%.*]] = call i32 (i32*, ...) bitcast (i32 (...)* @bar to i32 (i32*, ...)*)(i32* [[ARRAYIDX]])
+// CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[CALL]], [[CALL1]]
+// CHECK-NEXT:    ret i32 [[ADD]]
+//
 int foo(int i) { return bar(&Arr[49])+bar(&Arr[i]); }
-int foo2(int i) { 
+// CHECK-LABEL: define {{[^@]+}}@foo2
+// CHECK-SAME: (i32 [[I:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[I_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    [[P:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:    store i32 [[I]], i32* [[I_ADDR]], align 4
+// CHECK-NEXT:    store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @Arr, i64 0, i64 0), i32** [[P]], align 8
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32*, i32** [[P]], align 8
+// CHECK-NEXT:    [[INCDEC_PTR:%.*]] = getelementptr inbounds i32, i32* [[TMP0]], i32 1
+// CHECK-NEXT:    store i32* [[INCDEC_PTR]], i32** [[P]], align 8
+// CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[I_ADDR]], align 4
+// CHECK-NEXT:    [[IDX_EXT:%.*]] = sext i32 [[TMP1]] to i64
+// CHECK-NEXT:    [[ADD_PTR:%.*]] = getelementptr inbounds i32, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @Arr, i64 0, i64 0), i64 [[IDX_EXT]]
+// CHECK-NEXT:    [[CALL:%.*]] = call i32 (i32*, ...) bitcast (i32 (...)* @bar to i32 (i32*, ...)*)(i32* [[ADD_PTR]])
+// CHECK-NEXT:    ret i32 [[CALL]]
+//
+int foo2(int i) {
   static const int *X = &Arr[49];
    static int i23 = (int) &( ((struct X *)0) -> a[0]);
   int *P = Arr;
   ++P;
   return bar(Arr+i);
-}
+}
\ No newline at end of file

diff  --git a/clang/test/CodeGenCXX/2005-01-03-StaticInitializers.cpp b/clang/test/CodeGenCXX/2005-01-03-StaticInitializers.cpp
index 1c9d1202afb2..b8078d88a3f7 100644
--- a/clang/test/CodeGenCXX/2005-01-03-StaticInitializers.cpp
+++ b/clang/test/CodeGenCXX/2005-01-03-StaticInitializers.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
-// REQUIRES: LP64
+// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple=i386-linux-gnu -emit-llvm %s -o - | FileCheck %s
 
 struct S {
   int  A[2];
 };
 
-// CHECK-NOT: llvm.global_ctor
+// CHECK: @XX = global i32 4, align 4
 int XX = (int)(long)&(((struct S*)0)->A[1]);

diff  --git a/clang/test/CodeGenCXX/2008-05-07-CrazyOffsetOf.cpp b/clang/test/CodeGenCXX/2008-05-07-CrazyOffsetOf.cpp
index f842f958e9e6..6967df9d94e0 100644
--- a/clang/test/CodeGenCXX/2008-05-07-CrazyOffsetOf.cpp
+++ b/clang/test/CodeGenCXX/2008-05-07-CrazyOffsetOf.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm %s -o -
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s
 // rdar://5914926
 
 struct bork {
@@ -6,3 +6,4 @@ struct bork {
   char * query;
 };
 int offset =  (char *) &(((struct bork *) 0x10)->query) - (char *) 0x10;
+// CHECK: @offset = global i32 8, align 4


        


More information about the cfe-commits mailing list