public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix build_noexcept_spec ICE (PR c++/54207)
@ 2012-12-06  7:24 Jakub Jelinek
  2012-12-06 14:07 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2012-12-06  7:24 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

We ICE on the following testcase, because perform_implicit_conversion_flags
doesn't guarantee the type of the returned value is boolean_type_node,
if it is some other type compatible with it (in the same_type_p sense),
then simple == boolean_true_node and == boolean_false_node comparisons
don't really work.  Either we could fold_convert it to boolean_type_node
if INTEGER_CST first, or we can use operand_equal_p to compare instead of
pointer comparisons.  The INTEGER_CSTs checks in the patch are to avoid
calling operand_equal_p unnecessarily, but could be dropped if you prefer it
that way.

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

2012-12-06  Jakub Jelinek  <jakub@redhat.com>

	PR c++/54207
	* except.c (build_noexcept_spec): Avoid direct comparison
	with boolean_true_node or boolean_false_node, instead use
	operand_equal_p.
	* pt.c (tsubst_exception_specification): Likewise.
	* typeck2.c (merge_exception_specifiers): Likewise.

	* g++.dg/cpp0x/noexcept18.C: New test.

--- gcc/cp/except.c.jj	2012-11-19 14:41:16.000000000 +0100
+++ gcc/cp/except.c	2012-12-04 11:51:38.157724775 +0100
@@ -1316,15 +1316,18 @@ build_noexcept_spec (tree expr, int comp
 						LOOKUP_NORMAL);
       expr = cxx_constant_value (expr);
     }
