Commit 46c6e1e2 by David Malcolm Committed by David Malcolm

PR c/68757: fix uninitialized src_range for various builtins

gcc/c/ChangeLog:
	PR c/68757
	* c-parser.c (c_parser_get_builtin_args): Add
	"out_close_paren_loc" param, and write back to it.
	(c_parser_postfix_expression): Capture the closing
	parenthesis location for RID_CHOOSE_EXPR,
	RID_BUILTIN_CALL_WITH_STATIC_CHAIN, RID_BUILTIN_COMPLEX,
	RID_BUILTIN_SHUFFLE and use it to set the source range
	for such expressions; within RID_BUILTIN_COMPLEX set
	the underlying location.

gcc/testsuite/ChangeLog:
	PR c/68757
	* gcc.dg/plugin/diagnostic-test-expressions-1.c
	(test_builtin_choose_expr): New test function.
	(test_builtin_call_with_static_chain): Likewise.
	(test_builtin_complex): Likewise.
	(test_builtin_shuffle): Likewise.

From-SVN: r231414
parent b26a3da5
2015-12-08 David Malcolm <dmalcolm@redhat.com>
PR c/68757
* c-parser.c (c_parser_get_builtin_args): Add
"out_close_paren_loc" param, and write back to it.
(c_parser_postfix_expression): Capture the closing
parenthesis location for RID_CHOOSE_EXPR,
RID_BUILTIN_CALL_WITH_STATIC_CHAIN, RID_BUILTIN_COMPLEX,
RID_BUILTIN_SHUFFLE and use it to set the source range
for such expressions; within RID_BUILTIN_COMPLEX set
the underlying location.
2015-12-07 Marek Polacek <polacek@redhat.com> 2015-12-07 Marek Polacek <polacek@redhat.com>
PR c/68668 PR c/68668
......
...@@ -6933,11 +6933,14 @@ c_parser_alignof_expression (c_parser *parser) ...@@ -6933,11 +6933,14 @@ c_parser_alignof_expression (c_parser *parser)
for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
others. The name of the builtin is passed using BNAME parameter. others. The name of the builtin is passed using BNAME parameter.
Function returns true if there were no errors while parsing and Function returns true if there were no errors while parsing and
stores the arguments in CEXPR_LIST. */ stores the arguments in CEXPR_LIST. If it returns true,
*OUT_CLOSE_PAREN_LOC is written to with the location of the closing
parenthesis. */
static bool static bool
c_parser_get_builtin_args (c_parser *parser, const char *bname, c_parser_get_builtin_args (c_parser *parser, const char *bname,
vec<c_expr_t, va_gc> **ret_cexpr_list, vec<c_expr_t, va_gc> **ret_cexpr_list,
bool choose_expr_p) bool choose_expr_p,
location_t *out_close_paren_loc)
{ {
location_t loc = c_parser_peek_token (parser)->location; location_t loc = c_parser_peek_token (parser)->location;
vec<c_expr_t, va_gc> *cexpr_list; vec<c_expr_t, va_gc> *cexpr_list;
...@@ -6955,6 +6958,7 @@ c_parser_get_builtin_args (c_parser *parser, const char *bname, ...@@ -6955,6 +6958,7 @@ c_parser_get_builtin_args (c_parser *parser, const char *bname,
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
{ {
*out_close_paren_loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser); c_parser_consume_token (parser);
return true; return true;
} }
...@@ -6974,6 +6978,7 @@ c_parser_get_builtin_args (c_parser *parser, const char *bname, ...@@ -6974,6 +6978,7 @@ c_parser_get_builtin_args (c_parser *parser, const char *bname,
vec_safe_push (cexpr_list, expr); vec_safe_push (cexpr_list, expr);
} }
*out_close_paren_loc = c_parser_peek_token (parser)->location;
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
return false; return false;
...@@ -7594,11 +7599,13 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -7594,11 +7599,13 @@ c_parser_postfix_expression (c_parser *parser)
vec<c_expr_t, va_gc> *cexpr_list; vec<c_expr_t, va_gc> *cexpr_list;
c_expr_t *e1_p, *e2_p, *e3_p; c_expr_t *e1_p, *e2_p, *e3_p;
tree c; tree c;
location_t close_paren_loc;
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (!c_parser_get_builtin_args (parser, if (!c_parser_get_builtin_args (parser,
"__builtin_choose_expr", "__builtin_choose_expr",
&cexpr_list, true)) &cexpr_list, true,
&close_paren_loc))
{ {
expr.value = error_mark_node; expr.value = error_mark_node;
break; break;
...@@ -7626,6 +7633,7 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -7626,6 +7633,7 @@ c_parser_postfix_expression (c_parser *parser)
" a constant"); " a constant");
constant_expression_warning (c); constant_expression_warning (c);
expr = integer_zerop (c) ? *e3_p : *e2_p; expr = integer_zerop (c) ? *e3_p : *e2_p;
set_c_expr_source_range (&expr, loc, close_paren_loc);
break; break;
} }
case RID_TYPES_COMPATIBLE_P: case RID_TYPES_COMPATIBLE_P:
...@@ -7677,11 +7685,13 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -7677,11 +7685,13 @@ c_parser_postfix_expression (c_parser *parser)
vec<c_expr_t, va_gc> *cexpr_list; vec<c_expr_t, va_gc> *cexpr_list;
c_expr_t *e2_p; c_expr_t *e2_p;
tree chain_value; tree chain_value;
location_t close_paren_loc;
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (!c_parser_get_builtin_args (parser, if (!c_parser_get_builtin_args (parser,
"__builtin_call_with_static_chain", "__builtin_call_with_static_chain",
&cexpr_list, false)) &cexpr_list, false,
&close_paren_loc))
{ {
expr.value = error_mark_node; expr.value = error_mark_node;
break; break;
...@@ -7710,17 +7720,20 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -7710,17 +7720,20 @@ c_parser_postfix_expression (c_parser *parser)
"must be a pointer type"); "must be a pointer type");
else else
CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value; CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value;
set_c_expr_source_range (&expr, loc, close_paren_loc);
break; break;
} }
case RID_BUILTIN_COMPLEX: case RID_BUILTIN_COMPLEX:
{ {
vec<c_expr_t, va_gc> *cexpr_list; vec<c_expr_t, va_gc> *cexpr_list;
c_expr_t *e1_p, *e2_p; c_expr_t *e1_p, *e2_p;
location_t close_paren_loc;
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (!c_parser_get_builtin_args (parser, if (!c_parser_get_builtin_args (parser,
"__builtin_complex", "__builtin_complex",
&cexpr_list, false)) &cexpr_list, false,
&close_paren_loc))
{ {
expr.value = error_mark_node; expr.value = error_mark_node;
break; break;
...@@ -7765,11 +7778,12 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -7765,11 +7778,12 @@ c_parser_postfix_expression (c_parser *parser)
} }
pedwarn_c90 (loc, OPT_Wpedantic, pedwarn_c90 (loc, OPT_Wpedantic,
"ISO C90 does not support complex types"); "ISO C90 does not support complex types");
expr.value = build2 (COMPLEX_EXPR, expr.value = build2_loc (loc, COMPLEX_EXPR,
build_complex_type build_complex_type
(TYPE_MAIN_VARIANT (TYPE_MAIN_VARIANT
(TREE_TYPE (e1_p->value))), (TREE_TYPE (e1_p->value))),
e1_p->value, e2_p->value); e1_p->value, e2_p->value);
set_c_expr_source_range (&expr, loc, close_paren_loc);
break; break;
} }
case RID_BUILTIN_SHUFFLE: case RID_BUILTIN_SHUFFLE:
...@@ -7777,11 +7791,13 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -7777,11 +7791,13 @@ c_parser_postfix_expression (c_parser *parser)
vec<c_expr_t, va_gc> *cexpr_list; vec<c_expr_t, va_gc> *cexpr_list;
unsigned int i; unsigned int i;
c_expr_t *p; c_expr_t *p;
location_t close_paren_loc;
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (!c_parser_get_builtin_args (parser, if (!c_parser_get_builtin_args (parser,
"__builtin_shuffle", "__builtin_shuffle",
&cexpr_list, false)) &cexpr_list, false,
&close_paren_loc))
{ {
expr.value = error_mark_node; expr.value = error_mark_node;
break; break;
...@@ -7808,6 +7824,7 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -7808,6 +7824,7 @@ c_parser_postfix_expression (c_parser *parser)
"%<__builtin_shuffle%>"); "%<__builtin_shuffle%>");
expr.value = error_mark_node; expr.value = error_mark_node;
} }
set_c_expr_source_range (&expr, loc, close_paren_loc);
break; break;
} }
case RID_AT_SELECTOR: case RID_AT_SELECTOR:
......
2015-12-08 David Malcolm <dmalcolm@redhat.com>
PR c/68757
* gcc.dg/plugin/diagnostic-test-expressions-1.c
(test_builtin_choose_expr): New test function.
(test_builtin_call_with_static_chain): Likewise.
(test_builtin_complex): Likewise.
(test_builtin_shuffle): Likewise.
2015-12-08 Jiong Wang <jiong.wang@arm.com> 2015-12-08 Jiong Wang <jiong.wang@arm.com>
* gcc.target/aarch64/got_mem_hoist_1.c (dg-skip-if): Match big-endian * gcc.target/aarch64/got_mem_hoist_1.c (dg-skip-if): Match big-endian
......
...@@ -518,6 +518,56 @@ void test_builtin_offsetof (int i) ...@@ -518,6 +518,56 @@ void test_builtin_offsetof (int i)
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
} }
void test_builtin_choose_expr (int i)
{
__emit_expression_range (0, __builtin_choose_expr (1, i, i) + i); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
__emit_expression_range (0, __builtin_choose_expr (1, i, i) + i);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
{ dg-end-multiline-output "" } */
__emit_expression_range (0, i + __builtin_choose_expr (1, i, i)); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
__emit_expression_range (0, i + __builtin_choose_expr (1, i, i));
~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
extern int f (int);
void test_builtin_call_with_static_chain (int i, void *ptr)
{
__emit_expression_range (0, __builtin_call_with_static_chain (f (i), ptr)); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
__emit_expression_range (0, __builtin_call_with_static_chain (f (i), ptr));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
void test_builtin_complex (float i, float j)
{
__emit_expression_range (0, __builtin_complex (i, j) ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
__emit_expression_range (0, __builtin_complex (i, j) );
^~~~~~~~~~~~~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
typedef int v4si __attribute__ ((vector_size (16)));
void test_builtin_shuffle (v4si a, v4si b, v4si mask)
{
__emit_expression_range (0, __builtin_shuffle (a, mask) ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
__emit_expression_range (0, __builtin_shuffle (a, mask) );
^~~~~~~~~~~~~~~~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
__emit_expression_range (0, __builtin_shuffle (a, b, mask) ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
__emit_expression_range (0, __builtin_shuffle (a, b, mask) );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
/* Examples of non-trivial expressions. ****************************/ /* Examples of non-trivial expressions. ****************************/
extern double sqrt (double x); extern double sqrt (double x);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment