public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++/ARM Patch] PR 81942 ("ICE on empty constexpr constructor with C++14")
@ 2017-09-05 10:19 Paolo Carlini
  2017-09-05 11:18 ` Nathan Sidwell
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2017-09-05 10:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi,

Hi,

in this ICE on valid, a gcc_assert fires when a GOTO_EXPR is handled by 
cxx_eval_constant_expression which is the translation of a "return;" on 
a targetm.cxx.cdtor_returns_this target (like ARM):

;; Function constexpr A::A() (null)
;; enabled by -tree-original


{
   // predicted unlikely by goto predictor.;
   goto <D.4600>;
}
<D.4600>:;
return this;

I think the right way to handle this is marking such special labels with 
a LABEL_DECL_CDTOR flag and using it in the returns helper function (we 
already use a similar strategy with LABEL_DECL_BREAK and 
LABEL_DECL_CONTINUE and the breaks and continues helpers). Then 
adjusting the ICEing gcc_assert is trivial. Tested x86_64-linux and 
aarch64-linux.

Thanks,
Paolo.

//////////////////////////////////


[-- Attachment #2: CL_81942 --]
[-- Type: text/plain, Size: 503 bytes --]

/cp
2017-09-05  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/81942
	* cp-tree.h (LABEL_DECL_CDTOR): Add and document.
	* decl.c (start_preparsed_function): Set LABEL_DECL_CDTOR when
	creating cdtor_label.
	* constexpr.c (returns): Add the case of a constructor/destructor
	returning via a LABEL_DECL_CDTOR label.
	(cxx_eval_constant_expression, case [GOTO_EXPR]): Likewise.

/testsuite
2017-09-05  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/81942
	* g++.dg/cpp1y/constexpr-return3.C: New.

[-- Attachment #3: patch_81942 --]
[-- Type: text/plain, Size: 2919 bytes --]

Index: cp/constexpr.c
===================================================================
--- cp/constexpr.c	(revision 251700)
+++ cp/constexpr.c	(working copy)
@@ -3671,7 +3671,9 @@ static bool
 returns (tree *jump_target)
 {
   return *jump_target
-    && TREE_CODE (*jump_target) == RETURN_EXPR;
+    && (TREE_CODE (*jump_target) == RETURN_EXPR
+	|| (TREE_CODE (*jump_target) == LABEL_DECL
+	    && LABEL_DECL_CDTOR (*jump_target)));
 }
 
 static bool
@@ -4554,7 +4556,9 @@ cxx_eval_constant_expression (const constexpr_ctx
 
     case GOTO_EXPR:
       *jump_target = TREE_OPERAND (t, 0);
-      gcc_assert (breaks (jump_target) || continues (jump_target));
+      gcc_assert (breaks (jump_target) || continues (jump_target)
+		  /* Allow for jumping to a cdtor_label.  */
+		  || returns (jump_target));
       break;
 
     case LOOP_EXPR:
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 251700)
+++ cp/cp-tree.h	(working copy)
@@ -456,6 +456,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
       DECL_CONSTRAINT_VAR_P (in a PARM_DECL)
       TEMPLATE_DECL_COMPLEX_ALIAS_P (in TEMPLATE_DECL)
       DECL_INSTANTIATING_NSDMI_P (in a FIELD_DECL)
+      LABEL_DECL_CDTOR (in LABEL_DECL)
    3: DECL_IN_AGGR_P.
    4: DECL_C_BIT_FIELD (in a FIELD_DECL)
       DECL_ANON_UNION_VAR_P (in a VAR_DECL)
@@ -3833,6 +3834,11 @@ more_aggr_init_expr_args_p (const aggr_init_expr_a
 #define LABEL_DECL_CONTINUE(NODE) \
   DECL_LANG_FLAG_1 (LABEL_DECL_CHECK (NODE))
 
+/* Nonzero if NODE is the target for genericization of 'return' stmts
+   in constructors/destructors of targetm.cxx.cdtor_returns_this targets.  */
+#define LABEL_DECL_CDTOR(NODE) \
+  DECL_LANG_FLAG_2 (LABEL_DECL_CHECK (NODE))
+
 /* True if NODE was declared with auto in its return type, but it has
    started compilation and so the return type might have been changed by
    return type deduction; its declared return type should be found in
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 251700)
+++ cp/decl.c	(working copy)
@@ -15072,7 +15073,10 @@ start_preparsed_function (tree decl1, tree attrs,
   if (DECL_DESTRUCTOR_P (decl1)
       || (DECL_CONSTRUCTOR_P (decl1)
 	  && targetm.cxx.cdtor_returns_this ()))
-    cdtor_label = create_artificial_label (input_location);
+    {
+      cdtor_label = create_artificial_label (input_location);
+      LABEL_DECL_CDTOR (cdtor_label) = true;
+    }
 
   start_fname_decls ();
 
Index: testsuite/g++.dg/cpp1y/constexpr-return3.C
===================================================================
--- testsuite/g++.dg/cpp1y/constexpr-return3.C	(revision 0)
+++ testsuite/g++.dg/cpp1y/constexpr-return3.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/81942
+// { dg-do compile { target c++14 } }
+
+class A {
+public:
+    constexpr A() {
+      return;
+    }
+};
+
+A mwi;

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

* Re: [C++/ARM Patch] PR 81942 ("ICE on empty constexpr constructor with C++14")
  2017-09-05 10:19 [C++/ARM Patch] PR 81942 ("ICE on empty constexpr constructor with C++14") Paolo Carlini
@ 2017-09-05 11:18 ` Nathan Sidwell
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2017-09-05 11:18 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches; +Cc: Jason Merrill

On 09/05/2017 06:19 AM, Paolo Carlini wrote:

> in this ICE on valid, a gcc_assert fires when a GOTO_EXPR is handled by 
> cxx_eval_constant_expression which is the translation of a "return;" on 
> a targetm.cxx.cdtor_returns_this target (like ARM):

> I think the right way to handle this is marking such special labels with 
> a LABEL_DECL_CDTOR flag and using it in the returns helper function (we 
> already use a similar strategy with LABEL_DECL_BREAK and 
> LABEL_DECL_CONTINUE and the breaks and continues helpers). Then 
> adjusting the ICEing gcc_assert is trivial. Tested x86_64-linux and 
> aarch64-linux.

OK.

(heh, i notice we call the hook 'cdtor_returns_this', but AFAICT it only 
applies to ctors.  Not your problem though.)

nathan

-- 
Nathan Sidwell

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

end of thread, other threads:[~2017-09-05 11:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 10:19 [C++/ARM Patch] PR 81942 ("ICE on empty constexpr constructor with C++14") Paolo Carlini
2017-09-05 11:18 ` Nathan Sidwell

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).