Skip to content

Commit c6592d6

Browse files
committed
Update MSVCMacroRebuilding
1 parent 10af248 commit c6592d6

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

llvm/include/llvm/Transforms/IPO/MSVCMacroRebuilding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class MSVCMacroRebuildingPass : public PassInfoMixin<MSVCMacroRebuildingPass> {
1717

1818
private:
1919
// Replace '__FUNCTION__'
20-
bool replace__FUNCTION__(GlobalVariable &GV, ConstantDataArray *CDA,
21-
StringRef FunctionName);
20+
bool replace__FUNCTION__(std::string &RegexStr, GlobalVariable &GV,
21+
ConstantDataArray *CDA, StringRef FunctionName);
2222

2323
public:
2424
MSVCMacroRebuildingPass() {}

llvm/lib/Transforms/IPO/MSVCMacroRebuilding.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,10 @@
2222
using 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

Comments
 (0)