diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp --- a/openmp/libomptarget/src/rtl.cpp +++ b/openmp/libomptarget/src/rtl.cpp @@ -44,6 +44,8 @@ static char *ProfileTraceFile = nullptr; // List of TimeTraceProfiler instances on other threads +// Needs to be pointer. If this is a file-scope object, the destructor +// gets called before "deinit" is called. std::vector *profileInstancesOtherThreads = nullptr; std::mutex profLock; @@ -77,8 +79,8 @@ delete PM; if (ProfileTraceFile) { - for (auto prof : *profileInstancesOtherThreads) - timeTraceProfilerFinishThreadExternal(prof); + for (auto Prof : *profileInstancesOtherThreads) + timeTraceProfilerFinishThreadExternal(Prof); // TODO: add env var for file output if (auto E = timeTraceProfilerWrite(ProfileTraceFile, "-")) fprintf(stderr, "Error writing out the time trace\n"); @@ -96,9 +98,9 @@ if (llvm::getTimeTraceProfilerInstance() == nullptr) { DP("initializing profiler on thread"); llvm::timeTraceProfilerInitialize(500, "libomptarget"); - llvm::TimeTraceProfiler *prof = llvm::getTimeTraceProfilerInstance(); + llvm::TimeTraceProfiler *Prof = llvm::getTimeTraceProfilerInstance(); std::lock_guard Lock(profLock); - profileInstancesOtherThreads->push_back(prof); + profileInstancesOtherThreads->push_back(Prof); } } }