@@ -1106,48 +1106,6 @@ class ConstExprEmitter
1106
1106
}
1107
1107
1108
1108
auto desiredType = CGM.convertType (T);
1109
- // FIXME(cir): A hack to handle the emission of arrays of unions directly.
1110
- // See clang/test/CIR/CodeGen/union-array.c and
1111
- // clang/test/CIR/Lowering/nested-union-array.c for example. The root
1112
- // cause of these problems is CIR handles union differently than LLVM IR.
1113
- // So we can't fix the problem fundamentally by mocking LLVM's handling for
1114
- // unions. In LLVM, the union is basically a struct with the largest member
1115
- // of the union and consumers cast the union arbitrarily according to their
1116
- // needs. But in CIR, we tried to express union semantics properly. This is
1117
- // a fundamental difference.
1118
- //
1119
- // Concretely, for the problem here, if we're constructing the initializer
1120
- // for the array of unions, we can't even assume the type of the elements in
1121
- // the initializer are the same! It is odd that we can have an array with
1122
- // different element types. Here we just pretend it is fine by checking if
1123
- // we're constructing an array for an array of unions. If we didn't do so,
1124
- // we may meet problems during lowering to LLVM. To solve the problem, we
1125
- // may need to introduce 2 type systems for CIR: one for the CIR itself and
1126
- // one for lowering. e.g., we can compare the type of CIR during CIRGen,
1127
- // analysis and transformations without worrying the concerns here. And
1128
- // lower to LLVM IR (or anyother dialects) with the proper type.
1129
- //
1130
- // (Although the idea to make CIR's type system self contained and generate
1131
- // LLVM's
1132
- // types in later passes look fine, it has engineering level concern that
1133
- // it will make the skeleton of CIRGen to be diverged from the traditional
1134
- // CodeGen.)
1135
- //
1136
- // Besides union, there are other differences between CIR and LLVM's type
1137
- // system. e.g., LLVM's pointer types are opaque while CIR has concrete
1138
- // pointer types.
1139
- bool isDesiredArrayOfUnionDirectly = [&]() {
1140
- auto desiredArrayType = dyn_cast<cir::ArrayType>(desiredType);
1141
- if (!desiredArrayType)
1142
- return false ;
1143
-
1144
- auto elementRecordType =
1145
- dyn_cast<cir::RecordType>(desiredArrayType.getElementType ());
1146
- if (!elementRecordType)
1147
- return false ;
1148
-
1149
- return elementRecordType.isUnion ();
1150
- }();
1151
1109
1152
1110
// Emit initializer elements as MLIR attributes and check for common type.
1153
1111
mlir::Type CommonElementType;
@@ -1158,8 +1116,7 @@ class ConstExprEmitter
1158
1116
return {};
1159
1117
if (i == 0 )
1160
1118
CommonElementType = C.getType ();
1161
- else if (isDesiredArrayOfUnionDirectly &&
1162
- C.getType () != CommonElementType)
1119
+ else if (C.getType () != CommonElementType)
1163
1120
CommonElementType = nullptr ;
1164
1121
Elts.push_back (std::move (C));
1165
1122
}
0 commit comments