From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id F3928384DFA0; Mon, 11 Apr 2022 15:21:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3928384DFA0 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8085] c++: Set loc on call even if result is discarded X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/heads/master X-Git-Oldrev: 4132f6ba9583e128a00d55961ae8c8e7245b2223 X-Git-Newrev: 396a013a5857f85d878993eda32fb2df689bb8e8 Message-Id: <20220411152108.F3928384DFA0@sourceware.org> Date: Mon, 11 Apr 2022 15:21:08 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Apr 2022 15:21:09 -0000 https://gcc.gnu.org/g:396a013a5857f85d878993eda32fb2df689bb8e8 commit r12-8085-g396a013a5857f85d878993eda32fb2df689bb8e8 Author: Alexandre Oliva Date: Mon Apr 11 12:11:08 2022 -0300 c++: Set loc on call even if result is discarded This patch fixes a divergence in line numbers in diagnostics and, presumably, debug information, between targets whose cdtors return this and those that don't. The problem was visible in g++.dg/cpp2a/constexpr-dtor3.C: while the dtor call in the cleanup for f4 was expected at the closing brace, on returning-this targets it came up at the assignment. The reason is convoluted: statements in cleanups have their location information removed, to avoid bumpy debugger behavior, and then set to the location of the end of the scope. The cleanup dtor call has its locus cleared in both kinds of targets, but the end-of-scope locus doesn't make it on returning-this targets. The calls are wrapped with a cast-to-void to discard the unused return value, and the existing logic only attached the locus to the conversion NOP_EXPR. The call thus remains locus-less. When constexpr logic copies and evals the body, it sets unset locations; while copying cleanups, the locus is taken from the cleanup expression, rather than matching the end-of-scope locus set by the parser. So we end up with different locations. This patch sets the locus of the call even when it's wrapped by a convert-to-void NOP_EXPR, so it won't diverge any more. for gcc/cp/ChangeLog * semantics.cc (set_cleanup_locs): Propagate locus to call wrapped in cast-to-void. Diff: --- gcc/cp/semantics.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index a7f6449dafd..43627ed30af 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -609,7 +609,17 @@ set_cleanup_locs (tree stmts, location_t loc) { if (TREE_CODE (stmts) == CLEANUP_STMT) { - protected_set_expr_location (CLEANUP_EXPR (stmts), loc); + tree t = CLEANUP_EXPR (stmts); + protected_set_expr_location (t, loc); + /* Avoid locus differences for C++ cdtor calls depending on whether + cdtor_returns_this: a conversion to void is added to discard the return + value, and this conversion ends up carrying the location, and when it + gets discarded, the location is lost. So hold it in the call as + well. */ + if (TREE_CODE (t) == NOP_EXPR + && TREE_TYPE (t) == void_type_node + && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR) + protected_set_expr_location (TREE_OPERAND (t, 0), loc); set_cleanup_locs (CLEANUP_BODY (stmts), loc); } else if (TREE_CODE (stmts) == STATEMENT_LIST)