Re: [patch, fortran] Mark variables in references for variable definition context as used.

Mikael Morin <[email protected]> Thu, 18 Jun 2026 18:36:42 +0200
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Hello,

Le 13/06/2026 à 11:36, Thomas Koenig a écrit :
> index c2dd42840b5..2ce7e000a05 100644
> --- a/gcc/fortran/symbol.cc
> +++ b/gcc/fortran/symbol.cc
> @@ -5918,3 +5920,28 @@ bool gfc_lvalue_allocated_at (gfc_symbol *sym, locus *loc)
>    sym->attr.allocated = 1;
>    return true;
>  }
> +
> +/* Mark the variable of an expression in a vardef context as
> +   set and mark everything in the references as used.  */
> +
> +void
> +gfc_expr_set_at (gfc_expr *expr, locus *loc, enum value_set how_set)
> +{
> +  enum value_used prev_used;
> +  gfc_symbol *sym;
> +  locus prev_loc;
> +
> +  if (!expr)
> +    return;
> +
> +  if (expr->expr_type != EXPR_VARIABLE)
> +    return;
Don't you need to call gfc_value_used_expr in all cases, including for 
non-variables?  If I'm understanding well, we are in invalid code 
territory here, but avoiding a cascade of uninitialized diagnostics 
remains worth pursuing?

> +
> +  sym = expr->symtree->n.sym;
> +  gfc_value_set_at (sym, loc, how_set);
> +  prev_used = sym->attr.value_used;
> +  prev_loc = sym->other_loc;
> +  gfc_value_used_expr (expr, VALUE_USED);
> +  sym->other_loc = prev_loc;
> +  sym->attr.value_used = prev_used;
> +}
No other comment, the rest looks good.