From a174e38c098d49c437142b7a6d31f065a998d50c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 1 Jul 2011 09:36:17 -0400 Subject: [PATCH] re PR c++/49085 (Crash with SIGSEGV during compilation.) PR c++/49085 * semantics.c (finish_offsetof): Complain about incomplete type. From-SVN: r175758 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/semantics.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/offsetof2.C | 10 ++++++++++ 4 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/offsetof2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cc950786d9b..842d049b2a4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-07-01 Jason Merrill + + PR c++/49085 + * semantics.c (finish_offsetof): Complain about incomplete type. + 2011-06-30 Jason Merrill PR c++/49387 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index ad68a012d17..a704aa3182a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3422,6 +3422,12 @@ finish_offsetof (tree expr) } if (REFERENCE_REF_P (expr)) expr = TREE_OPERAND (expr, 0); + if (TREE_CODE (expr) == COMPONENT_REF) + { + tree object = TREE_OPERAND (expr, 0); + if (!complete_type_or_else (TREE_TYPE (object), object)) + return error_mark_node; + } return fold_offsetof (expr, NULL_TREE); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 857ed564f8a..8f2053a84fd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-07-01 Jason Merrill + + PR c++/49085 + * g++.dg/template/offsetof2.C: New. + 2011-07-01 Kai Tietz * gcc.dg/tree-ssa/bitwise-sink.c: New test. diff --git a/gcc/testsuite/g++.dg/template/offsetof2.C b/gcc/testsuite/g++.dg/template/offsetof2.C new file mode 100644 index 00000000000..da888f7a59e --- /dev/null +++ b/gcc/testsuite/g++.dg/template/offsetof2.C @@ -0,0 +1,10 @@ +// PR c++/49085 + +template +struct A // { dg-error "declaration" } +{ + int i, j; + int ar[__builtin_offsetof(A,j)]; // { dg-error "incomplete type" } +}; + +A a; -- 2.30.2