public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++/68711 - [5 regression] SEGV on an invalid offsetof of a member of a virtual base
@ 2015-12-05 23:07 Martin Sebor
  2015-12-07 20:39 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2015-12-05 23:07 UTC (permalink / raw)
  To: Gcc Patch List, Jason Merrill

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

The attached patch restores the "invalid access to non-static
data member" error for invalid offsetof-like expressions
involving members of virtually derived base classes that was
inadvertently made ineffective as a result of the merge of
the C++ delayed folding branch.

Martin

[-- Attachment #2: gcc-68711.patch --]
[-- Type: text/x-patch, Size: 1583 bytes --]

gcc/testsuite/ChangeLog:
2015-12-05  Martin Sebor  <msebor@redhat.com>

	PR c++/68711
	* g++.dg/other/offsetof8.C: New test.

gcc/cp/ChangeLog:
2015-12-05  Martin Sebor  <msebor@redhat.com>

	PR c++/68711
	* typeck.c (build_class_member_access_expr): Strip NOPs before
        testing a potentially null operand for equality to zero.

Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 231314)
+++ gcc/cp/typeck.c	(working copy)
@@ -2358,8 +2358,14 @@
       int type_quals;
       tree member_type;
 
-      null_object_p = (INDIRECT_REF_P (object)
-		       && integer_zerop (TREE_OPERAND (object, 0)));
+      if (INDIRECT_REF_P (object))
+	{
+	  tree oper = TREE_OPERAND (object, 0);
+	  STRIP_NOPS (oper);
+	  null_object_p = integer_zerop (oper);
+	}
+      else
+	null_object_p = false;
 
       /* Convert OBJECT to the type of MEMBER.  */
       if (!same_type_p (TYPE_MAIN_VARIANT (object_type),
Index: gcc/testsuite/g++.dg/other/offsetof8.C
===================================================================
--- gcc/testsuite/g++.dg/other/offsetof8.C	(revision 0)
+++ gcc/testsuite/g++.dg/other/offsetof8.C	(working copy)
@@ -0,0 +1,12 @@
+// PR c++/68711 - [5 regression] SEGV on an invalid offsetof of a member
+//                of a virtual base
+// { dg-do compile }
+
+struct A { int i; };
+
+struct B: virtual A { };
+
+int a[]  = {
+  !&((B*)0)->i,    // { dg-error "invalid access to non-static data member" }
+  __builtin_offsetof (B, i)   // { dg-error "invalid access to non-static" }
+};

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

* Re: [PATCH] c++/68711 - [5 regression] SEGV on an invalid offsetof of a member of a virtual base
  2015-12-05 23:07 [PATCH] c++/68711 - [5 regression] SEGV on an invalid offsetof of a member of a virtual base Martin Sebor
@ 2015-12-07 20:39 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2015-12-07 20:39 UTC (permalink / raw)
  To: Martin Sebor, Gcc Patch List

On 12/05/2015 06:07 PM, Martin Sebor wrote:
> +	  tree oper = TREE_OPERAND (object, 0);
> +	  STRIP_NOPS (oper);
> +	  null_object_p = integer_zerop (oper);

You could use tree_strip_nop_conversions to avoid needing a local 
variable, but this is OK too.

Jason

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

end of thread, other threads:[~2015-12-07 20:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-05 23:07 [PATCH] c++/68711 - [5 regression] SEGV on an invalid offsetof of a member of a virtual base Martin Sebor
2015-12-07 20:39 ` 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).