Skip to content

Commit aebe2e9

Browse files
ChuanqiXu9lanza
authored andcommitted
[CIR] [Lowering] Fix handling of multiple array for ZeroAttr (#970)
This is the following up fix for the previous fix #961 See the attached new test for the reproducer. Sorry for the initial overlook.
1 parent 634f656 commit aebe2e9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/CIR/Lowering/LoweringHelpers.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ void convertToDenseElementsAttrImpl(
8585
continue;
8686
}
8787

88-
if (mlir::isa<mlir::cir::ZeroAttr>(eltAttr))
88+
if (mlir::isa<mlir::cir::ZeroAttr>(eltAttr)) {
89+
currentIndex += elementsSizeInCurrentDim;
8990
continue;
91+
}
9092

9193
llvm_unreachable("unknown element in ConstArrayAttr");
9294
}

clang/test/CIR/Lowering/multi-array.c

+22
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,25 @@ unsigned char table3[15][16] =
3434
};
3535

3636
// LLVM: @table3 = {{.*}}[15 x [16 x i8]] {{.*}}[16 x i8] c"\01\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [16 x i8] c"\01\02\02\00\00\00\00\00\00\00\00\00\00\00\00\00", [16 x i8] c"\02\02\02\02\00\00\00\00\00\00\00\00\00\00\00\00", [16 x i8] c"\02\02\02\03\03\00\00\00\00\00\00\00\00\00\00\00", [16 x i8] c"\02\02\03\03\03\03\00\00\00\00\00\00\00\00\00\00", [16 x i8] c"\02\03\03\03\03\03\03\00\00\00\00\00\00\00\00\00", [16 x i8] c"\03\03\03\03\03\03\03\04\05\06\07\08\09\0A\0B\00", [16 x i8] zeroinitializer
37+
38+
39+
unsigned char table4[][20] =
40+
{
41+
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
42+
{ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 0, 0, 0 }
43+
};
44+
// LLVM: @table4 = {{.*}}[2 x [20 x i8]] {{.*}}[20 x i8] zeroinitializer, [20 x i8] c"\00\00\00\00\00\00\00\01\01\01\01\00\02\02\02\02\00\00\00\00"]
45+
46+
unsigned char table5[][20] =
47+
{
48+
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
49+
{ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 0, 0, 0 }
50+
};
51+
// LLVM: @table5 = {{.*}}[2 x [20 x i8]] {{.*}}[20 x i8] c"\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00", [20 x i8] c"\00\00\00\00\00\00\00\01\01\01\01\00\02\02\02\02\00\00\00\00"]
52+
53+
unsigned char table6[][20] =
54+
{
55+
{ 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
56+
{ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 0, 0, 0 }
57+
};
58+
// LLVM: @table6 = {{.*}}[2 x [20 x i8]] {{.*}}[20 x i8] c"\01\00\00\00\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00", [20 x i8] c"\00\00\00\00\00\00\00\01\01\01\01\00\02\02\02\02\00\00\00\00"]

0 commit comments

Comments
 (0)