[PATCH] D157267: [NewGVN] Fix an use after free when updating use count

Konstantina Mitropoulou via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 18 14:19:59 PDT 2023


kmitropoulou added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/NewGVN.cpp:4119
           if (isSSACopy) {
             unsigned &IIUseCount = UseCounts[II];
             if (--IIUseCount == 0)
----------------
The test case does not crash in my workspace. Anyway, I think the problem is here. If II is not in the UseCounts map, then it just adds it and it returns zero. Will the following change solve the problem?

if (isSSACopy) {
    auto It = UseCounts.find(II);
    if (It != UseCounts.end()) {
        unsigned &IIUseCount = It->second;
        if (--IIUseCount == 0)
             ProbablyDead.insert(II);
    }
}



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157267/new/

https://reviews.llvm.org/D157267



More information about the llvm-commits mailing list