@@ -4740,6 +4740,10 @@ struct DwarfLangField : public MDUnsignedField {
47404740 DwarfLangField () : MDUnsignedField(0 , dwarf::DW_LANG_hi_user) {}
47414741};
47424742
4743+ struct DwarfSourceLangNameField : public MDUnsignedField {
4744+ DwarfSourceLangNameField () : MDUnsignedField(0 , UINT32_MAX) {}
4745+ };
4746+
47434747struct DwarfCCField : public MDUnsignedField {
47444748 DwarfCCField () : MDUnsignedField(0 , dwarf::DW_CC_hi_user) {}
47454749};
@@ -4997,6 +5001,25 @@ bool LLParser::parseMDField(LocTy Loc, StringRef Name, DwarfLangField &Result) {
49975001 return false ;
49985002}
49995003
5004+ template <>
5005+ bool LLParser::parseMDField (LocTy Loc, StringRef Name,
5006+ DwarfSourceLangNameField &Result) {
5007+ if (Lex.getKind () == lltok::APSInt)
5008+ return parseMDField (Loc, Name, static_cast <MDUnsignedField &>(Result));
5009+
5010+ if (Lex.getKind () != lltok::DwarfSourceLangName)
5011+ return tokError (" expected DWARF source language name" );
5012+
5013+ unsigned Lang = dwarf::getSourceLanguageName (Lex.getStrVal ());
5014+ if (!Lang)
5015+ return tokError (" invalid DWARF source language name" + Twine (" '" ) +
5016+ Lex.getStrVal () + " '" );
5017+ assert (Lang <= Result.Max && " Expected valid DWARF source language name" );
5018+ Result.assign (Lang);
5019+ Lex.Lex ();
5020+ return false ;
5021+ }
5022+
50005023template <>
50015024bool LLParser::parseMDField (LocTy Loc, StringRef Name, DwarfCCField &Result) {
50025025 if (Lex.getKind () == lltok::APSInt)
@@ -5836,9 +5859,12 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
58365859 if (!IsDistinct)
58375860 return tokError (" missing 'distinct', required for !DICompileUnit" );
58385861
5862+ LocTy Loc = Lex.getLoc ();
5863+
58395864#define VISIT_MD_FIELDS (OPTIONAL, REQUIRED ) \
5840- REQUIRED (language, DwarfLangField, ); \
58415865 REQUIRED (file, MDField, (/* AllowNull */ false )); \
5866+ OPTIONAL (language, DwarfLangField, ); \
5867+ OPTIONAL (sourceLanguageName, DwarfSourceLangNameField, ); \
58425868 OPTIONAL (producer, MDStringField, ); \
58435869 OPTIONAL (isOptimized, MDBoolField, ); \
58445870 OPTIONAL (flags, MDStringField, ); \
@@ -5860,12 +5886,23 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
58605886 PARSE_MD_FIELDS ();
58615887#undef VISIT_MD_FIELDS
58625888
5889+ if (!language.Seen && !sourceLanguageName.Seen )
5890+ return error (Loc, " missing one of 'language' or 'sourceLanguageName', "
5891+ " required for !DICompileUnit" );
5892+
5893+ if (language.Seen && sourceLanguageName.Seen )
5894+ return error (Loc, " can only specify one of 'language' and "
5895+ " 'sourceLanguageName' on !DICompileUnit" );
5896+
58635897 Result = DICompileUnit::getDistinct (
5864- Context, DISourceLanguageName (language.Val ), file.Val , producer.Val ,
5865- isOptimized.Val , flags.Val , runtimeVersion.Val , splitDebugFilename.Val ,
5866- emissionKind.Val , enums.Val , retainedTypes.Val , globals.Val , imports.Val ,
5867- macros.Val , dwoId.Val , splitDebugInlining.Val , debugInfoForProfiling.Val ,
5868- nameTableKind.Val , rangesBaseAddress.Val , sysroot.Val , sdk.Val );
5898+ Context,
5899+ language.Seen ? DISourceLanguageName (language.Val )
5900+ : DISourceLanguageName (sourceLanguageName.Val , 0 ),
5901+ file.Val , producer.Val , isOptimized.Val , flags.Val , runtimeVersion.Val ,
5902+ splitDebugFilename.Val , emissionKind.Val , enums.Val , retainedTypes.Val ,
5903+ globals.Val , imports.Val , macros.Val , dwoId.Val , splitDebugInlining.Val ,
5904+ debugInfoForProfiling.Val , nameTableKind.Val , rangesBaseAddress.Val ,
5905+ sysroot.Val , sdk.Val );
58695906 return false ;
58705907}
58715908
0 commit comments