@@ -4742,6 +4742,10 @@ struct DwarfLangField : public MDUnsignedField {
4742
4742
DwarfLangField () : MDUnsignedField(0 , dwarf::DW_LANG_hi_user) {}
4743
4743
};
4744
4744
4745
+ struct DwarfSourceLangNameField : public MDUnsignedField {
4746
+ DwarfSourceLangNameField () : MDUnsignedField(0 , UINT32_MAX) {}
4747
+ };
4748
+
4745
4749
struct DwarfCCField : public MDUnsignedField {
4746
4750
DwarfCCField () : MDUnsignedField(0 , dwarf::DW_CC_hi_user) {}
4747
4751
};
@@ -5003,6 +5007,25 @@ bool LLParser::parseMDField(LocTy Loc, StringRef Name, DwarfLangField &Result) {
5003
5007
return false ;
5004
5008
}
5005
5009
5010
+ template <>
5011
+ bool LLParser::parseMDField (LocTy Loc, StringRef Name,
5012
+ DwarfSourceLangNameField &Result) {
5013
+ if (Lex.getKind () == lltok::APSInt)
5014
+ return parseMDField (Loc, Name, static_cast <MDUnsignedField &>(Result));
5015
+
5016
+ if (Lex.getKind () != lltok::DwarfSourceLangName)
5017
+ return tokError (" expected DWARF source language name" );
5018
+
5019
+ unsigned Lang = dwarf::getSourceLanguageName (Lex.getStrVal ());
5020
+ if (!Lang)
5021
+ return tokError (" invalid DWARF source language name" + Twine (" '" ) +
5022
+ Lex.getStrVal () + " '" );
5023
+ assert (Lang <= Result.Max && " Expected valid DWARF source language name" );
5024
+ Result.assign (Lang);
5025
+ Lex.Lex ();
5026
+ return false ;
5027
+ }
5028
+
5006
5029
template <>
5007
5030
bool LLParser::parseMDField (LocTy Loc, StringRef Name, DwarfCCField &Result) {
5008
5031
if (Lex.getKind () == lltok::APSInt)
@@ -5842,9 +5865,12 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
5842
5865
if (!IsDistinct)
5843
5866
return tokError (" missing 'distinct', required for !DICompileUnit" );
5844
5867
5868
+ LocTy Loc = Lex.getLoc ();
5869
+
5845
5870
#define VISIT_MD_FIELDS (OPTIONAL, REQUIRED ) \
5846
- REQUIRED (language, DwarfLangField, ); \
5847
5871
REQUIRED (file, MDField, (/* AllowNull */ false )); \
5872
+ OPTIONAL (language, DwarfLangField, ); \
5873
+ OPTIONAL (sourceLanguageName, DwarfSourceLangNameField, ); \
5848
5874
OPTIONAL (producer, MDStringField, ); \
5849
5875
OPTIONAL (isOptimized, MDBoolField, ); \
5850
5876
OPTIONAL (flags, MDStringField, ); \
@@ -5866,12 +5892,23 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
5866
5892
PARSE_MD_FIELDS ();
5867
5893
#undef VISIT_MD_FIELDS
5868
5894
5895
+ if (!language.Seen && !sourceLanguageName.Seen )
5896
+ return error (Loc, " missing one of 'language' or 'sourceLanguageName', "
5897
+ " required for !DICompileUnit" );
5898
+
5899
+ if (language.Seen && sourceLanguageName.Seen )
5900
+ return error (Loc, " can only specify one of 'language' and "
5901
+ " 'sourceLanguageName' on !DICompileUnit" );
5902
+
5869
5903
Result = DICompileUnit::getDistinct (
5870
- Context, DISourceLanguageName (language.Val ), file.Val , producer.Val ,
5871
- isOptimized.Val , flags.Val , runtimeVersion.Val , splitDebugFilename.Val ,
5872
- emissionKind.Val , enums.Val , retainedTypes.Val , globals.Val , imports.Val ,
5873
- macros.Val , dwoId.Val , splitDebugInlining.Val , debugInfoForProfiling.Val ,
5874
- nameTableKind.Val , rangesBaseAddress.Val , sysroot.Val , sdk.Val );
5904
+ Context,
5905
+ language.Seen ? DISourceLanguageName (language.Val )
5906
+ : DISourceLanguageName (sourceLanguageName.Val , 0 ),
5907
+ file.Val , producer.Val , isOptimized.Val , flags.Val , runtimeVersion.Val ,
5908
+ splitDebugFilename.Val , emissionKind.Val , enums.Val , retainedTypes.Val ,
5909
+ globals.Val , imports.Val , macros.Val , dwoId.Val , splitDebugInlining.Val ,
5910
+ debugInfoForProfiling.Val , nameTableKind.Val , rangesBaseAddress.Val ,
5911
+ sysroot.Val , sdk.Val );
5875
5912
return false ;
5876
5913
}
5877
5914
0 commit comments