Skip to content

Commit

Permalink
[Clang] Convert some tests to opaque pointers (NFC)
Browse files Browse the repository at this point in the history
These tests all require some adjustments to make sure that struct
types still get generated, mostly done by stripping pointer
indirections.

Some of this may no longer test the situation it was originally
intended for, e.g. the issue from pr18962 just doesn't really
exist anymore with opaque pointers, as we no longer generate
recursive types.
  • Loading branch information
nikic committed Jun 8, 2023
1 parent 0e3426f commit 32791f1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
20 changes: 10 additions & 10 deletions clang/test/CodeGenCXX/class-layout.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// RUN: %clang_cc1 -no-opaque-pointers %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s

// An extra byte should be allocated for an empty class.
namespace Test1 {
// CHECK: %"struct.Test1::A" = type { i8 }
struct A { } *a;
struct A { } a;
}

namespace Test2 {
// No need to add tail padding here.
// CHECK: %"struct.Test2::A" = type { i8*, i32 }
struct A { void *a; int b; } *a;
// CHECK: %"struct.Test2::A" = type { ptr, i32 }
struct A { void *a; int b; } a;
}

namespace Test3 {
// C should have a vtable pointer.
// CHECK: %"struct.Test3::A" = type <{ i32 (...)**, i32, [4 x i8] }>
struct A { virtual void f(); int a; } *a;
// CHECK: %"struct.Test3::A" = type <{ ptr, i32, [4 x i8] }>
struct A { virtual void f(); int a; } a;
}

namespace Test4 {
Expand All @@ -30,7 +30,7 @@ namespace Test4 {
struct B : public A {
short d;
double e;
} *b;
} b;
}

namespace Test5 {
Expand All @@ -43,7 +43,7 @@ namespace Test5 {
struct B : A {
char b : 1;
char c;
} *b;
} b;
}

// PR10912: don't crash
Expand Down Expand Up @@ -83,12 +83,12 @@ namespace Test6 {
namespace Test7 {
#pragma pack (1)
class A {};
// CHECK: %"class.Test7::B" = type <{ i32 (...)**, %"class.Test7::A" }>
// CHECK: %"class.Test7::B" = type <{ ptr, %"class.Test7::A" }>
class B {
virtual ~B();
A a;
};
B* b;
B test(B b) { return b; }
#pragma pack ()
}

Expand Down
10 changes: 5 additions & 5 deletions clang/test/CodeGenCXX/member-data-pointers.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-unknown | FileCheck -check-prefix GLOBAL-LP64 %s
// RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=armv7-unknown-unknown | FileCheck -check-prefix GLOBAL-LP32 %s
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-unknown | FileCheck -check-prefix GLOBAL-LP64 %s
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv7-unknown-unknown | FileCheck -check-prefix GLOBAL-LP32 %s

struct A;
typedef int A::*param_t;
struct {
const char *name;
param_t par;
} *ptr;
} ptr;
void test_ptr() { (void) ptr; } // forced use

// GLOBAL-LP64: type { i8*, i64 }
// GLOBAL-LP32: type { i8*, i32 }
// GLOBAL-LP64: type { ptr, i64 }
// GLOBAL-LP32: type { ptr, i32 }
23 changes: 14 additions & 9 deletions clang/test/CodeGenCXX/microsoft-inaccessible-base.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// RUN: %clang_cc1 -no-opaque-pointers -fms-compatibility -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -fms-compatibility -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s

// Make sure we choose the *direct* base path when doing these conversions.

// CHECK: %struct.C = type { %struct.A, %struct.B }
// CHECK: %struct.D = type { %struct.B, %struct.A }

struct A { int a; };
struct B : A { int b; };

struct C : A, B { };
extern "C" A *a_from_c(C *p) { return p; }
// CHECK-LABEL: define dso_local %struct.A* @a_from_c(%struct.C* noundef %{{.*}})
// CHECK: bitcast %struct.C* %{{.*}} to %struct.A*
// CHECK-LABEL: define dso_local ptr @a_from_c(ptr noundef %{{.*}})
// CHECK: [[P_ADDR:%.*]] = alloca ptr
// CHECK-NEXT: store ptr [[P:%.*]], ptr [[P_ADDR]]
// CHECK-NEXT: [[RET:%.*]] = load ptr, ptr [[P_ADDR]]
// CHECK-NEXT: ret ptr [[RET]]

struct D : B, A { };
extern "C" A *a_from_d(D *p) { return p; }
// CHECK-LABEL: define dso_local %struct.A* @a_from_d(%struct.D* noundef %{{.*}})
// CHECK: %[[p_i8:[^ ]*]] = bitcast %struct.D* %{{.*}} to i8*
// CHECK: getelementptr inbounds i8, i8* %[[p_i8]], i64 8
// CHECK-LABEL: define dso_local ptr @a_from_d(ptr noundef %{{.*}})
// CHECK: [[P_ADDR:%.*]] = alloca ptr
// CHECK-NEXT: store ptr [[P:%.*]], ptr [[P_ADDR]]
// CHECK-NEXT: [[P_RELOAD:%.*]] = load ptr, ptr [[P_ADDR]]
// CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P_RELOAD]], null
// CHECK: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[P_RELOAD]], i64 8
// CHECK: [[RET:%.*]] = phi ptr [ [[ADD_PTR]], {{.*}} ], [ null, %entry ]
// CHECK-NEXT: ret ptr [[RET]]
19 changes: 8 additions & 11 deletions clang/test/CodeGenCXX/pr18962.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -no-opaque-pointers -triple i686-linux-gnu %s -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -triple i686-linux-gnu %s -emit-llvm -o - | FileCheck %s

class A {
// append has to have the same prototype as fn1 to tickle the bug.
Expand All @@ -17,16 +17,13 @@ class C {
};
class D : C {};

void fn1(A *p1) {
}

void
fn2(C *) {
}
A p1;
C p2;
D p3;

// We end up using an opaque type for 'append' to avoid circular references.
// CHECK: %class.A = type { {}* }
// CHECK: %class.C = type <{ %class.D*, %class.B, [3 x i8] }>
// CHECK: %class.D = type { %class.C.base, [3 x i8] }
// CHECK: %class.C.base = type <{ %class.D*, %class.B }>
// CHECK: %class.A = type { ptr }
// CHECK: %class.C = type <{ ptr, %class.B, [3 x i8] }>
// CHECK: %class.B = type { i8 }
// CHECK: %class.D = type { %class.C.base, [3 x i8] }
// CHECK: %class.C.base = type <{ ptr, %class.B }>

0 comments on commit 32791f1

Please sign in to comment.