From 64ed018c41cc01c9e1be29e767d2764ea1a01f69 Mon Sep 17 00:00:00 2001 From: dodji Date: Tue, 3 Nov 2009 10:44:36 +0000 Subject: Fix PR c++/38699 gcc/ChangeLog: PR c++/38699 * c-common.c (fold_offsetof_1): Issue errors when the member designator of the offsetoff expression is not legitimate. gcc/testsuite/ChangeLog: * c-c++-common/dfp/builtin-offsetof.c: New test. * g++.dg/other/offsetof6.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@153843 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c (limited to 'gcc/testsuite/c-c++-common/dfp') diff --git a/gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c b/gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c new file mode 100644 index 00000000000..0ab498acd09 --- /dev/null +++ b/gcc/testsuite/c-c++-common/dfp/builtin-offsetof.c @@ -0,0 +1,29 @@ +// Contributed by Dodji Seketeli +// Origin PR c++/38699 +// { dg-options "-Warray-bounds" } +// { dg-do compile } + +struct A +{ + const char *p; +}; + +struct B +{ + char p[10]; + struct A a; +}; + +void +f0 () +{ + __builtin_offsetof(struct A, p); // OK + __builtin_offsetof(struct A, p[0]); // { dg-error "non constant address" } + __builtin_offsetof(struct B, p[0]); // OK + __builtin_offsetof(struct B, p[9]); // OK + __builtin_offsetof(struct B, p[10]); // { dg-warning "greater than size" } + __builtin_offsetof(struct B, a.p); // OK + __builtin_offsetof(struct B, p[0]); // OK + __builtin_offsetof(struct B, a.p[0]); // { dg-error "non constant address" } +} + -- cgit v1.2.1