gnu/gcc/5e7fa6dbae546cdc07857be19cf3aa2375e9edad c++: Fix ICE during explanation of failed __has_unique_object_representation [PR126867]
The following testcase ICEs since r16-5520 added explain
arguments to type_has_unique_obj_representations and
record_has_unique_obj_representations. Most of the location_t
arguments in that change look correct, either DECL_SOURCE_LOCATION
of some FIELD_DECL or in type_has_unique_obj_representations use
loc, which is initialized to
location_t loc = input_location;
if (tree m = TYPE_MAIN_DECL (t))
loc = DECL_SOURCE_LOCATION (m);
But in record_has_unique_obj_representations we don't have
a variable like that and t at that point is the RECORD_TYPE
or UNION_TYPE, so using DECL_SOURCE_LOCATION on it will surely ICE
in a checking compiler.
location_of call does the above dances, so it seems easiest to
call it rather than duplicate it by hand.
2026-08-18 Jakub Jelinek <jakub@redhat.com>
PR c++/126867
* tree.cc (record_has_unique_obj_representations): Use
location_of (const_cast <tree> (t)) rather than
DECL_SOURCE_LOCATION (t).
* g++.dg/cpp1z/has-unique-obj-representations6.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 318e6a4640420d5cc213df779bf751485fa56063)
2 files changed