https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85020
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the following is a better fix, the comment already explains how this is
wrong to do early.
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c (revision 258720)
+++ gcc/dwarf2out.c (working copy)
@@ -19878,6 +19878,7 @@ rtl_for_decl_location (tree decl)
in the current CU, resolve_addr will remove the expression referencing
it. */
if (rtl == NULL_RTX
+ && !early_dwarf
&& VAR_P (decl)
&& !DECL_EXTERNAL (decl)
&& TREE_STATIC (decl)
note for the specific case in the testcase this ends up without a location
because the context of the "location" is the TU (and current_function_decl
is NULL) so we fail
rtl = rtl_for_decl_location (loc);
if (rtl == NULL_RTX)
{
if (TREE_CODE (loc) != FUNCTION_DECL
&& early_dwarf
&& current_function_decl
&& want_address != 1
&& ! DECL_IGNORED_P (loc)
&& (INTEGRAL_TYPE_P (TREE_TYPE (loc))
|| POINTER_TYPE_P (TREE_TYPE (loc)))
&& DECL_CONTEXT (loc) == current_function_decl
&& (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc)))
<= DWARF2_ADDR_SIZE))
{
I guess the intent of the check was
(!decl_function_context (loc)
|| decl_function_context (loc) == current_function_decl)
so with additionally having
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c (revision 258720)
+++ gcc/dwarf2out.c (working copy)
@@ -18204,14 +18204,15 @@ loc_list_from_tree_1 (tree loc, int want
rtl = rtl_for_decl_location (loc);
if (rtl == NULL_RTX)
{
+ tree fn_ctx;
if (TREE_CODE (loc) != FUNCTION_DECL
&& early_dwarf
- && current_function_decl
&& want_address != 1
&& ! DECL_IGNORED_P (loc)
&& (INTEGRAL_TYPE_P (TREE_TYPE (loc))
|| POINTER_TYPE_P (TREE_TYPE (loc)))
- && DECL_CONTEXT (loc) == current_function_decl
+ && (!(fn_ctx = decl_function_context (loc))
+ || fn_ctx == current_function_decl)
&& (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc)))
<= DWARF2_ADDR_SIZE))
{
I get a location for this.
At this point it's probably better to instead guard with
!(early_dwarf && (flag_generate_lto || flag_generate_offload))
to not risk debug degradation for others. The 2nd change is optional
(preserve some debug), not sure if we should do that right now.