mirror of git://gcc.gnu.org/git/gcc.git
re PR c/67088 (Incorrect location of error on invalid type used in bit-field declaration)
PR c/67088 * c-decl.c (check_bitfield_type_and_width): Add location parameter. Use it. (grokdeclarator): Pass LOC down to check_bitfield_type_and_width. * gcc.dg/pr67088.c: New test. From-SVN: r226506
This commit is contained in:
parent
5030111533
commit
420a9d9bd8
|
|
@ -1,3 +1,10 @@
|
||||||
|
2015-08-03 Marek Polacek <polacek@redhat.com>
|
||||||
|
|
||||||
|
PR c/67088
|
||||||
|
* c-decl.c (check_bitfield_type_and_width): Add location parameter.
|
||||||
|
Use it.
|
||||||
|
(grokdeclarator): Pass LOC down to check_bitfield_type_and_width.
|
||||||
|
|
||||||
2015-08-02 Patrick Palka <ppalka@gcc.gnu.org>
|
2015-08-02 Patrick Palka <ppalka@gcc.gnu.org>
|
||||||
|
|
||||||
* c-parser.c (c_parser_if_body): Take token_indent_info
|
* c-parser.c (c_parser_if_body): Take token_indent_info
|
||||||
|
|
|
||||||
|
|
@ -5153,8 +5153,10 @@ flexible_array_type_p (tree type)
|
||||||
|
|
||||||
/* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
|
/* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
|
||||||
replacing with appropriate values if they are invalid. */
|
replacing with appropriate values if they are invalid. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
|
check_bitfield_type_and_width (location_t loc, tree *type, tree *width,
|
||||||
|
tree orig_name)
|
||||||
{
|
{
|
||||||
tree type_mv;
|
tree type_mv;
|
||||||
unsigned int max_width;
|
unsigned int max_width;
|
||||||
|
|
@ -5167,7 +5169,7 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
|
||||||
field widths. */
|
field widths. */
|
||||||
if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
|
if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
|
||||||
{
|
{
|
||||||
error ("bit-field %qs width not an integer constant", name);
|
error_at (loc, "bit-field %qs width not an integer constant", name);
|
||||||
*width = integer_one_node;
|
*width = integer_one_node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -5176,24 +5178,24 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
|
||||||
{
|
{
|
||||||
*width = c_fully_fold (*width, false, NULL);
|
*width = c_fully_fold (*width, false, NULL);
|
||||||
if (TREE_CODE (*width) == INTEGER_CST)
|
if (TREE_CODE (*width) == INTEGER_CST)
|
||||||
pedwarn (input_location, OPT_Wpedantic,
|
pedwarn (loc, OPT_Wpedantic,
|
||||||
"bit-field %qs width not an integer constant expression",
|
"bit-field %qs width not an integer constant expression",
|
||||||
name);
|
name);
|
||||||
}
|
}
|
||||||
if (TREE_CODE (*width) != INTEGER_CST)
|
if (TREE_CODE (*width) != INTEGER_CST)
|
||||||
{
|
{
|
||||||
error ("bit-field %qs width not an integer constant", name);
|
error_at (loc, "bit-field %qs width not an integer constant", name);
|
||||||
*width = integer_one_node;
|
*width = integer_one_node;
|
||||||
}
|
}
|
||||||
constant_expression_warning (*width);
|
constant_expression_warning (*width);
|
||||||
if (tree_int_cst_sgn (*width) < 0)
|
if (tree_int_cst_sgn (*width) < 0)
|
||||||
{
|
{
|
||||||
error ("negative width in bit-field %qs", name);
|
error_at (loc, "negative width in bit-field %qs", name);
|
||||||
*width = integer_one_node;
|
*width = integer_one_node;
|
||||||
}
|
}
|
||||||
else if (integer_zerop (*width) && orig_name)
|
else if (integer_zerop (*width) && orig_name)
|
||||||
{
|
{
|
||||||
error ("zero width for bit-field %qs", name);
|
error_at (loc, "zero width for bit-field %qs", name);
|
||||||
*width = integer_one_node;
|
*width = integer_one_node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5203,7 +5205,7 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
|
||||||
&& TREE_CODE (*type) != BOOLEAN_TYPE
|
&& TREE_CODE (*type) != BOOLEAN_TYPE
|
||||||
&& TREE_CODE (*type) != ENUMERAL_TYPE)
|
&& TREE_CODE (*type) != ENUMERAL_TYPE)
|
||||||
{
|
{
|
||||||
error ("bit-field %qs has invalid type", name);
|
error_at (loc, "bit-field %qs has invalid type", name);
|
||||||
*type = unsigned_type_node;
|
*type = unsigned_type_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5212,14 +5214,14 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
|
||||||
&& type_mv != integer_type_node
|
&& type_mv != integer_type_node
|
||||||
&& type_mv != unsigned_type_node
|
&& type_mv != unsigned_type_node
|
||||||
&& type_mv != boolean_type_node)
|
&& type_mv != boolean_type_node)
|
||||||
pedwarn_c90 (input_location, OPT_Wpedantic,
|
pedwarn_c90 (loc, OPT_Wpedantic,
|
||||||
"type of bit-field %qs is a GCC extension", name);
|
"type of bit-field %qs is a GCC extension", name);
|
||||||
|
|
||||||
max_width = TYPE_PRECISION (*type);
|
max_width = TYPE_PRECISION (*type);
|
||||||
|
|
||||||
if (0 < compare_tree_int (*width, max_width))
|
if (0 < compare_tree_int (*width, max_width))
|
||||||
{
|
{
|
||||||
error ("width of %qs exceeds its type", name);
|
error_at (loc, "width of %qs exceeds its type", name);
|
||||||
w = max_width;
|
w = max_width;
|
||||||
*width = build_int_cst (integer_type_node, w);
|
*width = build_int_cst (integer_type_node, w);
|
||||||
}
|
}
|
||||||
|
|
@ -5232,7 +5234,7 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
|
||||||
if (!lt
|
if (!lt
|
||||||
|| w < tree_int_cst_min_precision (lt->enum_min, TYPE_SIGN (*type))
|
|| w < tree_int_cst_min_precision (lt->enum_min, TYPE_SIGN (*type))
|
||||||
|| w < tree_int_cst_min_precision (lt->enum_max, TYPE_SIGN (*type)))
|
|| w < tree_int_cst_min_precision (lt->enum_max, TYPE_SIGN (*type)))
|
||||||
warning (0, "%qs is narrower than values of its type", name);
|
warning_at (loc, 0, "%qs is narrower than values of its type", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6224,7 +6226,7 @@ grokdeclarator (const struct c_declarator *declarator,
|
||||||
/* Check the type and width of a bit-field. */
|
/* Check the type and width of a bit-field. */
|
||||||
if (bitfield)
|
if (bitfield)
|
||||||
{
|
{
|
||||||
check_bitfield_type_and_width (&type, width, name);
|
check_bitfield_type_and_width (loc, &type, width, name);
|
||||||
/* C11 makes it implementation-defined (6.7.2.1#5) whether
|
/* C11 makes it implementation-defined (6.7.2.1#5) whether
|
||||||
atomic types are permitted for bit-fields; we have no code to
|
atomic types are permitted for bit-fields; we have no code to
|
||||||
make bit-field accesses atomic, so disallow them. */
|
make bit-field accesses atomic, so disallow them. */
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
2015-08-03 Marek Polacek <polacek@redhat.com>
|
||||||
|
|
||||||
|
PR c/67088
|
||||||
|
* gcc.dg/pr67088.c: New test.
|
||||||
|
|
||||||
2015-08-03 Szabolcs Nagy <szabolcs.nagy@arm.com>
|
2015-08-03 Szabolcs Nagy <szabolcs.nagy@arm.com>
|
||||||
|
|
||||||
PR target/66731
|
PR target/66731
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* PR c/67088 */
|
||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-options "-Wpedantic -std=c90" } */
|
||||||
|
|
||||||
|
enum E { A = 2 };
|
||||||
|
int j;
|
||||||
|
float f;
|
||||||
|
struct S1 {
|
||||||
|
double b1:1; /* { dg-error "10:has invalid type" } */
|
||||||
|
int b2:j; /* { dg-error "7:width not an integer constant" } */
|
||||||
|
int b3:f; /* { dg-error "7:width not an integer constant" } */
|
||||||
|
int b4:(int) __builtin_log (100); /* { dg-warning "7:width not an integer constant" } */
|
||||||
|
int b5:-2; /* { dg-error "7:negative width" } */
|
||||||
|
int b6:0; /* { dg-error "7:zero width" } */
|
||||||
|
long int b7:32; /* { dg-warning "12:type of bit-field" } */
|
||||||
|
int b8:sizeof (int) * __CHAR_BIT__ * 2; /* { dg-error "7:width of" } */
|
||||||
|
__extension__ enum E b9:1; /* { dg-warning "24:is narrower" } */
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue