Skip to content

Commit 5edd5ce

Browse files
committed
remove the too restrictive assertion
1 parent 0766623 commit 5edd5ce

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,16 @@ void CIRGenModule::replaceGlobal(mlir::cir::GlobalOp Old,
517517
auto OldSymUses = Old.getSymbolUses(theModule.getOperation());
518518
if (OldSymUses.has_value()) {
519519
for (auto Use : *OldSymUses) {
520-
auto UseOp = dyn_cast<mlir::cir::GetGlobalOp>(Use.getUser());
521-
assert(UseOp && "GlobalOp symbol user is not a GetGlobalOp");
522-
523-
auto UseOpResultValue = UseOp.getAddr();
524-
UseOpResultValue.setType(
525-
mlir::cir::PointerType::get(builder.getContext(), NewTy));
520+
auto *UserOp = Use.getUser();
521+
assert((isa<mlir::cir::GetGlobalOp>(UserOp) ||
522+
isa<mlir::cir::GlobalOp>(UserOp)) &&
523+
"GlobalOp symbol user is neither a GetGlobalOp nor a GlobalOp");
524+
525+
if (auto GGO = dyn_cast<mlir::cir::GetGlobalOp>(Use.getUser())) {
526+
auto UseOpResultValue = GGO.getAddr();
527+
UseOpResultValue.setType(
528+
mlir::cir::PointerType::get(builder.getContext(), NewTy));
529+
}
526530
}
527531
}
528532
}

clang/test/CIR/CodeGen/array-unknown-bound.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
extern int table[];
44
// CHECK: cir.global external @table = #cir.const_array<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i]> : !cir.array<!s32i x 3>
55

6+
int *table_ptr = table;
7+
// CHECK: cir.global external @table_ptr = #cir.global_view<@table> : !cir.ptr<!s32i>
8+
69
int test() { return table[1]; }
710
// CHECK: cir.func @_Z4testv() -> !s32i extra( {inline = #cir.inline<no>, optnone = #cir.optnone} ) {
811
// CHECK-NEXT: %0 = cir.alloca !s32i, cir.ptr <!s32i>, ["__retval"] {alignment = 4 : i64}
912
// CHECK-NEXT: %1 = cir.get_global @table : cir.ptr <!cir.array<!s32i x 3>>
1013

11-
int table[3] {1, 2, 3};
14+
int table[3] {1, 2, 3};

0 commit comments

Comments
 (0)