Skip to content

Commit 1c03684

Browse files
steakhaltstellar
authored andcommitted
[clang][analysis] Fix flaky clang/test/Analysis/live-stmts.cpp test (2nd attempt) (llvm#127406)
In my previous attempt (llvm#126913) of fixing the flaky case was on a good track when I used the begin locations as a stable ordering. However, I forgot to consider the case when the begin locations are the same among the Exprs. In an `EXPENSIVE_CHECKS` build, arrays are randomly shuffled prior to sorting them. This exposed the flaky behavior much more often basically breaking the "stability" of the vector - as it should. Because of this, I had to revert the previous fix attempt in llvm#127034. To fix this, I use this time `Expr::getID` for a stable ID for an Expr. Hopefully fixes llvm#126619 Hopefully fixes llvm#126804 (cherry picked from commit f378e52)
1 parent 0439d1d commit 1c03684

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

clang/lib/Analysis/LiveVariables.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,19 @@ void LiveVariables::dumpExprLiveness(const SourceManager &M) {
662662
}
663663

664664
void LiveVariablesImpl::dumpExprLiveness(const SourceManager &M) {
665+
const ASTContext &Ctx = analysisContext.getASTContext();
666+
auto ByIDs = [&Ctx](const Expr *L, const Expr *R) {
667+
return L->getID(Ctx) < R->getID(Ctx);
668+
};
669+
665670
// Don't iterate over blockEndsToLiveness directly because it's not sorted.
666671
for (const CFGBlock *B : *analysisContext.getCFG()) {
667-
668672
llvm::errs() << "\n[ B" << B->getBlockID()
669673
<< " (live expressions at block exit) ]\n";
670-
for (const Expr *E : blocksEndToLiveness[B].liveExprs) {
674+
std::vector<const Expr *> LiveExprs;
675+
llvm::append_range(LiveExprs, blocksEndToLiveness[B].liveExprs);
676+
llvm::sort(LiveExprs, ByIDs);
677+
for (const Expr *E : LiveExprs) {
671678
llvm::errs() << "\n";
672679
E->dump();
673680
}

clang/test/Analysis/live-stmts.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ int testThatDumperWorks(int x, int y, int z) {
4444
// CHECK-NEXT: ImplicitCastExpr {{.*}} <IntegralToBoolean>
4545
// CHECK-NEXT: `-ImplicitCastExpr {{.*}} <LValueToRValue>
4646
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'x' 'int'
47+
// CHECK-EMPTY:
48+
// CHECK-EMPTY:
4749
// CHECK: [ B4 (live expressions at block exit) ]
4850
// CHECK-EMPTY:
4951
// CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'

0 commit comments

Comments
 (0)