2222using namespace llvm ;
2323
2424// Replace '__FUNCTION__'
25- bool MSVCMacroRebuildingPass::replace__FUNCTION__ (GlobalVariable &GV,
25+ bool MSVCMacroRebuildingPass::replace__FUNCTION__ (std::string &RegexStr,
26+ GlobalVariable &GV,
2627 ConstantDataArray *CDA,
2728 StringRef FunctionName) {
28- // Construct the regular expression used to match the
29- // macro marker and the file name with escaped backslashes and line number.
30- static std::string RegexStr =
31- MSVCMacroRebuildingPass::get__FUNCTION__MarkerName ().str () +
32- std::regex_replace (GV.getParent ()->getSourceFileName (),
33- std::regex (" \\\\ " ), " \\\\ " ) +
34- " \\ (Line:\\ d+\\ )" ;
3529
3630 // Get the original string value of the constant data array.
3731 std::string OriginalStr = CDA->getAsCString ().str ();
@@ -71,6 +65,13 @@ PreservedAnalyses MSVCMacroRebuildingPass::run(Module &M,
7165 ModuleAnalysisManager &AM) {
7266 bool Changed = false ;
7367
68+ // Construct the regular expression used to match the
69+ // macro marker and the file name with escaped backslashes and line number.
70+ std::string RegexStrFor__FUNCTION__ =
71+ MSVCMacroRebuildingPass::get__FUNCTION__MarkerName ().str () +
72+ std::regex_replace (M.getSourceFileName (), std::regex (" \\\\ " ), " \\\\ " ) +
73+ " \\ (Line:\\ d+\\ )" ;
74+
7475 // Iterate over all global variables in the input module.
7576 for (GlobalVariable &GV : M.globals ()) {
7677 // Skip the variable if it does not have an initializer.
@@ -96,7 +97,8 @@ PreservedAnalyses MSVCMacroRebuildingPass::run(Module &M,
9697 continue ;
9798
9899 // Replace '__FUNCTION__'
99- Changed |= replace__FUNCTION__ (GV, CDA, F->getName ());
100+ Changed |= replace__FUNCTION__ (RegexStrFor__FUNCTION__, GV, CDA,
101+ F->getName ());
100102 }
101103 }
102104 }
0 commit comments