diff mbox series

[C++] PR c++/93299 - ICE in tsubst_copy with parenthesized expression.

Message ID 20200117210309.808128-1-polacek@redhat.com
State New
Headers show
Series [C++] PR c++/93299 - ICE in tsubst_copy with parenthesized expression. | expand

Commit Message

Marek Polacek Jan. 17, 2020, 9:03 p.m. UTC
Since e4511ca2e9ecdb51d41b64452398f8e2df575668 force_paren_expr can create
a VIEW_CONVERT_EXPR so that we have something to set REF_PARENTHESIZED_P
on, while not making the expression dependent.  But tsubst_copy can't cope
with such a VIEW_CONVERT_EXPR, because it's not location_wrapper_p, or
a TEMPLATE_PARM_INDEX wrapped in a VIEW_CONVERT_EXPR.

I think we need to teach tsubst_copy how to handle it.  Setting
EXPR_LOCATION_WRAPPER_P in force_paren_expr would make the ICE go away
too, but tsubst_copy would lose the REF_PARENTHESIZED_P flag.

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

	* pt.c (tsubst_copy): Handle a REF_PARENTHESIZED_P VIEW_CONVERT_EXPR.

	* g++.dg/cpp1y/paren5.C: New test.
---
 gcc/cp/pt.c                         |  8 ++++++++
 gcc/testsuite/g++.dg/cpp1y/paren5.C | 12 ++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/paren5.C


base-commit: 6687d13a87c42dddc7d1c7adade38d31ba0d1401

Comments

Marek Polacek Jan. 24, 2020, 3:36 p.m. UTC | #1
Ping.

On Fri, Jan 17, 2020 at 04:03:09PM -0500, Marek Polacek wrote:
> Since e4511ca2e9ecdb51d41b64452398f8e2df575668 force_paren_expr can create
> a VIEW_CONVERT_EXPR so that we have something to set REF_PARENTHESIZED_P
> on, while not making the expression dependent.  But tsubst_copy can't cope
> with such a VIEW_CONVERT_EXPR, because it's not location_wrapper_p, or
> a TEMPLATE_PARM_INDEX wrapped in a VIEW_CONVERT_EXPR.
> 
> I think we need to teach tsubst_copy how to handle it.  Setting
> EXPR_LOCATION_WRAPPER_P in force_paren_expr would make the ICE go away
> too, but tsubst_copy would lose the REF_PARENTHESIZED_P flag.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk and 9?
> 
> 	* pt.c (tsubst_copy): Handle a REF_PARENTHESIZED_P VIEW_CONVERT_EXPR.
> 
> 	* g++.dg/cpp1y/paren5.C: New test.
> ---
>  gcc/cp/pt.c                         |  8 ++++++++
>  gcc/testsuite/g++.dg/cpp1y/paren5.C | 12 ++++++++++++
>  2 files changed, 20 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/paren5.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 1b3d07b1a52..5d3d127e528 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -16423,6 +16423,14 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>  		  return op;
>  		}
>  	    }
> +	  /* force_paren_expr can also create a VIEW_CONVERT_EXPR.  */
> +	  else if (code == VIEW_CONVERT_EXPR && REF_PARENTHESIZED_P (t))
> +	    {
> +	      op = tsubst_copy (op, args, complain, in_decl);
> +	      op = build1 (code, TREE_TYPE (op), op);
> +	      REF_PARENTHESIZED_P (op) = true;
> +	      return op;
> +	    }
>  	  /* We shouldn't see any other uses of these in templates.  */
>  	  gcc_unreachable ();
>  	}
> diff --git a/gcc/testsuite/g++.dg/cpp1y/paren5.C b/gcc/testsuite/g++.dg/cpp1y/paren5.C
> new file mode 100644
> index 00000000000..86a51356465
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/paren5.C
> @@ -0,0 +1,12 @@
> +// PR c++/93299 - ICE in tsubst_copy with parenthesized expression.
> +// { dg-do compile { target c++14 } }
> +
> +template <typename> struct A {
> +  enum { b = 8 };
> +};
> +
> +template <int> struct __attribute__((aligned((A<int>::b)))) D { };
> +struct S : D<0> { };
> +
> +template <int N> struct __attribute__((aligned((A<int>::b) + N))) D2 { };
> +struct S2 : D2<0> { };
> 
> base-commit: 6687d13a87c42dddc7d1c7adade38d31ba0d1401
> -- 
> 2.24.1
> 

