[clang] Extend life of variables in `DiagComparison` in `ExprConstant` (PR #79522)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 26 11:37:49 PST 2024


================
@@ -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;
----------------
AdvenamTacet wrote:

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.

https://github.com/llvm/llvm-project/pull/79522


More information about the cfe-commits mailing list