@@ -4740,6 +4740,10 @@ struct DwarfLangField : public MDUnsignedField {
4740
4740
DwarfLangField () : MDUnsignedField(0 , dwarf::DW_LANG_hi_user) {}
4741
4741
};
4742
4742
4743
+ struct DwarfSourceLangNameField : public MDUnsignedField {
4744
+ DwarfSourceLangNameField () : MDUnsignedField(0 , UINT32_MAX) {}
4745
+ };
4746
+
4743
4747
struct DwarfCCField : public MDUnsignedField {
4744
4748
DwarfCCField () : MDUnsignedField(0 , dwarf::DW_CC_hi_user) {}
4745
4749
};
@@ -4997,6 +5001,25 @@ bool LLParser::parseMDField(LocTy Loc, StringRef Name, DwarfLangField &Result) {
4997
5001
return false ;
4998
5002
}
4999
5003
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
+
5000
5023
template <>
5001
5024
bool LLParser::parseMDField (LocTy Loc, StringRef Name, DwarfCCField &Result) {
5002
5025
if (Lex.getKind () == lltok::APSInt)
@@ -5836,9 +5859,12 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
5836
5859
if (!IsDistinct)
5837
5860
return tokError (" missing 'distinct', required for !DICompileUnit" );
5838
5861
5862
+ LocTy Loc = Lex.getLoc ();
5863
+
5839
5864
#define VISIT_MD_FIELDS (OPTIONAL, REQUIRED ) \
5840
- REQUIRED (language, DwarfLangField, ); \
5841
5865
REQUIRED (file, MDField, (/* AllowNull */ false )); \
5866
+ OPTIONAL (language, DwarfLangField, ); \
5867
+ OPTIONAL (sourceLanguageName, DwarfSourceLangNameField, ); \
5842
5868
OPTIONAL (producer, MDStringField, ); \
5843
5869
OPTIONAL (isOptimized, MDBoolField, ); \
5844
5870
OPTIONAL (flags, MDStringField, ); \
@@ -5860,12 +5886,23 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
5860
5886
PARSE_MD_FIELDS ();
5861
5887
#undef VISIT_MD_FIELDS
5862
5888
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
+
5863
5897
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 );
5869
5906
return false ;
5870
5907
}
5871
5908
0 commit comments