From: Jakub Jelinek Date: Thu, 2 Mar 2023 18:17:52 +0000 (+0100) Subject: c++, debug: Fix up locus of DW_TAG_imported_module [PR108716] X-Git-Tag: releases/gcc-10.5.0~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17ea4d1f5d3609ef2540a10c29f57c0bd185ba4b;p=thirdparty%2Fgcc.git c++, debug: Fix up locus of DW_TAG_imported_module [PR108716] Before IMPORTED_DECL has been introduced in PR37410, we used to emit correct DW_AT_decl_line on DW_TAG_imported_module on the testcase below, after that change we haven't emitted it at all for a while and after some time started emitting incorrect locus, in particular the location of } closing the function. The problem is that while we have correct EXPR_LOCATION on the USING_STMT, when genericizing that USING_STMT into IMPORTED_DECL we don't copy the location to DECL_SOURCE_LOCATION, so it gets whatever input_location happens to be when it is created. 2023-03-02 Jakub Jelinek PR debug/108716 * cp-gimplify.c (cp_genericize_r) : Set DECL_SOURCE_LOCATION on IMPORTED_DECL to expression location of USING_STMT or input_location. * g++.dg/debug/dwarf2/pr108716.C: New test. (cherry picked from commit 4d82022bfd15d36717bf60a11e75e9ea02204269) --- diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 7f94796ea010..6432e82fdead 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1590,6 +1590,8 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) { tree using_directive = make_node (IMPORTED_DECL); TREE_TYPE (using_directive) = void_type_node; + DECL_SOURCE_LOCATION (using_directive) + = cp_expr_loc_or_input_loc (stmt); IMPORTED_DECL_ASSOCIATED_DECL (using_directive) = decl; DECL_CHAIN (using_directive) = BLOCK_VARS (block); diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/pr108716.C b/gcc/testsuite/g++.dg/debug/dwarf2/pr108716.C new file mode 100644 index 000000000000..59ed52424dae --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/pr108716.C @@ -0,0 +1,14 @@ +// PR debug/108716 +// { dg-options "-O0 -gdwarf-5 -dA -fno-merge-debug-strings" } +// { dg-final { scan-assembler "DIE \\(\[^\n\r\]*\\) DW_TAG_imported_module\[^\n\r\]*\[\n\r]*\[^\n\r\]* DW_AT_decl_file\[^\n\r\]*\[\n\r]*\[^\n\r\]*0xc\[^\n\r\]* DW_AT_decl_line\[^\n\r\]*\[\n\r]*(\[^\n\r\]*0x13\[^\n\r\]* DW_AT_decl_column\[^\n\r\]*\[\n\r]*)?" } } + +namespace M { + int x = 1; +} + +int +main () +{ + using namespace M; + return 0; +}