Closed gregbedwell closed 2 years ago
mentioned in issue llvm/llvm-bugzilla-archive#37222
Ought to be fixed in r319230.
Thanks! Looks like FileOutputBuffer.cpp is compiling now with that fix in.
Ought to be fixed in r319230.
It looks like the right solution is - similar in sprit to the other bug - to not generate a new dbg.value when for a piece of the alloca that is outside of the variable (since the alloca may be larger than the variable).
reduced testcase for opt -sroa:
; ModuleID = '
%struct.F = type { %struct.B, i8 } %struct.B = type { [0 x double], [8 x i8] }
define void @"\01?fn3@@YAXXZ"() local_unnamed_addr !dbg !31 { entry: %tmp = alloca %struct.F, align 8 %0 = bitcast %struct.F %tmp to i8, !dbg !34 call void @llvm.lifetime.start.p0i8(i64 16, i8 %0), !dbg !34 call void @llvm.dbg.declare(metadata %struct.F %tmp, metadata !35, metadata !DIExpression()), !dbg !40 %_Myval2.i.i.i.i.i = bitcast %struct.F %tmp to i32, !dbg !71 store i32 0, i32* %_Myval2.i.i.i.i.i, align 8, !dbg !71 ret void, !dbg !82 }
; Function Attrs: argmemonly nounwind declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #0
; Function Attrs: nounwind readnone speculatable declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
attributes #0 = { argmemonly nounwind } attributes #1 = { nounwind readnone speculatable }
!llvm.dbg.cu = !{#0} !llvm.module.flags = !{#27, !28, !29, !30}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 319178) (llvm/trunk 319187)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !3) !1 = !DIFile(filename: "/Data/radar/35723927/test.cpp", directory: "/Data/radar/35723927") !2 = !{} !3 = !{#4} !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) !5 = distinct !DIGlobalVariable(name: "Dd", linkageName: "\01?Dd@@3UD@@A", scope: !0, file: !1, line: 19, type: !6, isLocal: false, isDefinition: true) !6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "D", file: !1, line: 14, size: 8, elements: !7, identifier: ".?AUD@@") !7 = !{#8} !8 = !DISubprogram(name: "takePayload", linkageName: "\01?takePayload@D@@QEAA?AUC@@XZ", scope: !6, file: !1, line: 15, type: !9, isLocal: false, isDefinition: false, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true) !9 = !DISubroutineType(types: !10) !10 = !{#11, !26} !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !1, line: 9, size: 32, elements: !12, identifier: ".?AUC@@") !12 = !{#13, !22} !13 = !DIDerivedType(tag: DW_TAG_member, name: "_Mypair", scope: !11, file: !1, line: 11, baseType: !14, size: 32) !14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !1, line: 2, size: 32, elements: !15, identifier: ".?AUA@@") !15 = !{#16, !18} !16 = !DIDerivedType(tag: DW_TAG_member, name: "_Myval2", scope: !14, file: !1, line: 3, baseType: !17, size: 32) !17 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !18 = !DISubprogram(name: "A", scope: !14, file: !1, line: 4, type: !19, isLocal: false, isDefinition: false, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true) !19 = !DISubroutineType(types: !20) !20 = !{null, !21} !21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) !22 = !DISubprogram(name: "C", scope: !11, file: !1, line: 10, type: !23, isLocal: false, isDefinition: false, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: true) !23 = !DISubroutineType(types: !24) !24 = !{null, !25, !17} !25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) !26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) !27 = !{i32 2, !"Dwarf Version", i32 4} !28 = !{i32 2, !"Debug Info Version", i32 3} !29 = !{i32 1, !"wchar_size", i32 2} !30 = !{i32 7, !"PIC Level", i32 2} !31 = distinct !DISubprogram(name: "fn3", linkageName: "\01?fn3@@YAXXZ", scope: !1, file: !1, line: 30, type: !32, isLocal: false, isDefinition: true, scopeLine: 30, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) !32 = !DISubroutineType(types: !33) !33 = !{null} !34 = !DILocation(line: 30, column: 14, scope: !31) !35 = !DILocalVariable(name: "Tmp", scope: !36, file: !1, line: 16, type: !11) !36 = distinct !DISubprogram(name: "takePayload", linkageName: "\01?takePayload@D@@QEAA?AUC@@XZ", scope: !6, file: !1, line: 15, type: !9, isLocal: false, isDefinition: true, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !8, variables: !37) !37 = !{#38, !35} !38 = !DILocalVariable(name: "this", arg: 1, scope: !36, type: !39, flags: DIFlagArtificial | DIFlagObjectPointer) !39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64) !40 = !DILocation(line: 16, column: 7, scope: !36, inlinedAt: !41) !41 = distinct !DILocation(line: 24, column: 19, scope: !42, inlinedAt: !66) !42 = distinct !DILexicalBlock(scope: !43, file: !1, line: 22, column: 25) !43 = distinct !DISubprogram(name: "F", linkageName: "\01??0F@@QEAA@UD@@@Z", scope: !44, file: !1, line: 22, type: !57, isLocal: false, isDefinition: true, scopeLine: 22, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !56, variables: !60) !44 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "F", file: !1, line: 21, size: 128, elements: !45, identifier: ".?AUF@@") !45 = !{#46, !54, !56} !46 = !DIDerivedType(tag: DW_TAG_member, name: "ErrorStorage", scope: !44, file: !1, line: 26, baseType: !47, size: 64) !47 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "B", file: !1, line: 6, size: 64, elements: !48, identifier: ".?AUB@@") !48 = !{#49} !49 = !DIDerivedType(tag: DW_TAG_member, name: "buffer", scope: !47, file: !1, line: 7, baseType: !50) !50 = !DICompositeType(tag: DW_TAG_array_type, baseType: !51, elements: !52) !51 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float) !52 = !{#53} !53 = !DISubrange(count: -1) !54 = !DIDerivedType(tag: DW_TAG_member, name: "HasError", scope: !44, file: !1, line: 27, baseType: !55, size: 8, offset: 64) !55 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) !56 = !DISubprogram(name: "F", scope: !44, file: !1, line: 22, type: !57, isLocal: false, isDefinition: false, scopeLine: 22, flags: DIFlagPrototyped, isOptimized: true) !57 = !DISubroutineType(types: !58) !58 = !{null, !59, !6} !59 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !44, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) !60 = !{#61, !62, !64} !61 = !DILocalVariable(name: "Err", arg: 2, scope: !43, file: !1, line: 22, type: !6) !62 = !DILocalVariable(name: "this", arg: 1, scope: !43, type: !63, flags: DIFlagArtificial | DIFlagObjectPointer) !63 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !44, size: 64) !64 = !DILocalVariable(name: "e", scope: !42, file: !1, line: 23, type: !65) !65 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) !66 = distinct !DILocation(line: 29, column: 18, scope: !67, inlinedAt: !70) !67 = distinct !DISubprogram(name: "fn2", linkageName: "\01?fn2@@YA?AUF@@XZ", scope: !1, file: !1, line: 29, type: !68, isLocal: false, isDefinition: true, scopeLine: 29, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) !68 = !DISubroutineType(types: !69) !69 = !{#44} !70 = distinct !DILocation(line: 30, column: 14, scope: !31) !71 = !DILocation(line: 4, column: 9, scope: !72, inlinedAt: !76) !72 = distinct !DISubprogram(name: "A", linkageName: "\01??0A@@QEAA@XZ", scope: !14, file: !1, line: 4, type: !19, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !18, variables: !73) !73 = !{#74} !74 = !DILocalVariable(name: "this", arg: 1, scope: !72, type: !75, flags: DIFlagArtificial | DIFlagObjectPointer) !75 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) !76 = distinct !DILocation(line: 10, column: 3, scope: !77, inlinedAt: !81) !77 = distinct !DISubprogram(name: "C", linkageName: "\01??0C@@QEAA@H@Z", scope: !11, file: !1, line: 10, type: !23, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !22, variables: !78) !78 = !{#79, !80} !79 = !DILocalVariable(arg: 2, scope: !77, file: !1, line: 10, type: !17) !80 = !DILocalVariable(name: "this", arg: 1, scope: !77, type: !65, flags: DIFlagArtificial | DIFlagObjectPointer) !81 = distinct !DILocation(line: 16, column: 7, scope: !36, inlinedAt: !41) !82 = !DILocation(line: 30, column: 21, scope: !31)
It's again happening in SROA
IR Dump After Deduce function attributes ; Function Attrs: uwtable define void @"\01?fn3@@YAXXZ"() local_unnamed_addr #0 !dbg !34 { entry: %tmp = alloca %struct.F, align 8 %0 = bitcast %struct.F %tmp to i8, !dbg !37 call void @llvm.lifetime.start.p0i8(i64 16, i8 %0) #5, !dbg !37 call void @llvm.dbg.value(metadata %struct.F %tmp, metadata !38, metadata !DIExpression()), !dbg !61 %HasError.i.i = getelementptr inbounds %struct.F, %struct.F %tmp, i64 0, i32 1, !dbg !67 store i8 0, i8 %HasError.i.i, align 8, !dbg !67, !tbaa !68, !alias.scope !72 call void @llvm.dbg.value(metadata %struct.F %tmp, metadata !58, metadata !DIExpression()), !dbg !75 call void @llvm.dbg.value(metadata %struct.D undef, metadata !57, metadata !DIExpression()), !dbg !76 call void @llvm.dbg.value(metadata %struct.D undef, metadata !77, metadata !DIExpression()), !dbg !82 call void @llvm.dbg.declare(metadata %struct.F %tmp, metadata !80, metadata !DIExpression()), !dbg !84 %call.i.i.i = call i32 @"\01?getPtr@@YAHXZ"(), !dbg !85, !noalias !86 call void @llvm.dbg.value(metadata i32 %call.i.i.i, metadata !89, metadata !DIExpression()), !dbg !93 call void @llvm.dbg.value(metadata %struct.F %tmp, metadata !92, metadata !DIExpression()), !dbg !95 call void @llvm.dbg.value(metadata %struct.F %tmp, metadata !96, metadata !DIExpression(DW_OP_stack_value)), !dbg !100 %_Myval2.i.i.i.i.i = bitcast %struct.F %tmp to i32, !dbg !102 store i32 0, i32 %_Myval2.i.i.i.i.i, align 8, !dbg !102, !tbaa !103, !alias.scope !86 call void @llvm.lifetime.end.p0i8(i64 16, i8 %0) #5, !dbg !37 ret void, !dbg !106 } IR Dump After SROA ; Function Attrs: uwtable define void @"\01?fn3@@YAXXZ"() local_unnamed_addr #0 !dbg !117 { entry: call void @llvm.dbg.declare(metadata !4, metadata !72, metadata !DIExpression()), !dbg !120 call void @llvm.dbg.declare(metadata !4, metadata !72, metadata !DIExpression(DW_OP_LLVM_fragment, 72, 56)), !dbg !120 call void @llvm.dbg.value(metadata %struct.F undef, metadata !53, metadata !DIExpression()), !dbg !124 call void @llvm.dbg.value(metadata i8 0, metadata !72, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 8)), !dbg !120 call void @llvm.dbg.value(metadata %struct.F undef, metadata !57, metadata !DIExpression()), !dbg !125 call void @llvm.dbg.value(metadata %struct.D undef, metadata !56, metadata !DIExpression()), !dbg !126 call void @llvm.dbg.value(metadata %struct.D undef, metadata !69, metadata !DIExpression()), !dbg !127 %call.i.i.i = call i32 @"\01?getPtr@@YAHXZ"(), !dbg !128, !noalias !129 call void @llvm.dbg.value(metadata i32 %call.i.i.i, metadata !81, metadata !DIExpression()), !dbg !134 call void @llvm.dbg.value(metadata %struct.F undef, metadata !84, metadata !DIExpression()), !dbg !136 call void @llvm.dbg.value(metadata %struct.F undef, metadata !88, metadata !DIExpression(DW_OP_stack_value)), !dbg !137 call void @llvm.dbg.value(metadata i32 0, metadata !72, metadata !DIExpression()), !dbg !120 ret void, !dbg !139 }
Thanks! I will try to fix this today.
assigned to @adrian-prantl
Extended Description
The fix from Bug 35416 resolved that issue, however it seems that the file in question (lib/Support/FileOutputBuffer.cpp) is still refusing to compile with TOT clang.
Here's another source-level reduced testcase (it only looks subtly different to the one from Bug 35416, so hopefully the fix is too):
$ type 1.cpp // ====================================================== struct A { int _Myval2; A() : _Myval2() {} }; struct B { double buffer[]; }; struct C { C(int) {} A _Mypair; }; int getPtr(); struct D { C takePayload() { C Tmp(getPtr()); return Tmp; } } Dd; void operator new(size_t, void ); struct F { F(D Err) : HasError() { C e = (C )(ErrorStorage.buffer); new (e) C(Err.takePayload()); } B ErrorStorage; bool HasError; }; F fn2() { return Dd; } void fn3() { fn2(); } // ======================================================
$ clang.exe -target x86_64-windows-pc-msvc -c -w -g -O2 1.cpp fragment is larger than or outside of variable call void @llvm.dbg.value(metadata i8 0, metadata !72, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 8)), !dbg !105 !72 = !DILocalVariable(name: "Tmp", scope: !70, file: !3, line: 16, type: !7) fragment is larger than or outside of variable call void @llvm.dbg.value(metadata i8 0, metadata !72, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 8)), !dbg !105 !72 = !DILocalVariable(name: "Tmp", scope: !70, file: !3, line: 16, type: !7) fatal error: error in backend: Broken module found, compilation aborted! clang.exe: error: clang frontend command failed with exit code 70 (use -v to see invocation) clang version 6.0.0 (trunk 319007) (llvm/trunk 319177) Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\work\public-git\upstream-llvm\build-vs2015-ps4-master\Release\bin clang.exe: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang.exe: note: diagnostic msg: