https://github.com/JOE1994 created https://github.com/llvm/llvm-project/pull/90625
First round of Sema checks were run at initial parsing step. Creating a new BinaryOperator instance (with the re-built LHS or RHS) will trigger another round of Sema checks, which can lead to duplicate diagnostic warning messages. All we want here is to replace the LHS or RHS with a NonOdrUse version. Don't create a new BinaryOperator, but simply replace the LHS or RHS of the given BinaryOperator. Fixes #45783 >From 24eb4db70e296d6454bac4c84a5bbc47e638876f Mon Sep 17 00:00:00 2001 From: Youngsuk Kim <[email protected]> Date: Tue, 30 Apr 2024 11:18:15 -0500 Subject: [PATCH] [clang][Sema] Re-use existing BinaryOperator if possible First round of Sema checks were run at initial parsing step. Creating a new BinaryOperator instance (with the re-built LHS or RHS) will trigger another round of Sema checks, which can lead to duplicate diagnostic warning messages. All we want here is to replace the LHS or RHS with a NonOdrUse version. Don't create a new BinaryOperator, but simply replace the LHS or RHS of the given BinaryOperator. Fixes #45783 --- clang/lib/Sema/SemaExpr.cpp | 7 +++---- clang/test/CXX/drs/dr7xx.cpp | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 50f92c496a539a..27733cd857d964 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -19707,18 +19707,17 @@ static ExprResult rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E, ExprResult Sub = Rebuild(LHS); if (!Sub.isUsable()) return Sub; - LHS = Sub.get(); + BO->setLHS(Sub.get()); // -- If e is a comma expression, ... } else if (BO->getOpcode() == BO_Comma) { ExprResult Sub = Rebuild(RHS); if (!Sub.isUsable()) return Sub; - RHS = Sub.get(); + BO->setRHS(Sub.get()); } else { break; } - return S.BuildBinOp(nullptr, BO->getOperatorLoc(), BO->getOpcode(), - LHS, RHS); + return ExprResult(BO); } // -- If e has the form (e1)... diff --git a/clang/test/CXX/drs/dr7xx.cpp b/clang/test/CXX/drs/dr7xx.cpp index 69ee6d6d4e6ae0..0300dae08d6d31 100644 --- a/clang/test/CXX/drs/dr7xx.cpp +++ b/clang/test/CXX/drs/dr7xx.cpp @@ -28,10 +28,8 @@ namespace cwg712 { // cwg712: partial use(a); use((a)); use(cond ? a : a); - // FIXME: should only warn once use((cond, a)); // expected-warning@-1 {{left operand of comma operator has no effect}} - // expected-warning@-2 {{left operand of comma operator has no effect}} (void)a; // expected-error@-1 {{reference to local variable 'a' declared in enclosing function 'cwg712::f'}} FIXME _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
