Skip to content

Commit ab88da0

Browse files
gitoleglanza
authored andcommitted
[CIR][CodeGen][BugFix] Fixes structures name collisions (#844)
CIR Codegen fails to generate functions with local types with the same names. For instance, the next code : ``` void foo(int a, float b) { struct A { int x; }; struct A loc = {a}; { struct A { float y; }; struct A loc = {b}; } } ``` fails with on the next assertion: `Unable to find record layout information for type`. The problem is that we don't create record layout for the structures with equal names and `CIRGenTypes::convertRecordDeclType` returns the wrong type for the second struct type in the example above. This PR fixes this problem. In the original codegen the call to `Ty->setName(name)` resolves name collisions and assign a proper name for the type. In our case looks like we need to use the same approach as we did for the anonymous structures, i.e. to track the used names in the builder. Also, I fixed the struct type creation. Previously, the type was created several times - first in the `CIRGenTypes::convertRecordDeclType` and then in the `CIRGenTypes::computeRecordLayout`. This is why the indexes used by the anonymous structures naming had relatively big values and this is where the most changes on the tests come from.
1 parent 00d82e3 commit ab88da0

File tree

14 files changed

+83
-60
lines changed

14 files changed

+83
-60
lines changed

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,26 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
5353
llvm::RoundingMode DefaultConstrainedRounding = llvm::RoundingMode::Dynamic;
5454

5555
llvm::StringMap<unsigned> GlobalsVersioning;
56-
llvm::StringSet<> anonRecordNames;
56+
llvm::StringMap<unsigned> RecordNames;
5757

5858
public:
5959
CIRGenBuilderTy(mlir::MLIRContext &C, const CIRGenTypeCache &tc)
60-
: CIRBaseBuilderTy(C), typeCache(tc) {}
60+
: CIRBaseBuilderTy(C), typeCache(tc) {
61+
RecordNames["anon"] = 0; // in order to start from the name "anon.0"
62+
}
6163

6264
std::string getUniqueAnonRecordName() {
63-
std::string name = "anon." + std::to_string(anonRecordNames.size());
64-
anonRecordNames.insert(name);
65-
return name;
65+
return getUniqueRecordName("anon");
66+
}
67+
68+
std::string getUniqueRecordName(const std::string& baseName) {
69+
auto it = RecordNames.find(baseName);
70+
if (it == RecordNames.end()) {
71+
RecordNames[baseName] = 0;
72+
return baseName;
73+
}
74+
75+
return baseName + "." + std::to_string(RecordNames[baseName]++);
6676
}
6777

6878
//

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
9292
if (!suffix.empty())
9393
outStream << suffix;
9494

95-
return std::string(typeName);
95+
return Builder.getUniqueRecordName(std::string(typeName));
9696
}
9797

9898
/// Return true if the specified type is already completely laid out.

clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *D,
689689
// Fill in the struct *after* computing the base type. Filling in the body
690690
// signifies that the type is no longer opaque and record layout is complete,
691691
// but we may need to recursively layout D while laying D out as a base type.
692-
*Ty = Builder.getCompleteStructTy(
693-
builder.fieldTypes, getRecordTypeName(D, ""), builder.isPacked, D);
692+
auto astAttr = mlir::cir::ASTRecordDeclAttr::get(Ty->getContext(), D);
693+
Ty->complete(builder.fieldTypes, builder.isPacked, astAttr);
694694

