aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/LiveVariables.cpp
diff options
context:
space:
mode:
authorBalazs Benics <benicsbalazs@gmail.com>2025-02-12 16:07:49 +0100
committerGitHub <noreply@github.com>2025-02-12 16:07:49 +0100
commitbe25d618320d136faffd9dc450b406557e07634e (patch)
tree1ca4925cc57d14fdb810cb8e298ff9c6e7fd16f0 /clang/lib/Analysis/LiveVariables.cpp
parent830a2911ee164e32a5459e2991233afb7168c812 (diff)
downloadllvm-be25d618320d136faffd9dc450b406557e07634e.zip
llvm-be25d618320d136faffd9dc450b406557e07634e.tar.gz
llvm-be25d618320d136faffd9dc450b406557e07634e.tar.bz2
[clang][analysis] Fix flaky clang/test/Analysis/live-stmts.cpp test (#126913)
Multiple people reported flaky bot failures tied to `clang/test/Analysis/live-stmts.cpp` I tried reproducing the flaky behavior on my Linux x86_64 system, but the tests appears to be stable in my context. Only by looking at the failures reported, I could formulate a potential diagnosis. The output always looked almost the same, except that the Exprs dumped per Basic block were shuffled compared to my expectation. This suggests to me some ordering issue. If you look at the backing storage of `blocksEndToLiveness[B].liveExprs`, it uses `llvm::ImmutableSet<const Expr *>`. That container likely uses the pointer values as keys, thus the runtime values of the addresses influence the iteration order. To fix this, before dumping, I sort the expressions by their "beginLocs". It should be efficient enough for a debug checker, where there is no performance constraint. This should hopefully fix the flaky behavior on systems where ASLR works differently than (my) Linux system. Hopefully fixes #126619 Hopefully fixes #126804
Diffstat (limited to 'clang/lib/Analysis/LiveVariables.cpp')
-rw-r--r--clang/lib/Analysis/LiveVariables.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp
index 481932e..af56370 100644
--- a/clang/lib/Analysis/LiveVariables.cpp
+++ b/clang/lib/Analysis/LiveVariables.cpp
@@ -16,7 +16,9 @@
#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
+#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <optional>
@@ -662,12 +664,19 @@ void LiveVariables::dumpExprLiveness(const SourceManager &M) {
}
void LiveVariablesImpl::dumpExprLiveness(const SourceManager &M) {
+ auto ByBeginLoc = [&M](const Expr *L, const Expr *R) {
+ return M.isBeforeInTranslationUnit(L->getBeginLoc(), R->getBeginLoc());
+ };
+
// Don't iterate over blockEndsToLiveness directly because it's not sorted.
for (const CFGBlock *B : *analysisContext.getCFG()) {
llvm::errs() << "\n[ B" << B->getBlockID()
<< " (live expressions at block exit) ]\n";
- for (const Expr *E : blocksEndToLiveness[B].liveExprs) {
+ std::vector<const Expr *> LiveExprs;
+ llvm::append_range(LiveExprs, blocksEndToLiveness[B].liveExprs);
+ llvm::sort(LiveExprs, ByBeginLoc);
+ for (const Expr *E : LiveExprs) {
llvm::errs() << "\n";
E->dump();
}