C: fix reported range of invalid unary dereference.
gcc/c/ChangeLog: * c-parser.c (c_parser_unary_expression): For dereferences, build a combined location before calling build_indirect_ref, so that error reports cover the full range, manually updating the c_expr src_range. gcc/testsuite/ChangeLog: * gcc.dg/bad-dereference.c: New test case. From-SVN: r232110
This commit is contained in:
parent
329289313c
commit
7443cf1305
4 changed files with 47 additions and 8 deletions
|
@ -1,3 +1,10 @@
|
|||
2016-01-06 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* c-parser.c (c_parser_unary_expression): For dereferences, build
|
||||
a combined location before calling build_indirect_ref, so that
|
||||
error reports cover the full range, manually updating the c_expr
|
||||
src_range.
|
||||
|
||||
2016-01-06 Marek Polacek <polacek@redhat.com>
|
||||
|
||||
PR sanitizer/69099
|
||||
|
|
|
@ -6759,14 +6759,18 @@ c_parser_unary_expression (c_parser *parser)
|
|||
mark_exp_read (op.value);
|
||||
return parser_build_unary_op (op_loc, ADDR_EXPR, op);
|
||||
case CPP_MULT:
|
||||
c_parser_consume_token (parser);
|
||||
exp_loc = c_parser_peek_token (parser)->location;
|
||||
op = c_parser_cast_expression (parser, NULL);
|
||||
finish = op.get_finish ();
|
||||
op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
|
||||
ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
|
||||
set_c_expr_source_range (&ret, op_loc, finish);
|
||||
return ret;
|
||||
{
|
||||
c_parser_consume_token (parser);
|
||||
exp_loc = c_parser_peek_token (parser)->location;
|
||||
op = c_parser_cast_expression (parser, NULL);
|
||||
finish = op.get_finish ();
|
||||
op = convert_lvalue_to_rvalue (exp_loc, op, true, true);
|
||||
location_t combined_loc = make_location (op_loc, op_loc, finish);
|
||||
ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR);
|
||||
ret.src_range.m_start = op_loc;
|
||||
ret.src_range.m_finish = finish;
|
||||
return ret;
|
||||
}
|
||||
case CPP_PLUS:
|
||||
if (!c_dialect_objc () && !in_system_header_at (input_location))
|
||||
warning_at (op_loc,
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2016-01-06 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* gcc.dg/bad-dereference.c: New test case.
|
||||
|
||||
2015-01-06 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
|
||||
|
||||
* gcc.target/powerpc/p9-lxvx-stxvx-3.c: New test.
|
||||
|
|
24
gcc/testsuite/gcc.dg/bad-dereference.c
Normal file
24
gcc/testsuite/gcc.dg/bad-dereference.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* { dg-options "-fdiagnostics-show-caret" } */
|
||||
|
||||
struct foo
|
||||
{
|
||||
int x;
|
||||
};
|
||||
|
||||
int test_1 (struct foo some_f)
|
||||
{
|
||||
return *some_f.x; /* { dg-error "invalid type argument of unary ... .have .int.." } */
|
||||
/* { dg-begin-multiline-output "" }
|
||||
return *some_f.x;
|
||||
^~~~~~~~~
|
||||
{ dg-end-multiline-output "" } */
|
||||
}
|
||||
|
||||
int test_2 (struct foo some_f)
|
||||
{
|
||||
return *some_f; /* { dg-error "invalid type argument of unary ... .have .struct foo.." } */
|
||||
/* { dg-begin-multiline-output "" }
|
||||
return *some_f;
|
||||
^~~~~~~
|
||||
{ dg-end-multiline-output "" } */
|
||||
}
|
Loading…
Add table
Reference in a new issue