https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77427

--- Comment #7 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #4)
> This fixes the ICE:
> ...
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 4531647..f13790f 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -10551,6 +10551,8 @@ ix86_build_builtin_va_list_64 (void)
>    TYPE_ATTRIBUTES (record) = tree_cons (get_identifier ("sysv_abi va_list"),
>                                         NULL_TREE, TYPE_ATTRIBUTES (record));
>  
> +  SET_TYPE_STRUCTURAL_EQUALITY (record);
> +
>    /* The correct type is an array type of one element.  */
>    return build_array_type (record, build_index_type (size_zero_node));
>  }
> ...

But causes regressions in bootstrap and reg-test:
...
+./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/other/vararg-4.C  -std=c++11 (test
for excess errors)
+./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/other/vararg-4.C  -std=c++14 (test
for excess errors)
+./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/other/vararg-4.C  -std=c++98 (test
for excess errors)
+./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/warn/Wunused-parm-3.C  -std=gnu++11
(test for excess errors)
+./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/warn/Wunused-parm-3.C  -std=gnu++14
(test for excess errors)
+./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/warn/Wunused-parm-3.C  -std=gnu++98
(test for excess errors)
...

Minimal version of Wunused-parm-3.C failure:
...
template <typename T>
int
fn7 (T ap)
{
  return __builtin_va_arg(ap, int);
}

int
fn8 (__builtin_va_list ap)
{
  return fn7<__builtin_va_list> (ap);
}
...

The test fails because there's an additional warning:
...
Wunused-parm-3.C: In function ‘int fn8(__va_list_tag*)’:
Wunused-parm-3.C:11:36: warning: ignoring attributes applied to ‘__va_list_tag’
after definition [-Wattributes]
   return fn7<__builtin_va_list> (ap);
...

Adding a main:
...
#ifdef MAIN
int
fn9 (int dummy, ...)
{
  __builtin_va_list ap;
  __builtin_va_start (ap, dummy);
  int res = fn8 (ap);
  __builtin_va_end (ap);
  return res;
}

int
main (void)
{
  int res = fn9 (0, 3);

  return !(res == 3);
}
#endif
...

shows that generated code is still ok:
...
$ g++ Wunused-parm-3.C -DMAIN && (./a.out ; echo $? )
Wunused-parm-3.C: In function ‘int fn8(__va_list_tag*)’:
Wunused-parm-3.C:11:36: warning: ignoring attributes applied to ‘__va_list_tag’
after definition [-Wattributes]
   return fn7<__builtin_va_list> (ap);
                                    ^
0
...

The warning is there because canonicalize_type_argument tries to build a copy
of va_list without the attribute (which it tries to do because the condition
arg == TYPE_CANONICAL (arg) no longer holds):

Reply via email to