From a7dea61705009a47b788ecafed0816ab8b54e3ac Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 27 Mar 2018 21:59:30 +0200 Subject: [PATCH] re PR c++/85061 (ICE with __builtin_offsetof applied to static member) PR c++/85061 * c-common.c (fold_offsetof_1) : 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. From-SVN: r258902 --- gcc/c-family/ChangeLog | 7 +++++++ gcc/c-family/c-common.c | 2 +- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/ext/builtin-offsetof3.C | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/builtin-offsetof3.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index f728311310a..e3558d7332f 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2018-03-27 Jakub Jelinek + + PR c++/85061 + * c-common.c (fold_offsetof_1) : 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. + 2018-03-23 Marek Polacek PR c++/85045 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index e1df1d3b73b..7e6905e791e 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -6272,7 +6272,7 @@ fold_offsetof_1 (tree expr, enum tree_code ctx) 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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9cd81d9946b..93557dda655 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-03-27 Jakub Jelinek + PR c++/85061 + * g++.dg/ext/builtin-offsetof3.C: New test. + PR c++/85076 * g++.dg/cpp1y/pr85076.C: New test. diff --git a/gcc/testsuite/g++.dg/ext/builtin-offsetof3.C b/gcc/testsuite/g++.dg/ext/builtin-offsetof3.C new file mode 100644 index 00000000000..79c358b6ad6 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin-offsetof3.C @@ -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" } -- 2.30.2