-  if (expr == boolean_true_node)
-    return noexcept_true_spec;
-  else if (expr == boolean_false_node)
-    return noexcept_false_spec;
-  else if (expr == error_mark_node)
+  if (TREE_CODE (expr) == INTEGER_CST)
+    {
+      if (operand_equal_p (expr, boolean_true_node, 0))
+	return noexcept_true_spec;
+      else if (operand_equal_p (expr, boolean_false_node, 0))
+	return noexcept_false_spec;
+    }
+  if (expr == error_mark_node)
     return error_mark_node;
   else
     {
-      gcc_assert (processing_template_decl || expr == error_mark_node
+      gcc_assert (processing_template_decl
 		  || TREE_CODE (expr) == DEFERRED_NOEXCEPT);
       return build_tree_list (expr, NULL_TREE);
     }
--- gcc/cp/pt.c.jj	2012-12-01 00:50:33.000000000 +0100
+++ gcc/cp/pt.c	2012-12-04 11:53:32.007085060 +0100
@@ -10840,8 +10840,14 @@ tsubst_exception_specification (tree fnt
     {
       /* A noexcept-specifier.  */
       tree expr = TREE_PURPOSE (specs);
-      if (expr == boolean_true_node || expr == boolean_false_node)
-	new_specs = expr;
+      if (TREE_CODE (expr) == INTEGER_CST)
+	{
+	  if (operand_equal_p (expr, boolean_true_node, 0)
+	      || operand_equal_p (expr, boolean_false_node, 0))
+	    new_specs = expr;
+	}
+      if (new_specs != NULL_TREE)
+	;
       else if (defer_ok)
 	{
 	  /* Defer instantiation of noexcept-specifiers to avoid
--- gcc/cp/typeck2.c.jj	2012-11-19 14:41:16.000000000 +0100
+++ gcc/cp/typeck2.c	2012-12-04 11:54:34.184735478 +0100
@@ -1871,7 +1871,7 @@ merge_exception_specifiers (tree list, t
       /* If ADD is a deferred noexcept, we must have been called from
 	 process_subob_fn.  For implicitly declared functions, we build up
 	 a list of functions to consider at instantiation time.  */
-      if (noex == boolean_true_node)
+      if (operand_equal_p (noex, boolean_true_node, 0))
 	noex = NULL_TREE;
       gcc_assert (fn && (!noex || is_overloaded_fn (noex)));
       noex = build_overload (fn, noex);
--- gcc/testsuite/g++.dg/cpp0x/noexcept18.C.jj	2012-12-04 11:56:32.910049983 +0100
+++ gcc/testsuite/g++.dg/cpp0x/noexcept18.C	2012-12-04 11:55:50.000000000 +0100
@@ -0,0 +1,11 @@
+// PR c++/54207
+// { dg-do compile }
+// { dg-options "-std=c++11" }
+
+typedef bool B;
+constexpr B foo () { return true; }
+
+void
+bar () noexcept (foo ())
+{
+}

	Jakub

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

* Re: [C++ PATCH] Fix build_noexcept_spec ICE (PR c++/54207)
  2012-12-06  7:24 [C++ PATCH] Fix build_noexcept_spec ICE (PR c++/54207) Jakub Jelinek
@ 2012-12-06 14:07 ` Jason Merrill
  2012-12-06 14:31   ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2012-12-06 14:07 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 12/06/2012 02:24 AM, Jakub Jelinek wrote:
> +  if (TREE_CODE (expr) == INTEGER_CST)
> +    {
> +      if (operand_equal_p (expr, boolean_true_node, 0))
> +	return noexcept_true_spec;
> +      else if (operand_equal_p (expr, boolean_false_node, 0))
> +	return noexcept_false_spec;
> +    }

These are the only two possibilities for a boolean INTEGER_CST, so let's 
assert that it's false if it isn't true.

You can then leave the 'else' on the "if (expr == error_mark_node)".

> +      if (TREE_CODE (expr) == INTEGER_CST)
> +	{
> +	  if (operand_equal_p (expr, boolean_true_node, 0)
> +	      || operand_equal_p (expr, boolean_false_node, 0))
> +	    new_specs = expr;
> +	}

And here you don't need to check the value at all unless in an assert.

Jason

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

* Re: [C++ PATCH] Fix build_noexcept_spec ICE (PR c++/54207)
  2012-12-06 14:07 ` Jason Merrill
@ 2012-12-06 14:31   ` Jakub Jelinek
  2012-12-06 15:08     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2012-12-06 14:31 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On Thu, Dec 06, 2012 at 09:07:43AM -0500, Jason Merrill wrote:
> These are the only two possibilities for a boolean INTEGER_CST, so
> let's assert that it's false if it isn't true.
> 
> You can then leave the 'else' on the "if (expr == error_mark_node)".
> 
> And here you don't need to check the value at all unless in an assert.

Ok, here is what I'm going to bootstrap/regtest then:

2012-12-06  Jakub Jelinek  <jakub@redhat.com>

	PR c++/54207
	* except.c (build_noexcept_spec): Avoid direct comparison
	with boolean_true_node or boolean_false_node, instead use
	operand_equal_p and/or INTEGER_CST check.
	* pt.c (tsubst_exception_specification): Likewise.
	* typeck2.c (merge_exception_specifiers): Likewise.

	* g++.dg/cpp0x/noexcept18.C: New test.

--- gcc/cp/pt.c.jj	2012-12-04 14:17:26.829197995 +0100
+++ gcc/cp/pt.c	2012-12-06 15:26:07.574298792 +0100
@@ -10840,7 +10840,7 @@ tsubst_exception_specification (tree fnt
     {
       /* A noexcept-specifier.  */
       tree expr = TREE_PURPOSE (specs);
-      if (expr == boolean_true_node || expr == boolean_false_node)
+      if (TREE_CODE (expr) == INTEGER_CST)
 	new_specs = expr;
       else if (defer_ok)
 	{
--- gcc/cp/typeck2.c.jj	2012-12-04 14:17:26.882197630 +0100
+++ gcc/cp/typeck2.c	2012-12-06 15:16:28.091620326 +0100
@@ -1871,7 +1871,7 @@ merge_exception_specifiers (tree list, t
       /* If ADD is a deferred noexcept, we must have been called from
 	 process_subob_fn.  For implicitly declared functions, we build up
 	 a list of functions to consider at instantiation time.  */
-      if (noex == boolean_true_node)
+      if (operand_equal_p (noex, boolean_true_node, 0))
 	noex = NULL_TREE;
       gcc_assert (fn && (!noex || is_overloaded_fn (noex)));
       noex = build_overload (fn, noex);
--- gcc/cp/except.c.jj	2012-12-04 14:17:26.916197394 +0100
+++ gcc/cp/except.c	2012-12-06 15:23:46.169113297 +0100
@@ -1316,15 +1316,21 @@ build_noexcept_spec (tree expr, int comp
 						LOOKUP_NORMAL);
       expr = cxx_constant_value (expr);
     }
-  if (expr == boolean_true_node)
-    return noexcept_true_spec;
-  else if (expr == boolean_false_node)
-    return noexcept_false_spec;
+  if (TREE_CODE (expr) == INTEGER_CST)
+    {
+      if (operand_equal_p (expr, boolean_true_node, 0))
+	return noexcept_true_spec;
+      else
+	{
+	  gcc_checking_assert (operand_equal_p (expr, boolean_false_node, 0));
+	  return noexcept_false_spec;
+	}
+    }
   else if (expr == error_mark_node)
     return error_mark_node;
   else
     {
-      gcc_assert (processing_template_decl || expr == error_mark_node
+      gcc_assert (processing_template_decl
 		  || TREE_CODE (expr) == DEFERRED_NOEXCEPT);
       return build_tree_list (expr, NULL_TREE);
     }
--- gcc/testsuite/g++.dg/cpp0x/noexcept18.C.jj	2012-12-06 15:16:28.125619775 +0100
+++ gcc/testsuite/g++.dg/cpp0x/noexcept18.C	2012-12-06 15:16:28.125619775 +0100
@@ -0,0 +1,11 @@
+// PR c++/54207
+// { dg-do compile }
+// { dg-options "-std=c++11" }
+
+typedef bool B;
+constexpr B foo () { return true; }
+
+void
+bar () noexcept (foo ())
+{
+}

	Jakub

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

* Re: [C++ PATCH] Fix build_noexcept_spec ICE (PR c++/54207)
  2012-12-06 14:31   ` Jakub Jelinek
@ 2012-12-06 15:08     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2012-12-06 15:08 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

OK.

Jason

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

end of thread, other threads:[~2012-12-06 15:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-06  7:24 [C++ PATCH] Fix build_noexcept_spec ICE (PR c++/54207) Jakub Jelinek
2012-12-06 14:07 ` Jason Merrill
2012-12-06 14:31   ` Jakub Jelinek
2012-12-06 15:08     ` 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).