You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CIR][Lowering] Fix lowering for multi dimensional array (llvm#851)
This PR fixes the lowering for multi dimensional arrays.
Consider the following code snippet `test.c`:
```
void foo() {
char arr[4][1] = {"a", "b", "c", "d"};
}
```
When ran with `bin/clang test.c -Xclang -fclangir -Xclang -emit-llvm -S
-o -`, It produces the following error:
```
~/clangir/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = mlir::ArrayAttr; From = mlir::Attribute]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
```
The bug can be traced back to `LoweringHelpers.cpp`. It considers the
values in the array as integer types, and this causes an error in this
case.
This PR updates `convertToDenseElementsAttrImpl` when the array contains
string attributes. I have also added one more similar test. Note that in
the tests I used a **literal match** to avoid matching as regex, so
`!dbg` is useful.
// LLVM: charInit1.ar = internal global [4 x [4 x i8]] {{.*}}4 x i8] c"aa\00\00", [4 x i8] c"aa\00\00", [4 x i8] c"aa\00\00", [4 x i8] c"aa\00\00"], align 16
5
+
charcharInit1() {
6
+
staticcharar[][4] = {"aa", "aa", "aa", "aa"};
7
+
returnar[0][0];
8
+
}
9
+
4
10
// LLVM: define dso_local void @zeroInit
5
11
// LLVM: [[RES:%.*]] = alloca [3 x i32], i64 1
6
12
// LLVM: store [3 x i32] zeroinitializer, ptr [[RES]]
7
13
voidzeroInit() {
8
14
inta[3] = {0, 0, 0};
9
15
}
10
16
17
+
// LLVM: %1 = alloca [4 x [1 x i8]], i64 1, align 1
18
+
// LLVM: 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
19
+
voidcharInit2() {
20
+
chararr[4][1] = {"a", "b", "c", "d"};
21
+
}
22
+
23
+
// LLVM: %1 = alloca [4 x [2 x i8]], i64 1, align 1
24
+
// LLVM: 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
0 commit comments