Marek
Jason Merrill Jan. 24, 2020, 5:09 p.m. UTC | #2
On 1/17/20 4:03 PM, Marek Polacek wrote:
> Since e4511ca2e9ecdb51d41b64452398f8e2df575668 force_paren_expr can create
> a VIEW_CONVERT_EXPR so that we have something to set REF_PARENTHESIZED_P
> on, while not making the expression dependent.  But tsubst_copy can't cope
> with such a VIEW_CONVERT_EXPR, because it's not location_wrapper_p, or
> a TEMPLATE_PARM_INDEX wrapped in a VIEW_CONVERT_EXPR.
> 
> I think we need to teach tsubst_copy how to handle it.  Setting
> EXPR_LOCATION_WRAPPER_P in force_paren_expr would make the ICE go away
> too, but tsubst_copy would lose the REF_PARENTHESIZED_P flag.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk and 9?
> 
> 	* pt.c (tsubst_copy): Handle a REF_PARENTHESIZED_P VIEW_CONVERT_EXPR.

OK.

> 	* g++.dg/cpp1y/paren5.C: New test.
> ---
>   gcc/cp/pt.c                         |  8 ++++++++
>   gcc/testsuite/g++.dg/cpp1y/paren5.C | 12 ++++++++++++
>   2 files changed, 20 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp1y/paren5.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 1b3d07b1a52..5d3d127e528 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -16423,6 +16423,14 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>   		  return op;
>   		}
>   	    }
> +	  /* force_paren_expr can also create a VIEW_CONVERT_EXPR.  */
> +	  else if (code == VIEW_CONVERT_EXPR && REF_PARENTHESIZED_P (t))
> +	    {
> +	      op = tsubst_copy (op, args, complain, in_decl);
> +	      op = build1 (code, TREE_TYPE (op), op);
> +	      REF_PARENTHESIZED_P (op) = true;
> +	      return op;
> +	    }
>   	  /* We shouldn't see any other uses of these in templates.  */
>   	  gcc_unreachable ();
>   	}
> diff --git a/gcc/testsuite/g++.dg/cpp1y/paren5.C b/gcc/testsuite/g++.dg/cpp1y/paren5.C
> new file mode 100644
> index 00000000000..86a51356465
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/paren5.C
> @@ -0,0 +1,12 @@
> +// PR c++/93299 - ICE in tsubst_copy with parenthesized expression.
> +// { dg-do compile { target c++14 } }
> +
> +template <typename> struct A {
> +  enum { b = 8 };
> +};
> +
> +template <int> struct __attribute__((aligned((A<int>::b)))) D { };
> +struct S : D<0> { };
> +
> +template <int N> struct __attribute__((aligned((A<int>::b) + N))) D2 { };
> +struct S2 : D2<0> { };
> 
> base-commit: 6687d13a87c42dddc7d1c7adade38d31ba0d1401
>
diff mbox series

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1b3d07b1a52..5d3d127e528 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -16423,6 +16423,14 @@  tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 		  return op;
 		}
 	    }
+	  /* force_paren_expr can also create a VIEW_CONVERT_EXPR.  */
+	  else if (code == VIEW_CONVERT_EXPR && REF_PARENTHESIZED_P (t))
+	    {
+	      op = tsubst_copy (op, args, complain, in_decl);
+	      op = build1 (code, TREE_TYPE (op), op);
+	      REF_PARENTHESIZED_P (op) = true;
+	      return op;
+	    }
 	  /* We shouldn't see any other uses of these in templates.  */
 	  gcc_unreachable ();
 	}
diff --git a/gcc/testsuite/g++.dg/cpp1y/paren5.C b/gcc/testsuite/g++.dg/cpp1y/paren5.C
new file mode 100644
index 00000000000..86a51356465
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/paren5.C
@@ -0,0 +1,12 @@ 
+// PR c++/93299 - ICE in tsubst_copy with parenthesized expression.
+// { dg-do compile { target c++14 } }
+
+template <typename> struct A {
+  enum { b = 8 };
+};
+
+template <int> struct __attribute__((aligned((A<int>::b)))) D { };
+struct S : D<0> { };
+
+template <int N> struct __attribute__((aligned((A<int>::b) + N))) D2 { };
+struct S2 : D2<0> { };