diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -76,6 +76,10 @@ - Now allow the `restrict` and `_Atomic` qualifiers to be used in conjunction with `__auto_type` to match the behavior in GCC. This fixes `Issue 53652 `_. +- The builtin function __builtin_dump_struct would crash clang when the target + struct have bitfield, now it fixed. The zero-width bitfield will be ignored and + unnamed bitfield will dump with an empty name. + This fixes `Issue 54462 `_. Improvements to Clang's diagnostics diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2044,7 +2044,7 @@ } static llvm::Value *dumpRecord(CodeGenFunction &CGF, QualType RType, - Value *&RecordPtr, CharUnits Align, + LValue RecordLV, CharUnits Align, llvm::FunctionCallee Func, int Lvl) { ASTContext &Context = CGF.getContext(); RecordDecl *RD = RType->castAs()->getDecl()->getDefinition(); @@ -2077,13 +2077,9 @@ } for (const auto *FD : RD->fields()) { - Value *FieldPtr = RecordPtr; - if (RD->isUnion()) - FieldPtr = CGF.Builder.CreatePointerCast( - FieldPtr, CGF.ConvertType(Context.getPointerType(FD->getType()))); - else - FieldPtr = CGF.Builder.CreateStructGEP(CGF.ConvertType(RType), FieldPtr, - FD->getFieldIndex()); + if (FD->isZeroSize(CGF.getContext())) + continue; + LValue FieldLV = CGF.EmitLValueForField(RecordLV, FD); GString = CGF.Builder.CreateGlobalStringPtr( llvm::Twine(Pad) @@ -2100,7 +2096,7 @@ // We check whether we are in a recursive type if (CanonicalType->isRecordType()) { - TmpRes = dumpRecord(CGF, CanonicalType, FieldPtr, Align, Func, Lvl + 1); + TmpRes = dumpRecord(CGF, CanonicalType, FieldLV, Align, Func, Lvl + 1); Res = CGF.Builder.CreateAdd(TmpRes, Res); continue; } @@ -2110,14 +2106,13 @@ ? Types[Context.VoidPtrTy] : Types[CanonicalType]; - Address FieldAddress = - Address(FieldPtr, CGF.ConvertTypeForMem(FD->getType()), Align); - FieldPtr = CGF.Builder.CreateLoad(FieldAddress); + RValue RV = FD->isBitField() + ? CGF.EmitLoadOfBitfieldLValue(FieldLV, FD->getLocation()) + : CGF.EmitLoadOfLValue(FieldLV, FD->getLocation()); - // FIXME Need to handle bitfield here GString = CGF.Builder.CreateGlobalStringPtr( Format.concat(llvm::Twine('\n')).str()); - TmpRes = CGF.Builder.CreateCall(Func, {GString, FieldPtr}); + TmpRes = CGF.Builder.CreateCall(Func, {GString, RV.getScalarVal()}); Res = CGF.Builder.CreateAdd(Res, TmpRes); } @@ -2664,7 +2659,8 @@ QualType Arg0Type = Arg0->getType()->getPointeeType(); Value *RecordPtr = EmitScalarExpr(Arg0); - Value *Res = dumpRecord(*this, Arg0Type, RecordPtr, Arg0Align, + LValue RecordLV = MakeAddrLValue(RecordPtr, Arg0Type, Arg0Align); + Value *Res = dumpRecord(*this, Arg0Type, RecordLV, Arg0Align, {LLVMFuncType, Func}, 0); return RValue::get(Res); } diff --git a/clang/test/CodeGen/dump-struct-builtin.c b/clang/test/CodeGen/dump-struct-builtin.c --- a/clang/test/CodeGen/dump-struct-builtin.c +++ b/clang/test/CodeGen/dump-struct-builtin.c @@ -126,7 +126,7 @@ .a = 12, }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U1]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[FIELD_U1]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U1]], i32 0, i32 0), i16 [[LOAD1]]) @@ -144,7 +144,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U2]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* [[FIELD_U2]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U2]], i32 0, i32 0), i16 [[LOAD1]]) @@ -162,7 +162,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U3]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* [[FIELD_U3]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U3]], i32 0, i32 0), i32 [[LOAD1]]) @@ -180,7 +180,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U4]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* [[FIELD_U4]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U4]], i32 0, i32 0), i32 [[LOAD1]]) @@ -198,7 +198,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U5]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* [[FIELD_U5]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U5]], i32 0, i32 0), i64 [[LOAD1]]) @@ -216,7 +216,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U6]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* [[FIELD_U6]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U6]], i32 0, i32 0), i64 [[LOAD1]]) @@ -234,7 +234,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U7]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[FIELD_U7]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* [[FORMAT_U7]], i32 0, i32 0), i64 [[LOAD1]]) @@ -252,7 +252,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U8]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U8A, %struct.U8A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U8A, %struct.U8A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* [[FIELD_U8]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* [[FORMAT_U8]], i32 0, i32 0), i64 [[LOAD1]]) @@ -270,7 +270,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U9]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U9A, %struct.U9A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U9A, %struct.U9A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* [[FIELD_U9]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i8, i8* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U9]], i32 0, i32 0), i8 [[LOAD1]]) @@ -288,7 +288,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U10]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U10A, %struct.U10A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U10A, %struct.U10A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* [[FIELD_U10]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i8*, i8** [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U10]], i32 0, i32 0), i8* [[LOAD1]]) @@ -306,7 +306,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U11]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U11A, %struct.U11A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U11A, %struct.U11A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* [[FIELD_U11]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i8*, i8** [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U11]], i32 0, i32 0), i8* [[LOAD1]]) @@ -324,7 +324,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U12]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U12A, %struct.U12A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U12A, %struct.U12A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* [[FIELD_U12]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i8*, i8** [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U12]], i32 0, i32 0), i8* [[LOAD1]]) @@ -343,7 +343,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U13]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U13A, %struct.U13A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U13A, %struct.U13A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* [[FIELD_U13]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i8*, i8** [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U13]], i32 0, i32 0), i8* [[LOAD1]]) @@ -361,7 +361,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U14]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U14A, %struct.U14A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U14A, %struct.U14A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* [[FIELD_U14]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load double, double* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U14]], i32 0, i32 0), double [[LOAD1]]) @@ -379,7 +379,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U15]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U15A, %struct.U15A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U15A, %struct.U15A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* [[FIELD_U15]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load [3 x i32], [3 x i32]* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U15]], i32 0, i32 0), [3 x i32] [[LOAD1]]) @@ -397,7 +397,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U16]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U16A, %struct.U16A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U16A, %struct.U16A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* [[FIELD_U16]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i8, i8* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* [[FORMAT_U16]], i32 0, i32 0), i8 [[LOAD1]]) @@ -415,7 +415,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U17]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U17A, %struct.U17A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U17A, %struct.U17A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* [[FIELD_U17]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load i8, i8* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* [[FORMAT_U17]], i32 0, i32 0), i8 [[LOAD1]]) @@ -433,7 +433,7 @@ }; // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[STRUCT_STR_U18]], i32 0, i32 0)) - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U18A, %struct.U18A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U18A, %struct.U18A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* [[FIELD_U18]], i32 0, i32 0)) // CHECK: [[LOAD1:%[0-9]+]] = load x86_fp80, x86_fp80* [[RES1]], // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U18]], i32 0, i32 0), x86_fp80 [[LOAD1]]) @@ -453,11 +453,11 @@ }; // CHECK: call i32 (i8*, ...) @printf( - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.T1A, %struct.T1A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[a-z0-9]+]] = getelementptr inbounds %struct.T1A, %struct.T1A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf( // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, i32 [[LOAD1]]) - // CHECK: [[RES2:%[0-9]+]] = getelementptr inbounds %struct.T1A, %struct.T1A* %a, i32 0, i32 1 + // CHECK: [[RES2:%[a-z0-9]+]] = getelementptr inbounds %struct.T1A, %struct.T1A* %a, i32 0, i32 1 // CHECK: call i32 (i8*, ...) @printf( // CHECK: [[LOAD2:%[0-9]+]] = load i8*, i8** [[RES2]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, i8* [[LOAD2]]) @@ -483,13 +483,13 @@ }; // CHECK: call i32 (i8*, ...) @printf( - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.T2B, %struct.T2B* %b, i32 0, i32 0 + // CHECK: [[RES1:%[a-z0-9]+]] = getelementptr inbounds %struct.T2B, %struct.T2B* %b, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf( // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, i32 [[LOAD1]]) - // CHECK: [[NESTED_STRUCT:%[0-9]+]] = getelementptr inbounds %struct.T2B, %struct.T2B* %b, i32 0, i32 1 + // CHECK: [[NESTED_STRUCT:%[a-z0-9]+]] = getelementptr inbounds %struct.T2B, %struct.T2B* %b, i32 0, i32 1 // CHECK: call i32 (i8*, ...) @printf( - // CHECK: [[RES2:%[0-9]+]] = getelementptr inbounds %struct.T2A, %struct.T2A* [[NESTED_STRUCT]], i32 0, i32 0 + // CHECK: [[RES2:%[a-z0-9]+]] = getelementptr inbounds %struct.T2A, %struct.T2A* [[NESTED_STRUCT]], i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf( // CHECK: [[LOAD2:%[0-9]+]] = load i32, i32* [[RES2]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, i32 [[LOAD2]]) @@ -510,12 +510,12 @@ }; // CHECK: call i32 (i8*, ...) @printf( - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.T3A, %struct.T3A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[a-z0-9]+]] = getelementptr inbounds %struct.T3A, %struct.T3A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf( - // CHECK: [[BC1:%[0-9]+]] = bitcast %union.anon* [[RES1]] to i32* + // CHECK: [[BC1:%[a-z0-9]+]] = bitcast %union.anon* [[RES1]] to i32* // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[BC1]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, i32 [[LOAD1]]) - // CHECK: [[BC2:%[0-9]+]] = bitcast %union.anon* [[RES1]] to [4 x i8]* + // CHECK: [[BC2:%[a-z0-9]+]] = bitcast %union.anon* [[RES1]] to [4 x i8]* // CHECK: [[LOAD2:%[0-9]+]] = load [4 x i8], [4 x i8]* [[BC2]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, [4 x i8] [[LOAD2]]) // CHECK: call i32 (i8*, ...) @printf( @@ -539,17 +539,150 @@ }; // CHECK: call i32 (i8*, ...) @printf( - // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.T4A, %struct.T4A* %a, i32 0, i32 0 + // CHECK: [[RES1:%[a-z0-9]+]] = getelementptr inbounds %struct.T4A, %struct.T4A* %a, i32 0, i32 0 // CHECK: call i32 (i8*, ...) @printf( - // CHECK: [[BC1:%[0-9]+]] = bitcast %union.anon.0* [[RES1]] to %struct.anon* - // CHECK: [[RES2:%[0-9]+]] = getelementptr inbounds %struct.anon, %struct.anon* [[BC1]], i32 0, i32 0 + // CHECK: [[BC1:%[a-z0-9]+]] = bitcast %union.anon.0* [[RES1]] to %struct.anon* + // CHECK: [[RES2:%[a-z0-9]+]] = getelementptr inbounds %struct.anon, %struct.anon* [[BC1]], i32 0, i32 0 // CHECK: [[LOAD1:%[0-9]+]] = load i8*, i8** [[RES2]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, i8* [[LOAD1]]) - // CHECK: [[BC2:%[0-9]+]] = bitcast %union.anon.0* [[RES1]] to %struct.anon.1* - // CHECK: [[RES3:%[0-9]+]] = getelementptr inbounds %struct.anon.1, %struct.anon.1* [[BC2]], i32 0, i32 0 + // CHECK: [[BC2:%[a-z0-9]+]] = bitcast %union.anon.0* [[RES1]] to %struct.anon.1* + // CHECK: [[RES3:%[a-z0-9]+]] = getelementptr inbounds %struct.anon.1, %struct.anon.1* [[BC2]], i32 0, i32 0 // CHECK: [[LOAD2:%[0-9]+]] = load i64, i64* [[RES3]], // CHECK: call i32 (i8*, ...) @printf({{.*}}, i64 [[LOAD2]]) // CHECK: call i32 (i8*, ...) @printf( __builtin_dump_struct(&a, &printf); } + +void test5(void) { + struct T5A { + unsigned a : 1; + }; + + struct T5A a = { + .a = 0, + }; + + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* {{.*}}, i32 0, i32 0)) + // CHECK: [[BC1:%[0-9a-z.]+]] = bitcast %struct.T5A* %a to i8* + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD1:%[0-9a-z.]+]] = load i8, i8* [[BC1]], + // CHECK: [[CLEAR1:%[0-9a-z.]+]] = and i8 [[LOAD1]], 1 + // CHECK: [[CAST1:%[0-9a-z.]+]] = zext i8 [[CLEAR1]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST1]]) + // CHECK: call i32 (i8*, ...) @printf( + __builtin_dump_struct(&a, &printf); +} + +void test6(void) { + struct T6A { + unsigned a : 1; + unsigned b : 1; + unsigned c : 1; + }; + + struct T6A a = { + .a = 1, + .b = 0, + .c = 1, + }; + + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* {{.*}}, i32 0, i32 0)) + // CHECK: [[BC1:%[0-9a-z.]+]] = bitcast %struct.T6A* %a to i8* + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD1:%[0-9a-z.]+]] = load i8, i8* [[BC1]], + // CHECK: [[CLEAR1:%[0-9a-z.]+]] = and i8 [[LOAD1]], 1 + // CHECK: [[CAST1:%[0-9a-z.]+]] = zext i8 [[CLEAR1]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST1]]) + + // CHECK: [[BC2:%[0-9a-z.]+]] = bitcast %struct.T6A* %a to i8* + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD2:%[0-9a-z.]+]] = load i8, i8* [[BC2]], + // CHECK: [[LSHR2:%[0-9a-z.]+]] = lshr i8 [[LOAD2]], 1 + // CHECK: [[CLEAR2:%[0-9a-z.]+]] = and i8 [[LSHR2]], 1 + // CHECK: [[CAST2:%[0-9a-z.]+]] = zext i8 [[CLEAR2]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST2]]) + + // CHECK: [[BC3:%[0-9a-z.]+]] = bitcast %struct.T6A* %a to i8* + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD3:%[0-9a-z.]+]] = load i8, i8* [[BC3]], + // CHECK: [[LSHR3:%[0-9a-z.]+]] = lshr i8 [[LOAD3]], 2 + // CHECK: [[CLEAR3:%[0-9a-z.]+]] = and i8 [[LSHR3]], 1 + // CHECK: [[CAST3:%[0-9a-z.]+]] = zext i8 [[CLEAR3]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST3]]) + + // CHECK: call i32 (i8*, ...) @printf( + + __builtin_dump_struct(&a, &printf); +} + +void test7(void) { + + struct T7A { + unsigned a : 1; + }; + + struct T7B { + struct T7A a; + unsigned b : 1; + }; + + struct T7B a = { + .a = {.a = 0}, + .b = 1, + }; + + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.T7B, %struct.T7B* %a, i32 0, i32 0 + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[BC1:%[−a−zA−Z._0-9]+]] = bitcast %struct.T7A* [[RES1]] to i8* + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD1:%[-a-zA-Z._0-9]+]] = load i8, i8* [[BC1]], + // CHECK: [[CLEAR1:%[-a-zA-Z._0-9]+]] = and i8 [[LOAD1]], 1 + // CHECK: [[CAST1:%[-a-zA-Z._0-9]+]] = zext i8 [[CLEAR1]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST1]]) + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[RES2:%[-a-zA-Z._0-9]+]] = getelementptr inbounds %struct.T7B, %struct.T7B* %a, i32 0, i32 1 + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD2:%[-a-zA-Z._0-9]+]] = load i8, i8* [[RES2]], align 4 + // CHECK: [[CLEAR2:%[-a-zA-Z._0-9]+]] = and i8 [[LOAD2]], 1 + // CHECK: [[CAST2:%[-a-zA-Z._0-9]+]] = zext i8 [[CLEAR2]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST2]]) + // CHECK: call i32 (i8*, ...) @printf( + __builtin_dump_struct(&a, &printf); +} + +void test8(void) { + struct T8A { + unsigned c : 1; + unsigned : 3; + unsigned : 0; + unsigned b; + }; + + struct T8A a = { + .b = 2022, + }; + + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[BC1:%[−a−zA−Z._0-9]+]] = bitcast %struct.T8A* %a to i8* + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD1:%[-a-zA-Z._0-9]+]] = load i8, i8* [[BC1]], + // CHECK: [[CLEAR1:%[-a-zA-Z._0-9]+]] = and i8 [[LOAD1]], 1 + // CHECK: [[CAST1:%[-a-zA-Z._0-9]+]] = zext i8 [[CLEAR1]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST1]]) + // CHECK: [[BC2:%[−a−zA−Z._0-9]+]] = bitcast %struct.T8A* %a to i8* + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD2:%[-a-zA-Z._0-9]+]] = load i8, i8* [[BC2]], + // CHECK: [[LSHR2:%[0-9a-z.]+]] = lshr i8 [[LOAD2]], 1 + // CHECK: [[CLEAR2:%[-a-zA-Z._0-9]+]] = and i8 [[LSHR2]], 7 + // CHECK: [[CAST2:%[-a-zA-Z._0-9]+]] = zext i8 [[CLEAR2]] to i32 + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[CAST2]]) + // CHECK: [[RES3:%[-a-zA-Z._0-9]+]] = getelementptr inbounds %struct.T8A, %struct.T8A* %a, i32 0, i32 1 + // CHECK: call i32 (i8*, ...) @printf( + // CHECK: [[LOAD3:%[-a-zA-Z._0-9]+]] = load i32, i32* [[RES3]], + // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* {{.*}}, i32 0, i32 0), i32 [[LOAD3]]) + // CHECK: call i32 (i8*, ...) @printf( + __builtin_dump_struct(&a, &printf); +}