aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2015-12-09 01:35:59 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2015-12-08 18:35:59 -0700
commit1a161cd7a7545318c1ee29dfd2eb76ee6ee9f43e (patch)
tree9d92fe8e1f3fe6ebcfa909771bb950bd93fef15c
parent9ba300b1a53cbce4924f0e392135b4cdf0ee9fdd (diff)
downloadgcc-1a161cd7a7545318c1ee29dfd2eb76ee6ee9f43e.zip
gcc-1a161cd7a7545318c1ee29dfd2eb76ee6ee9f43e.tar.gz
gcc-1a161cd7a7545318c1ee29dfd2eb76ee6ee9f43e.tar.bz2
Fix PR c++/68711 - [6 regression] SEGV on an invalid offsetof of a member
of a virtual base. gcc/testsuite/ChangeLog: * g++.dg/other/offsetof8.C: New test. gcc/cp/ChangeLog: * typeck.c (build_class_member_access_expr): Strip NOPs before testing a potentially null operand for equality to zero. From-SVN: r231437
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/offsetof8.C12
4 files changed, 28 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7569a62..ac41ca6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-08 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.
+
2015-12-07 Jakub Jelinek <jakub@redhat.com>
PR c++/68760
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 3cf3c95..17671ee 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2358,8 +2358,11 @@ build_class_member_access_expr (cp_expr object, tree member,
int type_quals;
tree member_type;
- null_object_p = (INDIRECT_REF_P (object)
- && integer_zerop (TREE_OPERAND (object, 0)));
+ if (INDIRECT_REF_P (object))
+ null_object_p =
+ integer_zerop (tree_strip_nop_conversions (TREE_OPERAND (object, 0)));
+ else
+ null_object_p = false;
/* Convert OBJECT to the type of MEMBER. */
if (!same_type_p (TYPE_MAIN_VARIANT (object_type),
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b596b03..5cefc07 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-08 Martin Sebor <msebor@redhat.com>
+
+ PR c++/68711
+ * g++.dg/other/offsetof8.C: New test.
+
2015-12-08 Nathan Sidwell <nathan@acm.org>
* gcc.target/nvptx/trailing-init.c: New.
diff --git a/gcc/testsuite/g++.dg/other/offsetof8.C b/gcc/testsuite/g++.dg/other/offsetof8.C
new file mode 100644
index 0000000..daca70a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/offsetof8.C
@@ -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" }
+};