695695
auto RL = std::make_unique<CIRGenRecordLayout>(
696696
Ty ? *Ty : mlir::cir::StructType{},

clang/test/CIR/CodeGen/bitfields.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ typedef struct {
5555

5656
// CHECK: !ty_D = !cir.struct<struct "D" {!u16i, !s32i}>
5757
// CHECK: !ty_T = !cir.struct<struct "T" {!u8i, !u32i} #cir.record.decl.ast>
58-
// CHECK: !ty_anon2E1_ = !cir.struct<struct "anon.1" {!u32i} #cir.record.decl.ast>
58+
// CHECK: !ty_anon2E0_ = !cir.struct<struct "anon.0" {!u32i} #cir.record.decl.ast>
5959
// CHECK: !ty_anon_struct = !cir.struct<struct {!u8i, !u8i, !s32i}>
6060
// CHECK: #bfi_a = #cir.bitfield_info<name = "a", storage_type = !u8i, size = 3, offset = 0, is_signed = true>
6161
// CHECK: #bfi_e = #cir.bitfield_info<name = "e", storage_type = !u16i, size = 15, offset = 0, is_signed = true>
6262
// CHECK: !ty_S = !cir.struct<struct "S" {!u32i, !cir.array<!u8i x 3>, !u16i, !u32i}>
6363
// CHECK: !ty_U = !cir.struct<struct "U" {!s8i, !s8i, !s8i, !cir.array<!u8i x 9>}>
64-
// CHECK: !ty___long = !cir.struct<struct "__long" {!ty_anon2E1_, !u32i, !cir.ptr<!u32i>}>
64+
// CHECK: !ty___long = !cir.struct<struct "__long" {!ty_anon2E0_, !u32i, !cir.ptr<!u32i>}>
6565
// CHECK: #bfi_d = #cir.bitfield_info<name = "d", storage_type = !cir.array<!u8i x 3>, size = 2, offset = 17, is_signed = true>
6666

6767
// CHECK: cir.func {{.*@store_field}}

clang/test/CIR/CodeGen/bitfields.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ typedef struct {
2828
unsigned b;
2929
} T;
3030
// CHECK: !ty_T = !cir.struct<struct "T" {!u8i, !u32i} #cir.record.decl.ast>
31-
// CHECK: !ty_anon2E1_ = !cir.struct<struct "anon.1" {!u32i} #cir.record.decl.ast>
31+
// CHECK: !ty_anon2E0_ = !cir.struct<struct "anon.0" {!u32i} #cir.record.decl.ast>
3232
// CHECK: !ty_S = !cir.struct<struct "S" {!u32i, !cir.array<!u8i x 3>, !u16i, !u32i}>
33-
// CHECK: !ty___long = !cir.struct<struct "__long" {!ty_anon2E1_, !u32i, !cir.ptr<!u32i>}>
33+
// CHECK: !ty___long = !cir.struct<struct "__long" {!ty_anon2E0_, !u32i, !cir.ptr<!u32i>}>
3434

3535
// CHECK: cir.func @_Z11store_field
3636
// CHECK: [[TMP0:%.*]] = cir.alloca !ty_S, !cir.ptr<!ty_S>

clang/test/CIR/CodeGen/compound-literal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ int foo() {
3737

3838
// CIR: cir.func no_proto @foo() -> !s32i
3939
// CIR: [[RET_MEM:%.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64}
40-
// CIR: [[COMPLITERAL_MEM:%.*]] = cir.alloca !ty_anon2E1_, !cir.ptr<!ty_anon2E1_>, [".compoundliteral"] {alignment = 4 : i64}
41-
// CIR: [[FIELD:%.*]] = cir.get_member [[COMPLITERAL_MEM]][0] {name = "i"} : !cir.ptr<!ty_anon2E1_> -> !cir.ptr<!s32i>
40+
// CIR: [[COMPLITERAL_MEM:%.*]] = cir.alloca !ty_anon2E0_, !cir.ptr<!ty_anon2E0_>, [".compoundliteral"] {alignment = 4 : i64}
41+
// CIR: [[FIELD:%.*]] = cir.get_member [[COMPLITERAL_MEM]][0] {name = "i"} : !cir.ptr<!ty_anon2E0_> -> !cir.ptr<!s32i>
4242
// CIR: [[ONE:%.*]] = cir.const #cir.int<1> : !s32i
4343
// CIR: cir.store [[ONE]], [[FIELD]] : !s32i, !cir.ptr<!s32i>
4444
// CIR: [[ONE:%.*]] = cir.const #cir.int<1> : !s32i

clang/test/CIR/CodeGen/coro-task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ folly::coro::Task<int> go4() {
356356
// CHECK: }
357357

358358
// CHECK: %12 = cir.scope {
359-
// CHECK: %17 = cir.alloca !ty_anon2E5_, !cir.ptr<!ty_anon2E5_>, ["ref.tmp1"] {alignment = 1 : i64}
359+
// CHECK: %17 = cir.alloca !ty_anon2E2_, !cir.ptr<!ty_anon2E2_>, ["ref.tmp1"] {alignment = 1 : i64}
360360

361361
// Get the lambda invoker ptr via `lambda operator folly::coro::Task<int> (*)(int const&)()`
362-
// CHECK: %18 = cir.call @_ZZ3go4vENK3$_0cvPFN5folly4coro4TaskIiEERKiEEv(%17) : (!cir.ptr<!ty_anon2E5_>) -> !cir.ptr<!cir.func<![[IntTask]] (!cir.ptr<!s32i>)>>
362+
// CHECK: %18 = cir.call @_ZZ3go4vENK3$_0cvPFN5folly4coro4TaskIiEERKiEEv(%17) : (!cir.ptr<!ty_anon2E2_>) -> !cir.ptr<!cir.func<![[IntTask]] (!cir.ptr<!s32i>)>>
363363
// CHECK: %19 = cir.unary(plus, %18) : !cir.ptr<!cir.func<![[IntTask]] (!cir.ptr<!s32i>)>>, !cir.ptr<!cir.func<![[IntTask]] (!cir.ptr<!s32i>)>>
364364
// CHECK: cir.yield %19 : !cir.ptr<!cir.func<![[IntTask]] (!cir.ptr<!s32i>)>>
365365
// CHECK: }

clang/test/CIR/CodeGen/forward-decls.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,12 @@ void testIndirectSelfReference(struct StructNodeA arg) {
9696
// RUN: FileCheck --check-prefix=CHECK5 --input-file=%t/complex_struct.cir %s
9797

9898
// A sizeable complex struct just to double check that stuff is working.
99-
100-
// CHECK5: !cir.struct<struct "anon.1" {!cir.ptr<!cir.struct<struct "A" {!cir.struct<struct "anon.1">, !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !cir.struct<struct "C" {!cir.ptr<!cir.struct<struct "A">>, !cir.ptr<!cir.struct<struct "B">>, !cir.ptr<!cir.struct<struct "C">>} #cir.record.decl.ast>, !cir.struct<union "anon.5" {!cir.ptr<!cir.struct<struct "A">>, !cir.struct<struct "anon.4" {!cir.ptr<!cir.struct<struct "B">>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>>} #cir.record.decl.ast>
101-
// CHECK5: !cir.struct<struct "C" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E1_, !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !cir.struct<struct "C">, !cir.struct<union "anon.5" {!cir.ptr<!cir.struct<struct "A">>, !cir.struct<struct "anon.4" {!cir.ptr<!cir.struct<struct "B">>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>>, !cir.ptr<!cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !cir.struct<struct "C">, !cir.struct<union "anon.5" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E1_, !cir.struct<struct "B">} #cir.record.decl.ast>>, !cir.struct<struct "anon.4" {!cir.ptr<!cir.struct<struct "B">>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>>, !cir.ptr<!cir.struct<struct "C">>} #cir.record.decl.ast>
102-
// CHECK5: !cir.struct<struct "anon.4" {!cir.ptr<!cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !ty_C, !cir.struct<union "anon.5" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E1_, !cir.struct<struct "B">} #cir.record.decl.ast>>, !cir.struct<struct "anon.4">} #cir.record.decl.ast>} #cir.record.decl.ast>>} #cir.record.decl.ast>
103-
// CHECK5: !cir.struct<union "anon.5" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E1_, !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !ty_C, !cir.struct<union "anon.5">} #cir.record.decl.ast>} #cir.record.decl.ast>>, !ty_anon2E4_} #cir.record.decl.ast>
104-
// CHECK5: !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !ty_C, !ty_anon2E5_} #cir.record.decl.ast>
105-
// CHECK5: !cir.struct<struct "A" {!ty_anon2E1_, !ty_B} #cir.record.decl.ast>
99+
// CHECK5: !cir.struct<struct "anon.0" {!cir.ptr<!cir.struct<struct "A" {!cir.struct<struct "anon.0">, !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !cir.struct<struct "C" {!cir.ptr<!cir.struct<struct "A">>, !cir.ptr<!cir.struct<struct "B">>, !cir.ptr<!cir.struct<struct "C">>} #cir.record.decl.ast>, !cir.struct<union "anon.1" {!cir.ptr<!cir.struct<struct "A">>, !cir.struct<struct "anon.2" {!cir.ptr<!cir.struct<struct "B">>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>>} #cir.record.decl.ast>
100+
// CHECK5: !cir.struct<struct "C" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E0_, !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !cir.struct<struct "C">, !cir.struct<union "anon.1" {!cir.ptr<!cir.struct<struct "A">>, !cir.struct<struct "anon.2" {!cir.ptr<!cir.struct<struct "B">>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>>, !cir.ptr<!cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !cir.struct<struct "C">, !cir.struct<union "anon.1" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E0_, !cir.struct<struct "B">} #cir.record.decl.ast>>, !cir.struct<struct "anon.2" {!cir.ptr<!cir.struct<struct "B">>} #cir.record.decl.ast>} #cir.record.decl.ast>} #cir.record.decl.ast>>, !cir.ptr<!cir.struct<struct "C">>} #cir.record.decl.ast>
101+
// CHECK5: !cir.struct<struct "anon.2" {!cir.ptr<!cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !ty_C, !cir.struct<union "anon.1" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E0_, !cir.struct<struct "B">} #cir.record.decl.ast>>, !cir.struct<struct "anon.2">} #cir.record.decl.ast>} #cir.record.decl.ast>>} #cir.record.decl.ast>
102+
// CHECK5: !cir.struct<union "anon.1" {!cir.ptr<!cir.struct<struct "A" {!ty_anon2E0_, !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !ty_C, !cir.struct<union "anon.1">} #cir.record.decl.ast>} #cir.record.decl.ast>>, !ty_anon2E2_} #cir.record.decl.ast>
103+
// CHECK5: !cir.struct<struct "B" {!cir.ptr<!cir.struct<struct "B">>, !ty_C, !ty_anon2E1_} #cir.record.decl.ast>
104+
// CHECK5: !cir.struct<struct "A" {!ty_anon2E0_, !ty_B} #cir.record.decl.ast>
106105
struct A {
107106
struct {
108107
struct A *a1;

clang/test/CIR/CodeGen/globals.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,25 @@ const int i = 12;
5757
int i2 = i;
5858
struct { int i; } i3 = {i};
5959
// CHECK: cir.global external @i2 = #cir.int<12> : !s32i
60-
// CHECK: cir.global external @i3 = #cir.const_struct<{#cir.int<12> : !s32i}> : !ty_anon2E7_
60+
// CHECK: cir.global external @i3 = #cir.const_struct<{#cir.int<12> : !s32i}> : !ty_anon2E3_
6161

6262
int a[10][10][10];
6363
int *a2 = &a[3][0][8];
6464
struct { int *p; } a3 = {&a[3][0][8]};
6565
// CHECK: cir.global external @a2 = #cir.global_view<@a, [3 : i32, 0 : i32, 8 : i32]> : !cir.ptr<!s32i>
66-
// CHECK: cir.global external @a3 = #cir.const_struct<{#cir.global_view<@a, [3 : i32, 0 : i32, 8 : i32]> : !cir.ptr<!s32i>}> : !ty_anon2E9_
66+
// CHECK: cir.global external @a3 = #cir.const_struct<{#cir.global_view<@a, [3 : i32, 0 : i32, 8 : i32]> : !cir.ptr<!s32i>}> : !ty_anon2E4_
6767

6868
int p[10];
6969
int *p1 = &p[0];
7070
struct { int *x; } p2 = {&p[0]};
7171
// CHECK: cir.global external @p1 = #cir.global_view<@p> : !cir.ptr<!s32i>
72-
// CHECK: cir.global external @p2 = #cir.const_struct<{#cir.global_view<@p> : !cir.ptr<!s32i>}> : !ty_anon2E11_
72+
// CHECK: cir.global external @p2 = #cir.const_struct<{#cir.global_view<@p> : !cir.ptr<!s32i>}> : !ty_anon2E5_
7373

7474
int q[10];
7575
int *q1 = q;
7676
struct { int *x; } q2 = {q};
7777
// CHECK: cir.global external @q1 = #cir.global_view<@q> : !cir.ptr<!s32i>
78-
// CHECK: cir.global external @q2 = #cir.const_struct<{#cir.global_view<@q> : !cir.ptr<!s32i>}> : !ty_anon2E13_
78+
// CHECK: cir.global external @q2 = #cir.const_struct<{#cir.global_view<@q> : !cir.ptr<!s32i>}> : !ty_anon2E6_
7979

8080
int foo() {
8181
extern int optind;

clang/test/CIR/CodeGen/lambda.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ void fn() {
66
a();
77
}
88

9-
// CHECK: !ty_anon2E2_ = !cir.struct<class "anon.2" {!u8i}>
9+
// CHECK: !ty_anon2E0_ = !cir.struct<class "anon.0" {!u8i}>
1010
// CHECK-DAG: module
1111

1212
// CHECK: cir.func lambda internal private @_ZZ2fnvENK3$_0clEv{{.*}}) extra
1313

1414
// CHECK: cir.func @_Z2fnv()
15-
// CHECK-NEXT: %0 = cir.alloca !ty_anon2E2_, !cir.ptr<!ty_anon2E2_>, ["a"]
15+
// CHECK-NEXT: %0 = cir.alloca !ty_anon2E0_, !cir.ptr<!ty_anon2E0_>, ["a"]
1616
// CHECK: cir.call @_ZZ2fnvENK3$_0clEv
1717

1818
void l0() {
@@ -23,15 +23,15 @@ void l0() {
2323

2424
// CHECK: cir.func lambda internal private @_ZZ2l0vENK3$_0clEv({{.*}}) extra
2525

26-
// CHECK: %0 = cir.alloca !cir.ptr<!ty_anon2E4_>, !cir.ptr<!cir.ptr<!ty_anon2E4_>>, ["this", init] {alignment = 8 : i64}
27-
// CHECK: cir.store %arg0, %0 : !cir.ptr<!ty_anon2E4_>, !cir.ptr<!cir.ptr<!ty_anon2E4_>>
28-
// CHECK: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_anon2E4_>>, !cir.ptr<!ty_anon2E4_>
29-
// CHECK: %2 = cir.get_member %1[0] {name = "i"} : !cir.ptr<!ty_anon2E4_> -> !cir.ptr<!cir.ptr<!s32i>>
26+
// CHECK: %0 = cir.alloca !cir.ptr<!ty_anon2E2_>, !cir.ptr<!cir.ptr<!ty_anon2E2_>>, ["this", init] {alignment = 8 : i64}
27+
// CHECK: cir.store %arg0, %0 : !cir.ptr<!ty_anon2E2_>, !cir.ptr<!cir.ptr<!ty_anon2E2_>>
28+
// CHECK: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_anon2E2_>>, !cir.ptr<!ty_anon2E2_>
29+
// CHECK: %2 = cir.get_member %1[0] {name = "i"} : !cir.ptr<!ty_anon2E2_> -> !cir.ptr<!cir.ptr<!s32i>>
3030
// CHECK: %3 = cir.load %2 : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>
3131
// CHECK: %4 = cir.load %3 : !cir.ptr<!s32i>, !s32i
3232
// CHECK: %5 = cir.const #cir.int<1> : !s32i
3333
// CHECK: %6 = cir.binop(add, %4, %5) nsw : !s32i
34-
// CHECK: %7 = cir.get_member %1[0] {name = "i"} : !cir.ptr<!ty_anon2E4_> -> !cir.ptr<!cir.ptr<!s32i>>
34+
// CHECK: %7 = cir.get_member %1[0] {name = "i"} : !cir.ptr<!ty_anon2E2_> -> !cir.ptr<!cir.ptr<!s32i>>
3535
// CHECK: %8 = cir.load %7 : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>
3636
// CHECK: cir.store %6, %8 : !s32i, !cir.ptr<!s32i>
3737

@@ -45,15 +45,15 @@ auto g() {
4545
};
4646
}
4747

48-
// CHECK: cir.func @_Z1gv() -> !ty_anon2E6_
49-
// CHECK: %0 = cir.alloca !ty_anon2E6_, !cir.ptr<!ty_anon2E6_>, ["__retval"] {alignment = 8 : i64}
48+
// CHECK: cir.func @_Z1gv() -> !ty_anon2E3_
49+
// CHECK: %0 = cir.alloca !ty_anon2E3_, !cir.ptr<!ty_anon2E3_>, ["__retval"] {alignment = 8 : i64}
5050
// CHECK: %1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64}
5151
// CHECK: %2 = cir.const #cir.int<12> : !s32i
5252
// CHECK: cir.store %2, %1 : !s32i, !cir.ptr<!s32i>
53-
// CHECK: %3 = cir.get_member %0[0] {name = "i"} : !cir.ptr<!ty_anon2E6_> -> !cir.ptr<!cir.ptr<!s32i>>
53+
// CHECK: %3 = cir.get_member %0[0] {name = "i"} : !cir.ptr<!ty_anon2E3_> -> !cir.ptr<!cir.ptr<!s32i>>
5454
// CHECK: cir.store %1, %3 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
55-
// CHECK: %4 = cir.load %0 : !cir.ptr<!ty_anon2E6_>, !ty_anon2E6_
56-
// CHECK: cir.return %4 : !ty_anon2E6_
55+
// CHECK: %4 = cir.load %0 : !cir.ptr<!ty_anon2E3_>, !ty_anon2E3_
56+
// CHECK: cir.return %4 : !ty_anon2E3_
5757

5858
auto g2() {
5959
int i = 12;
@@ -65,15 +65,15 @@ auto g2() {
6565
}
6666

6767
// Should be same as above because of NRVO
68-
// CHECK: cir.func @_Z2g2v() -> !ty_anon2E8_
69-
// CHECK-NEXT: %0 = cir.alloca !ty_anon2E8_, !cir.ptr<!ty_anon2E8_>, ["__retval", init] {alignment = 8 : i64}
68+
// CHECK: cir.func @_Z2g2v() -> !ty_anon2E4_
69+
// CHECK-NEXT: %0 = cir.alloca !ty_anon2E4_, !cir.ptr<!ty_anon2E4_>, ["__retval", init] {alignment = 8 : i64}
7070
// CHECK-NEXT: %1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64}
7171
// CHECK-NEXT: %2 = cir.const #cir.int<12> : !s32i
7272
// CHECK-NEXT: cir.store %2, %1 : !s32i, !cir.ptr<!s32i>
73-
// CHECK-NEXT: %3 = cir.get_member %0[0] {name = "i"} : !cir.ptr<!ty_anon2E8_> -> !cir.ptr<!cir.ptr<!s32i>>
73+
// CHECK-NEXT: %3 = cir.get_member %0[0] {name = "i"} : !cir.ptr<!ty_anon2E4_> -> !cir.ptr<!cir.ptr<!s32i>>
7474
// CHECK-NEXT: cir.store %1, %3 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
75-
// CHECK-NEXT: %4 = cir.load %0 : !cir.ptr<!ty_anon2E8_>, !ty_anon2E8_
76-
// CHECK-NEXT: cir.return %4 : !ty_anon2E8_
75+
// CHECK-NEXT: %4 = cir.load %0 : !cir.ptr<!ty_anon2E4_>, !ty_anon2E4_
76+
// CHECK-NEXT: cir.return %4 : !ty_anon2E4_
7777

7878
int f() {
7979
return g2()();
@@ -82,10 +82,10 @@ int f() {
8282
// CHECK: cir.func @_Z1fv() -> !s32i
8383
// CHECK-NEXT: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64}
8484
// CHECK-NEXT: cir.scope {
85-
// CHECK-NEXT: %2 = cir.alloca !ty_anon2E8_, !cir.ptr<!ty_anon2E8_>, ["ref.tmp0"] {alignment = 8 : i64}
86-
// CHECK-NEXT: %3 = cir.call @_Z2g2v() : () -> !ty_anon2E8_
87-
// CHECK-NEXT: cir.store %3, %2 : !ty_anon2E8_, !cir.ptr<!ty_anon2E8_>
88-
// CHECK-NEXT: %4 = cir.call @_ZZ2g2vENK3$_0clEv(%2) : (!cir.ptr<!ty_anon2E8_>) -> !s32i
85+
// CHECK-NEXT: %2 = cir.alloca !ty_anon2E4_, !cir.ptr<!ty_anon2E4_>, ["ref.tmp0"] {alignment = 8 : i64}
86+
// CHECK-NEXT: %3 = cir.call @_Z2g2v() : () -> !ty_anon2E4_
87+
// CHECK-NEXT: cir.store %3, %2 : !ty_anon2E4_, !cir.ptr<!ty_anon2E4_>
88+
// CHECK-NEXT: %4 = cir.call @_ZZ2g2vENK3$_0clEv(%2) : (!cir.ptr<!ty_anon2E4_>) -> !s32i
8989
// CHECK-NEXT: cir.store %4, %0 : !s32i, !cir.ptr<!s32i>
9090
// CHECK-NEXT: }
9191
// CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!s32i>, !s32i
@@ -114,8 +114,8 @@ int g3() {
114114

115115
// 1. Use `operator int (*)(int const&)()` to retrieve the fnptr to `__invoke()`.
116116
// CHECK: %3 = cir.scope {
117-
// CHECK: %7 = cir.alloca !ty_anon2E11_, !cir.ptr<!ty_anon2E11_>, ["ref.tmp0"] {alignment = 1 : i64}
118-
// CHECK: %8 = cir.call @_ZZ2g3vENK3$_0cvPFiRKiEEv(%7) : (!cir.ptr<!ty_anon2E11_>) -> !cir.ptr<!cir.func<!s32i (!cir.ptr<!s32i>)>>
117+
// CHECK: %7 = cir.alloca !ty_anon2E5_, !cir.ptr<!ty_anon2E5_>, ["ref.tmp0"] {alignment = 1 : i64}
118+
// CHECK: %8 = cir.call @_ZZ2g3vENK3$_0cvPFiRKiEEv(%7) : (!cir.ptr<!ty_anon2E5_>) -> !cir.ptr<!cir.func<!s32i (!cir.ptr<!s32i>)>>
119119
// CHECK: %9 = cir.unary(plus, %8) : !cir.ptr<!cir.func<!s32i (!cir.ptr<!s32i>)>>, !cir.ptr<!cir.func<!s32i (!cir.ptr<!s32i>)>>
120120
// CHECK: cir.yield %9 : !cir.ptr<!cir.func<!s32i (!cir.ptr<!s32i>)>>
121121
// CHECK: }

0 commit comments

Comments
 (0)