PR100281 C++: Fix SImode pointer handling
commit720dff974ea0487c35c0a4bfa527f30df5066ce1
authorAndreas Krebbel <krebbel@linux.ibm.com>
Tue, 27 Apr 2021 08:09:06 +0000 (27 10:09 +0200)
committerAndreas Krebbel <krebbel@linux.ibm.com>
Tue, 18 May 2021 06:45:09 +0000 (18 08:45 +0200)
tree6e1d3a36cc316a3e0b24f651fa8903f570da7bde
parentfe993b469c528230d9a01e1ae2208610f960dd9f
PR100281 C++: Fix SImode pointer handling

The problem appears to be triggered by two locations in the front-end
where non-POINTER_SIZE pointers aren't handled right now.

1. An assertion in strip_typedefs is triggered because the alignment
of the types don't match. This in turn is caused by creating the new
type with build_pointer_type instead of taking the type of the
original pointer into account.

2. An assertion in cp_convert_to_pointer is triggered which expects
the target type to always have POINTER_SIZE.

gcc/cp/ChangeLog:

PR c++/100281
* cvt.c (cp_convert_to_pointer): Use the size of the target
pointer type.
* tree.c (cp_build_reference_type): Call
cp_build_reference_type_for_mode with VOIDmode.
(cp_build_reference_type_for_mode): Rename from
cp_build_reference_type.  Add MODE argument and invoke
build_reference_type_for_mode.
(strip_typedefs): Use build_pointer_type_for_mode and
cp_build_reference_type_for_mode for pointers and references.

gcc/ChangeLog:

PR c++/100281
* tree.c (build_reference_type_for_mode)
(build_pointer_type_for_mode): Pick pointer mode if MODE argument
is VOIDmode.
(build_reference_type, build_pointer_type): Invoke
build_*_type_for_mode with VOIDmode.

gcc/testsuite/ChangeLog:

PR c++/100281
* g++.target/s390/pr100281-1.C: New test.
* g++.target/s390/pr100281-2.C: New test.
gcc/cp/cvt.c
gcc/cp/tree.c
gcc/testsuite/g++.target/s390/pr100281-1.C [new file with mode: 0644]
gcc/testsuite/g++.target/s390/pr100281-2.C [new file with mode: 0644]
gcc/tree.c