Skip to content

Commit

Permalink
remove the too restrictive assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancern committed Jan 8, 2024
1 parent 0766623 commit 5edd5ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,16 @@ void CIRGenModule::replaceGlobal(mlir::cir::GlobalOp Old,
auto OldSymUses = Old.getSymbolUses(theModule.getOperation());
if (OldSymUses.has_value()) {
for (auto Use : *OldSymUses) {
auto UseOp = dyn_cast<mlir::cir::GetGlobalOp>(Use.getUser());
assert(UseOp && "GlobalOp symbol user is not a GetGlobalOp");

auto UseOpResultValue = UseOp.getAddr();
UseOpResultValue.setType(
mlir::cir::PointerType::get(builder.getContext(), NewTy));
auto *UserOp = Use.getUser();
assert((isa<mlir::cir::GetGlobalOp>(UserOp) ||
isa<mlir::cir::GlobalOp>(UserOp)) &&
"GlobalOp symbol user is neither a GetGlobalOp nor a GlobalOp");

if (auto GGO = dyn_cast<mlir::cir::GetGlobalOp>(Use.getUser())) {
auto UseOpResultValue = GGO.getAddr();
UseOpResultValue.setType(
mlir::cir::PointerType::get(builder.getContext(), NewTy));
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion clang/test/CIR/CodeGen/array-unknown-bound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
extern int table[];
// 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>

int *table_ptr = table;
// CHECK: cir.global external @table_ptr = #cir.global_view<@table> : !cir.ptr<!s32i>

int test() { return table[1]; }
// CHECK: cir.func @_Z4testv() -> !s32i extra( {inline = #cir.inline<no>, optnone = #cir.optnone} ) {
// CHECK-NEXT: %0 = cir.alloca !s32i, cir.ptr <!s32i>, ["__retval"] {alignment = 4 : i64}
// CHECK-NEXT: %1 = cir.get_global @table : cir.ptr <!cir.array<!s32i x 3>>

int table[3] {1, 2, 3};
int table[3] {1, 2, 3};

0 comments on commit 5edd5ce

Please sign in to comment.