* [PATCH] c++: Fix up mangling ICE with void{} [PR106863]
@ 2022-10-19 8:00 Jakub Jelinek
2022-10-20 14:19 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2022-10-19 8:00 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
We ICE on the following testcase during mangling, finish_compound_literal
returns for void{} void_node and the mangler doesn't handle it.
Handling void_node in the mangler seems problematic to me, because
we don't know for which case it has been created.
The following patch arranges to mangle just void{} the same as void()
if that is what we want to use, by doing what we do for void() when
processing void{}.
The code does that only if processing_template_decl, because otherwise
build_functional_cast will return void_node, so calling it looks like
wasted effort to me. But if you want to call it unconditionally,
I can certainly do that too.
Or do you want to mangle it differently? How?
clang++ doesn't support DR2351, so I can't check what they are doing.
Bootstrapped/regtested on x86_64-linux and i686-linux.
2022-10-19 Jakub Jelinek <jakub@redhat.com>
PR c++/106863
* semantics.cc (finish_compound_literal): For void{}, if
processing_template_decl return build_functional_cast of NULL_TREE
to VOID_TYPE rather than void_node.
* g++.dg/cpp0x/dr2351-2.C: New test.
--- gcc/cp/semantics.cc.jj 2022-10-10 09:31:57.410985121 +0200
+++ gcc/cp/semantics.cc 2022-10-18 15:24:08.726026118 +0200
@@ -3164,7 +3164,12 @@ finish_compound_literal (tree type, tree
{
/* DR2351 */
if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
- return void_node;
+ {
+ if (!processing_template_decl)
+ return void_node;
+ location_t loc = cp_expr_loc_or_input_loc (compound_literal);
+ return build_functional_cast (loc, type, NULL_TREE, complain);
+ }
else if (VOID_TYPE_P (type)
&& processing_template_decl
&& maybe_zero_constructor_nelts (compound_literal))
--- gcc/testsuite/g++.dg/cpp0x/dr2351-2.C.jj 2022-10-18 15:27:01.146690132 +0200
+++ gcc/testsuite/g++.dg/cpp0x/dr2351-2.C 2022-10-18 15:27:39.909164970 +0200
@@ -0,0 +1,16 @@
+// DR2351
+// { dg-do compile { target c++11 } }
+
+void bar (int);
+
+template <typename T>
+auto foo (T t) -> decltype (bar (t), void{})
+{
+ return bar (t);
+}
+
+int
+main ()
+{
+ foo (0);
+}
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: Fix up mangling ICE with void{} [PR106863]
2022-10-19 8:00 [PATCH] c++: Fix up mangling ICE with void{} [PR106863] Jakub Jelinek
@ 2022-10-20 14:19 ` Jason Merrill
2022-10-20 14:38 ` [PATCH] c++, v2: " Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2022-10-20 14:19 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 10/19/22 04:00, Jakub Jelinek wrote:
> Hi!
>
> We ICE on the following testcase during mangling, finish_compound_literal
> returns for void{} void_node and the mangler doesn't handle it.
> Handling void_node in the mangler seems problematic to me, because
> we don't know for which case it has been created.
> The following patch arranges to mangle just void{} the same as void()
> if that is what we want to use, by doing what we do for void() when
> processing void{}.
> The code does that only if processing_template_decl, because otherwise
> build_functional_cast will return void_node, so calling it looks like
> wasted effort to me. But if you want to call it unconditionally,
> I can certainly do that too.
I think in a template we want the same early-return behavior as in the
processing_template_decl block farther down in the function:
specifically, we want to return a CONSTRUCTOR (for which
COMPOUND_LITERAL_P is true), so it mangles as void{} rather than void().
> Or do you want to mangle it differently? How?
>
> clang++ doesn't support DR2351, so I can't check what they are doing.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux.
>
> 2022-10-19 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/106863
> * semantics.cc (finish_compound_literal): For void{}, if
> processing_template_decl return build_functional_cast of NULL_TREE
> to VOID_TYPE rather than void_node.
>
> * g++.dg/cpp0x/dr2351-2.C: New test.
>
> --- gcc/cp/semantics.cc.jj 2022-10-10 09:31:57.410985121 +0200
> +++ gcc/cp/semantics.cc 2022-10-18 15:24:08.726026118 +0200
> @@ -3164,7 +3164,12 @@ finish_compound_literal (tree type, tree
> {
> /* DR2351 */
> if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
> - return void_node;
> + {
> + if (!processing_template_decl)
> + return void_node;
> + location_t loc = cp_expr_loc_or_input_loc (compound_literal);
> + return build_functional_cast (loc, type, NULL_TREE, complain);
> + }
> else if (VOID_TYPE_P (type)
> && processing_template_decl
> && maybe_zero_constructor_nelts (compound_literal))
> --- gcc/testsuite/g++.dg/cpp0x/dr2351-2.C.jj 2022-10-18 15:27:01.146690132 +0200
> +++ gcc/testsuite/g++.dg/cpp0x/dr2351-2.C 2022-10-18 15:27:39.909164970 +0200
> @@ -0,0 +1,16 @@
> +// DR2351
> +// { dg-do compile { target c++11 } }
> +
> +void bar (int);
> +
> +template <typename T>
> +auto foo (T t) -> decltype (bar (t), void{})
> +{
> + return bar (t);
> +}
> +
> +int
> +main ()
> +{
> + foo (0);
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] c++, v2: Fix up mangling ICE with void{} [PR106863]
2022-10-20 14:19 ` Jason Merrill
@ 2022-10-20 14:38 ` Jakub Jelinek
2022-10-20 14:45 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2022-10-20 14:38 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Thu, Oct 20, 2022 at 10:19:59AM -0400, Jason Merrill wrote:
> I think in a template we want the same early-return behavior as in the
> processing_template_decl block farther down in the function: specifically,
> we want to return a CONSTRUCTOR (for which COMPOUND_LITERAL_P is true), so
> it mangles as void{} rather than void().
So like this then?
2022-10-20 Jakub Jelinek <jakub@redhat.com>
PR c++/106863
* semantics.cc (finish_compound_literal): For void{}, if
processing_template_decl return a COMPOUND_LITERAL_P
CONSTRUCTOR rather than void_node.
* g++.dg/cpp0x/dr2351-2.C: New test.
--- gcc/cp/semantics.cc.jj 2022-10-19 01:14:58.343483355 +0200
+++ gcc/cp/semantics.cc 2022-10-20 16:32:30.605571968 +0200
@@ -3164,7 +3164,16 @@ finish_compound_literal (tree type, tree
{
/* DR2351 */
if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
- return void_node;
+ {
+ if (!processing_template_decl)
+ return void_node;
+ TREE_TYPE (compound_literal) = type;
+ TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
+ CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
+ if (fcl_context == fcl_c99)
+ CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
+ return compound_literal;
+ }
else if (VOID_TYPE_P (type)
&& processing_template_decl
&& maybe_zero_constructor_nelts (compound_literal))
--- gcc/testsuite/g++.dg/cpp0x/dr2351-2.C.jj 2022-10-20 16:27:19.645821706 +0200
+++ gcc/testsuite/g++.dg/cpp0x/dr2351-2.C 2022-10-20 16:27:19.645821706 +0200
@@ -0,0 +1,16 @@
+// DR2351
+// { dg-do compile { target c++11 } }
+
+void bar (int);
+
+template <typename T>
+auto foo (T t) -> decltype (bar (t), void{})
+{
+ return bar (t);
+}
+
+int
+main ()
+{
+ foo (0);
+}
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++, v2: Fix up mangling ICE with void{} [PR106863]
2022-10-20 14:38 ` [PATCH] c++, v2: " Jakub Jelinek
@ 2022-10-20 14:45 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2022-10-20 14:45 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 10/20/22 10:38, Jakub Jelinek wrote:
> On Thu, Oct 20, 2022 at 10:19:59AM -0400, Jason Merrill wrote:
>> I think in a template we want the same early-return behavior as in the
>> processing_template_decl block farther down in the function: specifically,
>> we want to return a CONSTRUCTOR (for which COMPOUND_LITERAL_P is true), so
>> it mangles as void{} rather than void().
>
> So like this then?
>
> 2022-10-20 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/106863
> * semantics.cc (finish_compound_literal): For void{}, if
> processing_template_decl return a COMPOUND_LITERAL_P
> CONSTRUCTOR rather than void_node.
>
> * g++.dg/cpp0x/dr2351-2.C: New test.
>
> --- gcc/cp/semantics.cc.jj 2022-10-19 01:14:58.343483355 +0200
> +++ gcc/cp/semantics.cc 2022-10-20 16:32:30.605571968 +0200
> @@ -3164,7 +3164,16 @@ finish_compound_literal (tree type, tree
> {
> /* DR2351 */
> if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
> - return void_node;
> + {
> + if (!processing_template_decl)
> + return void_node;
> + TREE_TYPE (compound_literal) = type;
> + TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
> + CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
> + if (fcl_context == fcl_c99)
> + CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
I don't think it's possible to get here with the C compound literal
syntax, so you can drop these two lines. OK with that change.
> + return compound_literal;
> + }
> else if (VOID_TYPE_P (type)
> && processing_template_decl
> && maybe_zero_constructor_nelts (compound_literal))
> --- gcc/testsuite/g++.dg/cpp0x/dr2351-2.C.jj 2022-10-20 16:27:19.645821706 +0200
> +++ gcc/testsuite/g++.dg/cpp0x/dr2351-2.C 2022-10-20 16:27:19.645821706 +0200
> @@ -0,0 +1,16 @@
> +// DR2351
> +// { dg-do compile { target c++11 } }
> +
> +void bar (int);
> +
> +template <typename T>
> +auto foo (T t) -> decltype (bar (t), void{})
> +{
> + return bar (t);
> +}
> +
> +int
> +main ()
> +{
> + foo (0);
> +}
>
>
> Jakub
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-20 14:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 8:00 [PATCH] c++: Fix up mangling ICE with void{} [PR106863] Jakub Jelinek
2022-10-20 14:19 ` Jason Merrill
2022-10-20 14:38 ` [PATCH] c++, v2: " Jakub Jelinek
2022-10-20 14:45 ` 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).