On Wed, Nov 9, 2016 at 7:24 AM, Jakub Jelinek <ja...@redhat.com> wrote: > The match.pd hunk is needed, otherwise the generic folding happily folds > int arr[2]; > ... > auto [ x, y ] = arr; > &x == &arr[0] > into 0, because it thinks x and arr are distinct VAR_DECLs. Though, if > such comparisons are required to be folded in constexpr contexts under > certain conditions, we'd need to handle the DECL_VALUE_EXPRs in constexpr.c > somehow.
What do you think of this approach instead?
commit 7aa4bc14bdd8f01937ce2dc148722f0468d66d1b Author: Jason Merrill <ja...@redhat.com> Date: Sun Nov 13 19:17:40 2016 -0500 addr_base diff --git a/gcc/match.pd b/gcc/match.pd index 79a418f..29ddcd8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2547,15 +2547,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (with { int equal = 2; - /* Punt in GENERIC on variables with value expressions; - the value expressions might point to fields/elements - of other vars etc. */ - if (GENERIC - && ((VAR_P (base0) && DECL_HAS_VALUE_EXPR_P (base0)) - || (VAR_P (base1) && DECL_HAS_VALUE_EXPR_P (base1)))) - ; - else if (decl_in_symtab_p (base0) - && decl_in_symtab_p (base1)) + if (decl_in_symtab_p (base0) + && decl_in_symtab_p (base1)) equal = symtab_node::get_create (base0) ->equal_address_to (symtab_node::get_create (base1)); else if ((DECL_P (base0) diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c index 0396feb..0a8523b 100644 --- a/gcc/tree-dfa.c +++ b/gcc/tree-dfa.c @@ -673,6 +673,15 @@ get_addr_base_and_unit_offset_1 (tree exp, HOST_WIDE_INT *poffset, { switch (TREE_CODE (exp)) { + case VAR_DECL: + if (DECL_HAS_VALUE_EXPR_P (exp)) + { + exp = DECL_VALUE_EXPR (exp); + continue; + } + else + goto done; + case BIT_FIELD_REF: { HOST_WIDE_INT this_off = TREE_INT_CST_LOW (TREE_OPERAND (exp, 2));