public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/91877 - ICE with converting member of packed struct.
@ 2019-09-24 15:17 Marek Polacek
  2019-09-25  4:28 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2019-09-24 15:17 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

This started to ICE with my CWG 2352 fix.  In reference_binding, we now bind
directly when the types are similar, not just when they are the same.  But even
direct binding can involve a temporary, e.g. for a bit-field, or, as in this
test, for a packed field.

convert_like will actually create the temporary, but we were triggering the
assert checking that the types are the same.  Now they don't have to be, so
adjust the assert accordingly.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-09-24  Marek Polacek  <polacek@redhat.com>

	PR c++/91877 - ICE with converting member of packed struct.
	* call.c (convert_like_real): Use similar_type_p in an assert.

	* g++.dg/conversion/packed1.C: New test.

diff --git gcc/cp/call.c gcc/cp/call.c
index 77f10a9f5f1..45b984ecb11 100644
--- gcc/cp/call.c
+++ gcc/cp/call.c
@@ -7382,8 +7382,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 	    tree type = TREE_TYPE (ref_type);
 	    cp_lvalue_kind lvalue = lvalue_kind (expr);
 
-	    gcc_assert (same_type_ignoring_top_level_qualifiers_p
-			(type, next_conversion (convs)->type));
+	    gcc_assert (similar_type_p (type, next_conversion (convs)->type));
 	    if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
 		&& !TYPE_REF_IS_RVALUE (ref_type))
 	      {
diff --git gcc/testsuite/g++.dg/conversion/packed1.C gcc/testsuite/g++.dg/conversion/packed1.C
new file mode 100644
index 00000000000..c4be930bc19
--- /dev/null
+++ gcc/testsuite/g++.dg/conversion/packed1.C
@@ -0,0 +1,12 @@
+// PR c++/91877 - ICE with converting member of packed struct.
+// { dg-do compile { target c++11 } }
+// { dg-options "-fpack-struct" }
+
+template <typename a> class b {
+public:
+  b(const a &);
+};
+struct {
+  int *c;
+} d;
+void e() { b<const int *>(d.c); }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: C++ PATCH for c++/91877 - ICE with converting member of packed struct.
  2019-09-24 15:17 C++ PATCH for c++/91877 - ICE with converting member of packed struct Marek Polacek
@ 2019-09-25  4:28 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-09-25  4:28 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 9/24/19 11:17 AM, Marek Polacek wrote:
> This started to ICE with my CWG 2352 fix.  In reference_binding, we now bind
> directly when the types are similar, not just when they are the same.  But even
> direct binding can involve a temporary, e.g. for a bit-field, or, as in this
> test, for a packed field.

Well, if there's a temporary, it isn't direct binding.

> convert_like will actually create the temporary, but we were triggering the
> assert checking that the types are the same.  Now they don't have to be, so
> adjust the assert accordingly.

Previously we could have gotten a derived class, but we would have a 
ck_base to make the assert succeed.  Do we want a ck_qual under the 
ck_ref_bind?  It isn't necessary for adjustment, but might be helpful 
for conversion sequence ranking (which seems to be missing some standard 
wording).  On the other hand, it might be too much trouble making things 
understand ck_ref_bind around ck_qual, and compare_ics can probably do 
just fine without.

The patch is OK, but please add some testcases for overload resolution 
with more and less-qualified similar types.

> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2019-09-24  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/91877 - ICE with converting member of packed struct.
> 	* call.c (convert_like_real): Use similar_type_p in an assert.
> 
> 	* g++.dg/conversion/packed1.C: New test.
> 
> diff --git gcc/cp/call.c gcc/cp/call.c
> index 77f10a9f5f1..45b984ecb11 100644
> --- gcc/cp/call.c
> +++ gcc/cp/call.c
> @@ -7382,8 +7382,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
>   	    tree type = TREE_TYPE (ref_type);
>   	    cp_lvalue_kind lvalue = lvalue_kind (expr);
>   
> -	    gcc_assert (same_type_ignoring_top_level_qualifiers_p
> -			(type, next_conversion (convs)->type));
> +	    gcc_assert (similar_type_p (type, next_conversion (convs)->type));
>   	    if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
>   		&& !TYPE_REF_IS_RVALUE (ref_type))
>   	      {
> diff --git gcc/testsuite/g++.dg/conversion/packed1.C gcc/testsuite/g++.dg/conversion/packed1.C
> new file mode 100644
> index 00000000000..c4be930bc19
> --- /dev/null
> +++ gcc/testsuite/g++.dg/conversion/packed1.C
> @@ -0,0 +1,12 @@
> +// PR c++/91877 - ICE with converting member of packed struct.
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-fpack-struct" }
> +
> +template <typename a> class b {
> +public:
> +  b(const a &);
> +};
> +struct {
> +  int *c;
> +} d;
> +void e() { b<const int *>(d.c); }
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-09-25  4:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24 15:17 C++ PATCH for c++/91877 - ICE with converting member of packed struct Marek Polacek
2019-09-25  4:28 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).