[Patch] visit order of InitListExpr

Hi all,

I checked “VisitInitListExpr(InitListExpr *ILE)” function and found strange type checking order. Current type checking order is as following.

829 llvm::Constant *VisitInitListExpr(InitListExpr *ILE) {
830 if (ILE->getType()->isArrayType())
831 return EmitArrayInitialization(ILE);
832
833 if (ILE->getType()->isRecordType())
834 return EmitUnionInitialization(ILE);
835
836 if (ILE->getType()->isUnionType())
837 return EmitStructInitialization(ILE);

If RecodeType is checked eariler, UnionType will not be check because UnionType is checked from Decl’s field and Type is also RecordType. Although EmitStructInitialization() and EmitUnionInitialization() call the same ConstStructBuilder::BuildStruct() function, It looks like wrong. I think UnionType should be checked eariler than RecordType.

What do you think about this?

I attach a simple patch to fix it.

Regards,
Jin-Gu Kang

clang.patch (599 Bytes)