diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 64a67c0ef2a5..100cb2eb1e10 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -746,6 +746,7 @@ lltok::Kind LLLexer::LexIdentifier() { } DWKEYWORD(TAG, DwarfTag); DWKEYWORD(ATE, DwarfAttEncoding); + DWKEYWORD(LANG, DwarfLang); #undef DWKEYWORD // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 42ce206e3af6..33f395a1f5a5 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2949,6 +2949,9 @@ struct DwarfTagField : public MDUnsignedField { struct DwarfAttEncodingField : public MDUnsignedField { DwarfAttEncodingField() : MDUnsignedField(0, dwarf::DW_ATE_hi_user) {} }; +struct DwarfLangField : public MDUnsignedField { + DwarfLangField() : MDUnsignedField(0, dwarf::DW_LANG_hi_user) {} +}; struct MDSignedField : public MDFieldImpl { int64_t Min; @@ -2960,6 +2963,9 @@ struct MDSignedField : public MDFieldImpl { : ImplTy(Default), Min(Min), Max(Max) {} }; +struct MDBoolField : public MDFieldImpl { + MDBoolField(bool Default = false) : ImplTy(Default) {} +}; struct MDField : public MDFieldImpl { MDField() : ImplTy(nullptr) {} }; @@ -3017,6 +3023,24 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) { return false; } +template <> +bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfLangField &Result) { + if (Lex.getKind() == lltok::APSInt) + return ParseMDField(Loc, Name, static_cast(Result)); + + if (Lex.getKind() != lltok::DwarfLang) + return TokError("expected DWARF language"); + + unsigned Lang = dwarf::getLanguage(Lex.getStrVal()); + if (!Lang) + return TokError("invalid DWARF language" + Twine(" '") + Lex.getStrVal() + + "'"); + assert(Lang <= Result.Max && "Expected valid DWARF language"); + Result.assign(Lang); + Lex.Lex(); + return false; +} + template <> bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfAttEncodingField &Result) { @@ -3056,6 +3080,22 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, return false; } +template <> +bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDBoolField &Result) { + switch (Lex.getKind()) { + default: + return TokError("expected 'true' or 'false'"); + case lltok::kw_true: + Result.assign(true); + break; + case lltok::kw_false: + Result.assign(false); + break; + } + Lex.Lex(); + return false; +} + template <> bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) { Metadata *MD; @@ -3273,7 +3313,7 @@ bool LLParser::ParseMDCompositeType(MDNode *&Result, bool IsDistinct) { OPTIONAL(offset, MDUnsignedField, (0, UINT32_MAX)); \ OPTIONAL(flags, MDUnsignedField, (0, UINT32_MAX)); \ OPTIONAL(elements, MDField, ); \ - OPTIONAL(runtimeLang, MDUnsignedField, (0, UINT32_MAX)); \ + OPTIONAL(runtimeLang, DwarfLangField, ); \ OPTIONAL(vtableHolder, MDField, ); \ OPTIONAL(templateParams, MDField, ); \ OPTIONAL(identifier, MDStringField, ); diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h index 65c59b5654b0..ae43a14201ac 100644 --- a/lib/AsmParser/LLToken.h +++ b/lib/AsmParser/LLToken.h @@ -200,6 +200,7 @@ namespace lltok { StringConstant, // "foo" DwarfTag, // DW_TAG_foo (includes "DW_TAG_") DwarfAttEncoding, // DW_ATE_foo (includes "DW_ATE_") + DwarfLang, // DW_LANG_foo (includes "DW_LANG_") // Type valued tokens (TyVal). Type, diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 77e2b2d64b99..0a585a097e2e 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1461,8 +1461,14 @@ static void writeMDCompositeType(raw_ostream &Out, const MDCompositeType *N, writeMetadataAsOperand(Out, N->getElements(), TypePrinter, Machine, Context); } - if (N->getRuntimeLang()) - Out << FS << "runtimeLang: " << N->getRuntimeLang(); + if (unsigned Lang = N->getRuntimeLang()) { + Out << FS << "runtimeLang: "; + if (const char *S = dwarf::LanguageString(Lang)) + Out << S; + else + Out << Lang; + } + if (N->getVTableHolder()) { Out << FS << "vtableHolder: "; writeMetadataAsOperand(Out, N->getVTableHolder(), TypePrinter, Machine, diff --git a/test/Assembler/debug-info.ll b/test/Assembler/debug-info.ll index b4b29fe77a24..0b8ada7a2318 100644 --- a/test/Assembler/debug-info.ll +++ b/test/Assembler/debug-info.ll @@ -1,8 +1,8 @@ ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s ; RUN: verify-uselistorder %s -; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23} -!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25} +; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24} +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26} ; CHECK: !0 = !MDSubrange(count: 3) ; CHECK-NEXT: !1 = !MDSubrange(count: 3, lowerBound: 4) @@ -41,22 +41,24 @@ !15 = !MDDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 32, align: 32) ; CHECK-NEXT: !14 = !MDCompositeType(tag: DW_TAG_structure_type, name: "MyType", file: !9, line: 2, size: 32, align: 32, identifier: "MangledMyType") -; CHECK-NEXT: !15 = distinct !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", file: !9, line: 3, scope: !14, size: 128, align: 32, offset: 64, flags: 3, elements: !16, runtimeLang: 6, vtableHolder: !15, templateParams: !18, identifier: "MangledBase") +; CHECK-NEXT: !15 = distinct !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", file: !9, line: 3, scope: !14, size: 128, align: 32, offset: 64, flags: 3, elements: !16, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !15, templateParams: !18, identifier: "MangledBase") ; CHECK-NEXT: !16 = !{!17} ; CHECK-NEXT: !17 = !MDDerivedType(tag: DW_TAG_member, name: "field", file: !9, line: 4, scope: !15, baseType: !6, size: 32, align: 32, offset: 32, flags: 3) ; CHECK-NEXT: !18 = !{!6} -; CHECK-NEXT: !19 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", file: !9, line: 3, scope: !14, baseType: !15, size: 128, align: 32, offset: 64, flags: 3, elements: !20, runtimeLang: 6, vtableHolder: !15, templateParams: !18, identifier: "MangledBase") +; CHECK-NEXT: !19 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", file: !9, line: 3, scope: !14, baseType: !15, size: 128, align: 32, offset: 64, flags: 3, elements: !20, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !15, templateParams: !18, identifier: "MangledBase") ; CHECK-NEXT: !20 = !{!21} ; CHECK-NEXT: !21 = !MDDerivedType(tag: DW_TAG_inheritance, scope: !19, baseType: !15) ; CHECK-NEXT: !22 = !MDDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !6, size: 32, align: 32, extraData: !15) ; CHECK-NEXT: !23 = !MDCompositeType(tag: DW_TAG_structure_type) +; CHECK-NEXT: !24 = !MDCompositeType(tag: DW_TAG_structure_type, runtimeLang: DW_LANG_Cobol85) !16 = !MDCompositeType(tag: DW_TAG_structure_type, name: "MyType", file: !11, line: 2, size: 32, align: 32, identifier: "MangledMyType") -!17 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", file: !11, line: 3, scope: !16, size: 128, align: 32, offset: 64, flags: 3, elements: !18, runtimeLang: 6, vtableHolder: !17, templateParams: !20, identifier: "MangledBase") +!17 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", file: !11, line: 3, scope: !16, size: 128, align: 32, offset: 64, flags: 3, elements: !18, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !17, templateParams: !20, identifier: "MangledBase") !18 = !{!19} !19 = !MDDerivedType(tag: DW_TAG_member, name: "field", file: !11, line: 4, scope: !17, baseType: !7, size: 32, align: 32, offset: 32, flags: 3) !20 = !{!7} -!21 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", file: !11, line: 3, scope: !16, baseType: !17, size: 128, align: 32, offset: 64, flags: 3, elements: !22, runtimeLang: 6, vtableHolder: !17, templateParams: !20, identifier: "MangledBase") +!21 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", file: !11, line: 3, scope: !16, baseType: !17, size: 128, align: 32, offset: 64, flags: 3, elements: !22, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !17, templateParams: !20, identifier: "MangledBase") !22 = !{!23} !23 = !MDDerivedType(tag: DW_TAG_inheritance, scope: !21, baseType: !17) !24 = !MDDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !7, size: 32, align: 32, extraData: !17) !25 = !MDCompositeType(tag: DW_TAG_structure_type) +!26 = !MDCompositeType(tag: DW_TAG_structure_type, runtimeLang: 6) diff --git a/utils/vim/llvm.vim b/utils/vim/llvm.vim index 6f32864ed3de..df564113185e 100644 --- a/utils/vim/llvm.vim +++ b/utils/vim/llvm.vim @@ -79,6 +79,7 @@ syn match llvmIdentifier /![-a-zA-Z$._][-a-zA-Z$._0-9]*\ze\s*[=!]/ syn match llvmType /!\zs\a\+\ze\s*(/ syn match llvmConstant /\/ syn match llvmConstant /\/ +syn match llvmConstant /\/ " Syntax-highlight dejagnu test commands. syn match llvmSpecialComment /;\s*RUN:.*$/