Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend life of variables in DiagComparison in ExprConstant #79522

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13288,9 +13288,23 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const BinaryOperator *E,
// Reject differing bases from the normal codepath; we special-case
// comparisons to null.
if (!HasSameBase(LHSValue, RHSValue)) {
auto DiagComparison = [&] (unsigned DiagID, bool Reversed = false) {
std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
auto DiagComparison = [&](unsigned DiagID, bool Reversed = false) {
static std::string LHS, RHS;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not const, how can we make them static?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not const, but we update their value every time visiting the function. Assigning value is moved to the next line, which is executed every time.

It is a workaround, but I'm unsure if a good one. (However, it solved the problem with buildbots.)
Code suggested by @cor3ntin works as well for a reason I don't understand.
It's more confusing than I initially thought.

// FIXME: To prevent the use of variables beyond their lifetime, we have
// made them static. However, this approach may not fully address the
// underlying issue. StringRef objects (made from those strings) can
// potentially change their contents unexpectedly.
// Or potentially use of freed memory may happen. Therefore, further
// investigation is required to ensure that making those variables
// static effectively resolves the problem.
// We should investigate why buildbots were failing with ASan short
// string annotations turned on. Related PR:
// https://github.com/llvm/llvm-project/pull/79049
// If making those variables static didn't fix the problem,
// please confirm that https://github.com/llvm/llvm-project/pull/79489
// fixed the real issue.
LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType());
RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType());
Info.FFDiag(E, DiagID)
<< (Reversed ? RHS : LHS) << (Reversed ? LHS : RHS);
return false;
Expand Down
Loading