Hi!

The following testcase ICEs, because we assert that we see a COMPOUND_EXPR
only for static data member in a volatile struct, but as the testcase shows,
we can see it also if using some component of the static data member.

Fixed by using get_base_address, plus, as the check isn't as cheap as
before, turn the assert into a checking assert only.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-03-27  Jakub Jelinek  <ja...@redhat.com>

        PR c++/85061
        * c-common.c (fold_offsetof_1) <case COMPOUND_EXPR>: Assert that
        get_base_address of the second operand is a VAR_P, rather than the
        operand itself, and use gcc_checking_assert instead of gcc_assert.

        * g++.dg/ext/builtin-offsetof3.C: New test.

--- gcc/c-family/c-common.c.jj  2018-03-13 00:38:23.809662252 +0100
+++ gcc/c-family/c-common.c     2018-03-24 15:21:36.171485128 +0100
@@ -6272,7 +6272,7 @@ fold_offsetof_1 (tree expr, enum tree_co
     case COMPOUND_EXPR:
       /* Handle static members of volatile structs.  */
       t = TREE_OPERAND (expr, 1);
-      gcc_assert (VAR_P (t));
+      gcc_checking_assert (VAR_P (get_base_address (t)));
       return fold_offsetof_1 (t);
 
     default:
--- gcc/testsuite/g++.dg/ext/builtin-offsetof3.C.jj     2018-03-26 
11:54:54.338627270 +0200
+++ gcc/testsuite/g++.dg/ext/builtin-offsetof3.C        2018-03-26 
11:54:07.992610454 +0200
@@ -0,0 +1,14 @@
+// PR c++/85061
+// { dg-do compile }
+
+struct B { int a, b; };
+struct A
+{
+  static int x[2];
+  static int y;
+  static B z;
+};
+
+int i = __builtin_offsetof (volatile A, x[0]); // { dg-error "cannot apply 
'offsetof' to static data member 'A::x'" }
+int j = __builtin_offsetof (volatile A, y);    // { dg-error "cannot apply 
'offsetof' to static data member 'A::y'" }
+int k = __builtin_offsetof (volatile A, z.a);  // { dg-error "cannot apply 
'offsetof' to a non constant address" }

        Jakub

Reply via email to