From 59dc2654d4e16ababf4ef4a3f25ec24b65889d95 Mon Sep 17 00:00:00 2001 From: jsm28 Date: Wed, 30 Dec 2009 21:28:45 +0000 Subject: [PATCH] PR c/42439 * c-decl.c (check_bitfield_type_and_width): Only pedwarn if pedantic for bit-field width not an integer constant expression but folding to one. testsuite: * gcc.dg/bitfld-19.c, gcc.dg/bitfld-20.c, gcc.dg/bitfld-21.c: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155526 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/c-decl.c | 16 ++++++++++++++-- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/bitfld-19.c | 11 +++++++++++ gcc/testsuite/gcc.dg/bitfld-20.c | 11 +++++++++++ gcc/testsuite/gcc.dg/bitfld-21.c | 11 +++++++++++ 6 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/bitfld-19.c create mode 100644 gcc/testsuite/gcc.dg/bitfld-20.c create mode 100644 gcc/testsuite/gcc.dg/bitfld-21.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9b4a6fe9412..bd540df9bba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2009-12-30 Joseph Myers + + PR c/42439 + * c-decl.c (check_bitfield_type_and_width): Only pedwarn if + pedantic for bit-field width not an integer constant expression + but folding to one. + 2009-12-30 Ira Rosen PR tree-optimization/41956 diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 49a530c551b..0655197f5bc 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4570,14 +4570,26 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name) /* Detect and ignore out of range field width and process valid field widths. */ - if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)) - || TREE_CODE (*width) != INTEGER_CST) + if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))) { error ("bit-field %qs width not an integer constant", name); *width = integer_one_node; } else { + if (TREE_CODE (*width) != INTEGER_CST) + { + *width = c_fully_fold (*width, false, NULL); + if (TREE_CODE (*width) == INTEGER_CST) + pedwarn (input_location, OPT_pedantic, + "bit-field %qs width not an integer constant expression", + name); + } + if (TREE_CODE (*width) != INTEGER_CST) + { + error ("bit-field %qs width not an integer constant", name); + *width = integer_one_node; + } constant_expression_warning (*width); if (tree_int_cst_sgn (*width) < 0) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c49c2d5a37..005b4ac4e9d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2009-12-30 Joseph Myers + + PR c/42439 + * gcc.dg/bitfld-19.c, gcc.dg/bitfld-20.c, gcc.dg/bitfld-21.c: New + tests. + 2009-12-30 Ira Rosen PR tree-optimization/41956 diff --git a/gcc/testsuite/gcc.dg/bitfld-19.c b/gcc/testsuite/gcc.dg/bitfld-19.c new file mode 100644 index 00000000000..072e93c2ae9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitfld-19.c @@ -0,0 +1,11 @@ +/* Test for bit-field widths not integer constant expressions but + folding to integer constants: PR 42439. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void +f (void) +{ + const int m = 1; + ((void)(sizeof(struct { int i:!!m; }))); +} diff --git a/gcc/testsuite/gcc.dg/bitfld-20.c b/gcc/testsuite/gcc.dg/bitfld-20.c new file mode 100644 index 00000000000..63aaa5c8dc9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitfld-20.c @@ -0,0 +1,11 @@ +/* Test for bit-field widths not integer constant expressions but + folding to integer constants: PR 42439. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -pedantic" } */ + +void +f (void) +{ + const int m = 1; + ((void)(sizeof(struct { int i:!!m; }))); /* { dg-warning "not an integer constant expression" } */ +} diff --git a/gcc/testsuite/gcc.dg/bitfld-21.c b/gcc/testsuite/gcc.dg/bitfld-21.c new file mode 100644 index 00000000000..66f9330f190 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitfld-21.c @@ -0,0 +1,11 @@ +/* Test for bit-field widths not integer constant expressions but + folding to integer constants: PR 42439. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -pedantic-errors" } */ + +void +f (void) +{ + const int m = 1; + ((void)(sizeof(struct { int i:!!m; }))); /* { dg-error "not an integer constant expression" } */ +} -- 2.11.4.GIT