Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][Lowering] Fix lowering for multi dimensional array #851

Merged
merged 17 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clang/lib/CIR/Lowering/LoweringHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ mlir::Type getNestedTypeAndElemQuantity(mlir::Type Ty, unsigned &elemQuantity) {
template <typename AttrTy, typename StorageTy>
void convertToDenseElementsAttrImpl(mlir::cir::ConstArrayAttr attr,
llvm::SmallVectorImpl<StorageTy> &values) {
if (auto stringAttr = mlir::dyn_cast<mlir::StringAttr>(attr.getElts())) {
if (auto arrayType = mlir::dyn_cast<mlir::cir::ArrayType>(attr.getType())) {
for (auto element : stringAttr) {
auto intAttr = mlir::cir::IntAttr::get(arrayType.getEltType(), element);
values.push_back(mlir::dyn_cast<AttrTy>(intAttr).getValue());
}
return;
}
}

auto arrayAttr = mlir::cast<mlir::ArrayAttr>(attr.getElts());
for (auto eltAttr : arrayAttr) {
if (auto valueAttr = mlir::dyn_cast<AttrTy>(eltAttr)) {
Expand Down
11 changes: 11 additions & 0 deletions clang/test/CIR/Lowering/array-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ void zeroInit() {
int a[3] = {0, 0, 0};
}

// LLVM{LITERAL}: %1 = alloca [4 x [1 x i8]], i64 1, align 1, !dbg !9
// LLVM{LITERAL}: store [4 x [1 x i8]] [[1 x i8] c"a", [1 x i8] c"b", [1 x i8] c"c", [1 x i8] c"d"], ptr %1, align 1, !dbg !9
bcardosolopes marked this conversation as resolved.
Show resolved Hide resolved
void charInit1() {
char arr[4][1] = {"a", "b", "c", "d"};
}

// LLVM{LITERAL}: %1 = alloca [4 x [2 x i8]], i64 1, align 1, !dbg !12
// LLVM{LITERAL}: store [4 x [2 x i8]] [[2 x i8] c"ab", [2 x i8] c"cd", [2 x i8] c"ef", [2 x i8] c"gh"], ptr %1, align 1, !dbg !12
void charInit2() {
char arr[4][2] = {"ab", "cd", "ef", "gh"};
}
Loading