[llvm] 6e06f1c - GCOVProfiling: Avoid use-after-move
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 13:10:57 PDT 2020
Author: David Blaikie
Date: 2020-09-13T12:54:36-07:00
New Revision: 6e06f1cd0816b03d9336083667a0c71760d6b99f
URL: https://github.com/llvm/llvm-project/commit/6e06f1cd0816b03d9336083667a0c71760d6b99f
DIFF: https://github.com/llvm/llvm-project/commit/6e06f1cd0816b03d9336083667a0c71760d6b99f.diff
LOG: 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.
Added:
Modified:
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index 68199f6379d4..c72c44809acc 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<BlockFrequencyInfo *(Function &F)> GetBFI,
- function_ref<BranchProbabilityInfo *(Function &F)> GetBPI,
- function_ref<const TargetLibraryInfo &(Function &F)> GetTLI);
+ bool
+ runOnModule(Module &M, function_ref<BlockFrequencyInfo *(Function &F)> GetBFI,
+ function_ref<BranchProbabilityInfo *(Function &F)> GetBPI,
+ std::function<const TargetLibraryInfo &(Function &F)> 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<BlockFrequencyInfo *(Function &F)> GetBFI,
function_ref<BranchProbabilityInfo *(Function &F)> GetBPI,
- function_ref<const TargetLibraryInfo &(Function &F)> GetTLI) {
+ std::function<const TargetLibraryInfo &(Function &F)> 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;
}
More information about the llvm-commits
mailing list