Index: llvm/trunk/include/llvm-c/DebugInfo.h =================================================================== --- llvm/trunk/include/llvm-c/DebugInfo.h +++ llvm/trunk/include/llvm-c/DebugInfo.h @@ -50,7 +50,6 @@ LLVMDIFlagIntroducedVirtual = 1 << 18, LLVMDIFlagBitField = 1 << 19, LLVMDIFlagNoReturn = 1 << 20, - LLVMDIFlagMainSubprogram = 1 << 21, LLVMDIFlagTypePassByValue = 1 << 22, LLVMDIFlagTypePassByReference = 1 << 23, LLVMDIFlagEnumClass = 1 << 24, Index: llvm/trunk/include/llvm/IR/DebugInfoFlags.def =================================================================== --- llvm/trunk/include/llvm/IR/DebugInfoFlags.def +++ llvm/trunk/include/llvm/IR/DebugInfoFlags.def @@ -50,7 +50,6 @@ HANDLE_DI_FLAG((1 << 18), IntroducedVirtual) HANDLE_DI_FLAG((1 << 19), BitField) HANDLE_DI_FLAG((1 << 20), NoReturn) -HANDLE_DI_FLAG((1 << 21), MainSubprogram) HANDLE_DI_FLAG((1 << 22), TypePassByValue) HANDLE_DI_FLAG((1 << 23), TypePassByReference) HANDLE_DI_FLAG((1 << 24), EnumClass) @@ -88,11 +87,12 @@ HANDLE_DISP_FLAG((1u << 5), Pure) HANDLE_DISP_FLAG((1u << 6), Elemental) HANDLE_DISP_FLAG((1u << 7), Recursive) +HANDLE_DISP_FLAG((1u << 8), MainSubprogram) #ifdef DISP_FLAG_LARGEST_NEEDED // Intended to be used with ADT/BitmaskEnum.h. // NOTE: Always must be equal to largest flag, check this when adding new flags. -HANDLE_DISP_FLAG((1 << 7), Largest) +HANDLE_DISP_FLAG((1 << 8), Largest) #undef DISP_FLAG_LARGEST_NEEDED #endif Index: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h =================================================================== --- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h +++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h @@ -1675,7 +1675,8 @@ // Helper for converting old bitfields to new flags word. static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, - unsigned Virtuality = SPFlagNonvirtual) { + unsigned Virtuality = SPFlagNonvirtual, + bool IsMainSubprogram = false) { // We're assuming virtuality is the low-order field. static_assert( int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) && @@ -1685,7 +1686,8 @@ (Virtuality & SPFlagVirtuality) | (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) | (IsDefinition ? SPFlagDefinition : SPFlagZero) | - (IsOptimized ? SPFlagOptimized : SPFlagZero)); + (IsOptimized ? SPFlagOptimized : SPFlagZero) | + (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero)); } private: @@ -1784,6 +1786,7 @@ bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; } bool isDefinition() const { return getSPFlags() & SPFlagDefinition; } bool isOptimized() const { return getSPFlags() & SPFlagOptimized; } + bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; } bool isArtificial() const { return getFlags() & FlagArtificial; } bool isPrivate() const { @@ -1800,7 +1803,6 @@ bool areAllCallsDescribed() const { return getFlags() & FlagAllCallsDescribed; } - bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; } bool isPure() const { return getSPFlags() & SPFlagPure; } bool isElemental() const { return getSPFlags() & SPFlagElemental; } bool isRecursive() const { return getSPFlags() & SPFlagRecursive; } Index: llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp =================================================================== --- llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp +++ llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp @@ -1406,12 +1406,33 @@ return error("Invalid record"); bool HasSPFlags = Record[0] & 4; - DISubprogram::DISPFlags SPFlags = - HasSPFlags - ? static_cast(Record[9]) - : DISubprogram::toSPFlags( - /*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8], - /*IsOptimized=*/Record[14], /*Virtuality=*/Record[11]); + + DINode::DIFlags Flags; + DISubprogram::DISPFlags SPFlags; + if (!HasSPFlags) + Flags = static_cast(Record[11 + 2]); + else { + Flags = static_cast(Record[11]); + SPFlags = static_cast(Record[9]); + } + + // Support for old metadata when + // subprogram specific flags are placed in DIFlags. + const unsigned DIFlagMainSubprogram = 1 << 21; + bool HasOldMainSubprogramFlag = Flags & DIFlagMainSubprogram; + if (HasOldMainSubprogramFlag) + // Remove old DIFlagMainSubprogram from DIFlags. + // Note: This assumes that any future use of bit 21 defaults to it + // being 0. + Flags &= ~static_cast(DIFlagMainSubprogram); + + if (HasOldMainSubprogramFlag && HasSPFlags) + SPFlags |= DISubprogram::SPFlagMainSubprogram; + else if (!HasSPFlags) + SPFlags = DISubprogram::toSPFlags( + /*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8], + /*IsOptimized=*/Record[14], /*Virtuality=*/Record[11], + /*DIFlagMainSubprogram*/HasOldMainSubprogramFlag); // All definitions should be distinct. IsDistinct = (Record[0] & 1) || (SPFlags & DISubprogram::SPFlagDefinition); @@ -1455,7 +1476,7 @@ getDITypeRefOrNull(Record[8 + OffsetA]), // containingType Record[10 + OffsetA], // virtualIndex HasThisAdj ? Record[16 + OffsetB] : 0, // thisAdjustment - static_cast(Record[11 + OffsetA]),// flags + Flags, // flags SPFlags, // SPFlags HasUnit ? CUorFn : nullptr, // unit getMDOrNull(Record[13 + OffsetB]), // templateParams Index: llvm/trunk/test/Bitcode/DISubprogram-v5.ll =================================================================== --- llvm/trunk/test/Bitcode/DISubprogram-v5.ll +++ llvm/trunk/test/Bitcode/DISubprogram-v5.ll @@ -0,0 +1,24 @@ + ; The .bc file was generated from this source using llvm-as from 8.0 release. + ; RUN: llvm-dis < %s.bc | FileCheck %s + +define i32 @main() !dbg !5 { +entry: + %retval = alloca i32, align 4 + store i32 0, i32* %retval + ret i32 0, !dbg !9 +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2) +!1 = !DIFile(filename: "mainsubprogram.c", directory: "/dir") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 1, !"Debug Info Version", i32 3} +!5 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !6, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped | DIFlagMainSubprogram, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +; CHECK: !5 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !6, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !0, retainedNodes: !2) +!6 = !DISubroutineType(types: !7) +!7 = !{!8} +!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!9 = !DILocation(line: 7, scope: !5) Index: llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll =================================================================== --- llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll +++ llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll @@ -25,7 +25,7 @@ !0 = distinct !DICompileUnit(language: DW_LANG_Rust, producer: "clang version 3.4 (trunk 185475)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !15, imports: !2) !1 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test") !2 = !{} -!4 = distinct !DISubprogram(name: "main", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2) +!4 = distinct !DISubprogram(name: "main", line: 6, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2) !5 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test") !6 = !DISubroutineType(types: !7) !7 = !{!8} Index: llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll =================================================================== --- llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll +++ llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll @@ -53,7 +53,7 @@ !2 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !3, producer: "clang LLVM (rustc version 1.24.0-dev)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4) !3 = !DIFile(filename: "e3.rs", directory: "/home/tromey/Rust") !4 = !{} -!5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, isLocal: true, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4) +!5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4) !6 = !DINamespace(name: "e3", scope: null) !7 = !DIFile(filename: "", directory: "") !8 = !DISubroutineType(types: !9) Index: llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll =================================================================== --- llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll +++ llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll @@ -25,7 +25,7 @@ !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.4 (trunk 185475)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) !1 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test") !2 = !{} -!4 = distinct !DISubprogram(name: "main", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2) +!4 = distinct !DISubprogram(name: "main", line: 6, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2) !5 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test") !6 = !DISubroutineType(types: !7) !7 = !{!8} Index: llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll =================================================================== --- llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll +++ llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll @@ -40,7 +40,7 @@ !2 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !3, producer: "clang LLVM (rustc version 1.24.0-dev)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4) !3 = !DIFile(filename: "e3.rs", directory: "/home/tromey/Rust") !4 = !{} -!5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, isLocal: true, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4) +!5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4) !6 = !DINamespace(name: "e3", scope: null) !7 = !DIFile(filename: "", directory: "") !8 = !DISubroutineType(types: !9) Index: llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll =================================================================== --- llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll +++ llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll @@ -109,7 +109,7 @@ !22 = !DIExpression() !23 = !DILocation(line: 1, scope: !11) !24 = !DILocation(line: 59, scope: !11) -!25 = distinct !DISubprogram(name: "main", linkageName: "_ZN2t24mainE", scope: !26, file: !9, line: 9, type: !27, isLocal: true, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !8, templateParams: !4, retainedNodes: !4) +!25 = distinct !DISubprogram(name: "main", linkageName: "_ZN2t24mainE", scope: !26, file: !9, line: 9, type: !27, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !8, templateParams: !4, retainedNodes: !4) !26 = !DINamespace(name: "t2", scope: null) !27 = !DISubroutineType(types: !28) !28 = !{null}