public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: Use empty field in constexpr eval.
@ 2021-04-29 18:33 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-04-29 18:33 UTC (permalink / raw)
  To: gcc-patches

In discussion of PR98463, Jakub noted that cxx_fold_indirect_ref_1 was
bailing out early for empty bases even when we do have fields for them (in
C++17 mode or later).  This corrects that.

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

gcc/cp/ChangeLog:

	* constexpr.c (cxx_fold_indirect_ref_1): Only set *empty_base if we
	don't find a field.
---
 gcc/cp/constexpr.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index fa7eaed945a..9481a5bfd3c 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4734,28 +4734,17 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type,
 {
   tree optype = TREE_TYPE (op);
   unsigned HOST_WIDE_INT const_nunits;
-  if (off == 0)
-    {
-      if (similar_type_p (optype, type))
-	return op;
-      /* Also handle conversion to an empty base class, which
-	 is represented with a NOP_EXPR.  */
-      /* *(foo *)&complexfoo => __real__ complexfoo */
-      else if (TREE_CODE (optype) == COMPLEX_TYPE
-	       && similar_type_p (type, TREE_TYPE (optype)))
-	return build1_loc (loc, REALPART_EXPR, type, op);
-    }
-  /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
+  if (off == 0 && similar_type_p (optype, type))
+    return op;
   else if (TREE_CODE (optype) == COMPLEX_TYPE
-	   && similar_type_p (type, TREE_TYPE (optype))
-	   && tree_to_uhwi (TYPE_SIZE_UNIT (type)) == off)
-    return build1_loc (loc, IMAGPART_EXPR, type, op);
-  if (is_empty_class (type)
-      && CLASS_TYPE_P (optype)
-      && DERIVED_FROM_P (type, optype))
+	   && similar_type_p (type, TREE_TYPE (optype)))
     {
-      *empty_base = true;
-      return op;
+      /* *(foo *)&complexfoo => __real__ complexfoo */
+      if (off == 0)
+	return build1_loc (loc, REALPART_EXPR, type, op);
+      /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
+      else if (tree_to_uhwi (TYPE_SIZE_UNIT (type)) == off)
+	return build1_loc (loc, IMAGPART_EXPR, type, op);
     }
   /* ((foo*)&vectorfoo)[x] => BIT_FIELD_REF<vectorfoo,...> */
   else if (VECTOR_TYPE_P (optype)
@@ -4834,6 +4823,15 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type,
 		  return ret;
 	      }
 	  }
+      /* Also handle conversion to an empty base class, which
+	 is represented with a NOP_EXPR.  */
+      if (is_empty_class (type)
+	  && CLASS_TYPE_P (optype)
+	  && DERIVED_FROM_P (type, optype))
+	{
+	  *empty_base = true;
+	  return op;
+	}
     }
 
   return NULL_TREE;

base-commit: 449d7b40f6f6be8d7f9aa7232c73b0371f0963bf
prerequisite-patch-id: 39f358d55a4ba496b673d13e00215152266caa54
prerequisite-patch-id: f0d6c56fe2c9e16572f0760fb223f6d4df3e859e
prerequisite-patch-id: 8188da37013371fd5864b80fb0cc5ad4596a1ff6
prerequisite-patch-id: f9c0d88147525dd47cab54ddfdde9341b7b10a4c
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-29 18:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29 18:33 [pushed] c++: Use empty field in constexpr eval 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).