Avoid a double-free of HipifyPPCallbacks instance

This bug was present all along, but something changed in the order
of de-initialisation performed by llvm that makes it actually
crash now.

The constructor of HipifyPPCallbacks gives:
```
std::unique_ptr<HipifyPPCallbacks>(this)
```
to the LLVM Preprocessor instance. The Preprocessor instance
subsequently frees the HipifyPPCallbacks, which is then freed
again when we leave the stack frame at line 4340.

So: let's leak the HipifyPPCallbacks onto the heap, and leave
the LLVM Preprocessor object responsible for tidying it up.


[ROCm/clr commit: 893ee6d6ca]
This commit is contained in:
Chris Kitching
2017-10-15 11:51:35 +01:00
parent 64a26027b7
commit d0feaee4f4
@@ -4302,12 +4302,12 @@ int main(int argc, const char **argv) {
replacementsToUse = &Tool.getReplacements(); replacementsToUse = &Tool.getReplacements();
#endif #endif
HipifyPPCallbacks PPCallbacks(replacementsToUse, tmpFile); HipifyPPCallbacks* PPCallbacks = new HipifyPPCallbacks(replacementsToUse, tmpFile);
Cuda2HipCallback Callback(replacementsToUse, &Finder, &PPCallbacks, tmpFile); Cuda2HipCallback Callback(replacementsToUse, &Finder, PPCallbacks, tmpFile);
addAllMatchers(Finder, &Callback); addAllMatchers(Finder, &Callback);
auto action = newFrontendActionFactory(&Finder, &PPCallbacks); auto action = newFrontendActionFactory(&Finder, PPCallbacks);
Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster("--cuda-host-only", ArgumentInsertPosition::BEGIN)); Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster("--cuda-host-only", ArgumentInsertPosition::BEGIN));
@@ -4365,13 +4365,13 @@ int main(int argc, const char **argv) {
} }
std::remove(csv.c_str()); std::remove(csv.c_str());
} }
if (0 == printStats(csv, src, PPCallbacks, Callback, repBytes, bytes, lines, start)) { if (0 == printStats(csv, src, *PPCallbacks, Callback, repBytes, bytes, lines, start)) {
filesTranslated--; filesTranslated--;
} }
start = std::chrono::steady_clock::now(); start = std::chrono::steady_clock::now();
repBytesTotal += repBytes; repBytesTotal += repBytes;
bytesTotal += bytes; bytesTotal += bytes;
changedLinesTotal += PPCallbacks.LOCs.size() + Callback.LOCs.size(); changedLinesTotal += PPCallbacks->LOCs.size() + Callback.LOCs.size();
linesTotal += lines; linesTotal += lines;
} }
dst.clear(); dst.clear();