public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/56481 (time hog with repeated &&)
@ 2013-02-28 20:21 Jason Merrill
  2013-03-17  1:34 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2013-02-28 20:21 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 330 bytes --]

The problem with this testcase was that for a repeated &&, each call of 
potential_constant_expression_1 led to two calls for the LHS, giving it 
O(N^2) complexity.  Fixed by avoiding the redundant call in 
maybe_constant_value by calling cxx_eval_outermost_constant_expr directly.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 56481.patch --]
[-- Type: text/x-patch, Size: 2174 bytes --]

commit 001c03d979ea1aaa9bc9565f2b9c82371cc481f1
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Feb 28 12:30:40 2013 -0500

    	PR c++/56481
    	* semantics.c (potential_constant_expression_1): Use
    	cxx_eval_outermost_constant_expr rather than maybe_constant_value.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 9446f83..8038aa2 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8683,10 +8683,12 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
     case ROUND_MOD_EXPR:
       {
 	tree denom = TREE_OPERAND (t, 1);
-	/* We can't call maybe_constant_value on an expression
+	if (!potential_constant_expression_1 (denom, rval, flags))
+	  return false;
+	/* We can't call cxx_eval_outermost_constant_expr on an expression
 	   that hasn't been through fold_non_dependent_expr yet.  */
 	if (!processing_template_decl)
-	  denom = maybe_constant_value (denom);
+	  denom = cxx_eval_outermost_constant_expr (denom, true);
 	if (integer_zerop (denom))
 	  {
 	    if (flags & tf_error)
@@ -8696,7 +8698,8 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
 	else
 	  {
 	    want_rval = true;
-	    goto binary;
+	    return potential_constant_expression_1 (TREE_OPERAND (t, 0),
+						    want_rval, flags);
 	  }
       }
 
@@ -8731,7 +8734,7 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
 	if (!potential_constant_expression_1 (op, rval, flags))
 	  return false;
 	if (!processing_template_decl)
-	  op = maybe_constant_value (op);
+	  op = cxx_eval_outermost_constant_expr (op, true);
 	if (tree_int_cst_equal (op, tmp))
 	  return potential_constant_expression_1 (TREE_OPERAND (t, 1), rval, flags);
 	else
@@ -8793,7 +8796,7 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
       if (!potential_constant_expression_1 (tmp, rval, flags))
 	return false;
       if (!processing_template_decl)
-	tmp = maybe_constant_value (tmp);
+	tmp = cxx_eval_outermost_constant_expr (tmp, true);
       if (integer_zerop (tmp))
 	return potential_constant_expression_1 (TREE_OPERAND (t, 2),
 						want_rval, flags);

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

* Re: C++ PATCH for c++/56481 (time hog with repeated &&)
  2013-02-28 20:21 C++ PATCH for c++/56481 (time hog with repeated &&) Jason Merrill
@ 2013-03-17  1:34 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2013-03-17  1:34 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 166 bytes --]

It is also the case that using 'this' in a non-constexpr function should 
prevent the expression from being constant.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 56481-2.patch --]
[-- Type: text/x-patch, Size: 897 bytes --]

commit e0f26a1998f2cb404e58bcf8a9f22e29401312e0
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Feb 28 11:58:44 2013 -0500

    	PR c++/56481
    	* semantics.c (potential_constant_expression_1): Use of 'this' in
    	a non-constexpr function makes the expression not potentially
    	constant.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 1cf060e..9d2f3f4 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8497,6 +8497,13 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
         STRIP_NOPS (x);
         if (is_this_parameter (x))
 	  {
+	    if (DECL_CONTEXT (x)
+		&& !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x)))
+	      {
+		if (flags & tf_error)
+		  error ("use of %<this%> in a constant expression");
+		return false;
+	      }
 	    if (want_rval && DECL_CONTEXT (x)
 		&& DECL_CONSTRUCTOR_P (DECL_CONTEXT (x)))
 	      {

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

end of thread, other threads:[~2013-03-17  1:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-28 20:21 C++ PATCH for c++/56481 (time hog with repeated &&) Jason Merrill
2013-03-17  1:34 ` 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).