@@ -74,6 +74,23 @@ static std::string getTypeString(Type *T) {
7474 return Tmp.str ();
7575}
7676
77+ // Whatever debug info format we parsed, we should convert to the expected debug
78+ // info format immediately afterwards.
79+ bool LLParser::finalizeDebugInfoFormat (Module *M) {
80+ // We should have already returned an error if we observed both intrinsics and
81+ // records in this IR.
82+ assert (!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
83+ " Mixed debug intrinsics/records seen without a parsing error?" );
84+ if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
85+ UseNewDbgInfoFormat = SeenNewDbgInfoFormat;
86+ WriteNewDbgInfoFormatToBitcode = SeenNewDbgInfoFormat;
87+ WriteNewDbgInfoFormat = SeenNewDbgInfoFormat;
88+ } else if (M) {
89+ M->setIsNewDbgInfoFormat (false );
90+ }
91+ return false ;
92+ }
93+
7794// / Run: module ::= toplevelentity*
7895bool LLParser::Run (bool UpgradeDebugInfo,
7996 DataLayoutCallbackTy DataLayoutCallback) {
@@ -91,7 +108,7 @@ bool LLParser::Run(bool UpgradeDebugInfo,
91108 }
92109
93110 return parseTopLevelEntities () || validateEndOfModule (UpgradeDebugInfo) ||
94- validateEndOfIndex ();
111+ validateEndOfIndex () || finalizeDebugInfoFormat (M) ;
95112}
96113
97114bool LLParser::parseStandaloneConstantValue (Constant *&C,
@@ -190,18 +207,6 @@ void LLParser::dropUnknownMetadataReferences() {
190207bool LLParser::validateEndOfModule (bool UpgradeDebugInfo) {
191208 if (!M)
192209 return false ;
193-
194- // We should have already returned an error if we observed both intrinsics and
195- // records in this IR.
196- assert (!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
197- " Mixed debug intrinsics/records seen without a parsing error?" );
198- if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
199- UseNewDbgInfoFormat = SeenNewDbgInfoFormat;
200- WriteNewDbgInfoFormatToBitcode = SeenNewDbgInfoFormat;
201- WriteNewDbgInfoFormat = SeenNewDbgInfoFormat;
202- M->setNewDbgInfoFormatFlag (SeenNewDbgInfoFormat);
203- }
204-
205210 // Handle any function attribute group forward references.
206211 for (const auto &RAG : ForwardRefAttrGroups) {
207212 Value *V = RAG.first ;
@@ -434,9 +439,6 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
434439 UpgradeModuleFlags (*M);
435440 UpgradeSectionAttributes (*M);
436441
437- if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE)
438- M->setIsNewDbgInfoFormat (UseNewDbgInfoFormat);
439-
440442 if (!Slots)
441443 return false ;
442444 // Initialize the slot mapping.
0 commit comments