Skip to content

Commit

Permalink
[CIR][Lowering] Fix static array lowering
Browse files Browse the repository at this point in the history
  • Loading branch information
bruteforceboy committed Sep 13, 2024
1 parent bde154c commit 3e76d6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/CIR/Lowering/LoweringHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void convertToDenseElementsAttrImpl(mlir::cir::ConstArrayAttr attr,

auto nestTy = localArrayTy.getEltType();
if (!mlir::isa<mlir::cir::ArrayType>(nestTy))
values.insert(values.end(), localArrayTy.getSize() - numTrailingZeros,
values.insert(values.end(), numTrailingZeros,
getZeroInitFromType<StorageTy>(nestTy));
}
}
Expand Down
8 changes: 8 additions & 0 deletions clang/test/CIR/Lowering/static-array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM

int test(int x) {
static int arr[10] = {0, 1, 0, 0};
return arr[x];
}
// LLVM: internal global [10 x i32] [i32 0, i32 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0]

0 comments on commit 3e76d6c

Please sign in to comment.