From 6e06f1cd0816b03d9336083667a0c71760d6b99f Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sun, 13 Sep 2020 12:54:36 -0700 Subject: [PATCH] GCOVProfiling: Avoid use-after-move Turns out this was use-after-move of function_ref, which is trivially copyable and movable, so the move did nothing and use after move was safe. But since this function_ref is being copied into a std::function, change the function_ref to be std::function to avoid extra layers of type erasure indirection - and then it's a real use after move, and fix that by referring to the moved-to member variable rather than the moved-from parameter. --- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 68199f6..c72c448 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -99,10 +99,10 @@ class GCOVProfiler { public: GCOVProfiler() : GCOVProfiler(GCOVOptions::getDefault()) {} GCOVProfiler(const GCOVOptions &Opts) : Options(Opts) {} - bool runOnModule(Module &M, - function_ref GetBFI, - function_ref GetBPI, - function_ref GetTLI); + bool + runOnModule(Module &M, function_ref GetBFI, + function_ref GetBPI, + std::function GetTLI); void write(uint32_t i) { char Bytes[4]; @@ -609,7 +609,7 @@ std::string GCOVProfiler::mangleName(const DICompileUnit *CU, bool GCOVProfiler::runOnModule( Module &M, function_ref GetBFI, function_ref GetBPI, - function_ref GetTLI) { + std::function GetTLI) { this->M = &M; this->GetTLI = std::move(GetTLI); Ctx = &M.getContext(); @@ -622,7 +622,7 @@ bool GCOVProfiler::runOnModule( FilterRe = createRegexesFromString(Options.Filter); ExcludeRe = createRegexesFromString(Options.Exclude); - emitProfileNotes(CUNode, HasExecOrFork, GetBFI, GetBPI, GetTLI); + emitProfileNotes(CUNode, HasExecOrFork, GetBFI, GetBPI, this->GetTLI); return true; } -- 2.7.4