diff options
author | Martin Jambor <mjambor@suse.cz> | 2017-07-31 14:43:24 +0200 |
---|---|---|
committer | Martin Jambor <mjambor@suse.cz> | 2017-07-31 14:43:24 +0200 |
commit | b32f12dece884f1fa0f04c643a77105aff6ce8bc (patch) | |
tree | cdab5f10806561fc198f907299b0e55eb5701ef0 /gcc/c | |
parent | 166bec868d991fdf71f9a66f994e5977fcab4aa2 (diff) | |
parent | a168a775e93ec31ae743ad282d8e60fa1c116891 (diff) | |
download | gcc-gcn.tar.gz |
Merge branch 'master' into gcngcn
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 55 | ||||
-rw-r--r-- | gcc/c/c-convert.c | 1 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 14 | ||||
-rw-r--r-- | gcc/c/c-lang.c | 5 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 66 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 7 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 2 |
7 files changed, 132 insertions, 18 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 58d59a65871..aff4866d915 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,58 @@ +2017-07-31 Jan Hubicka <hubicka@ucw.cz> + Martin Liska <mliska@suse.cz> + + * c-typeck.c (c_finish_goto_label): Build gimple predict + stament. + +2017-07-31 Martin Liska <mliska@suse.cz> + + PR sanitize/81530 + * c-convert.c (convert): Guard condition with flag_sanitize_p + also with current_function_decl non-null equality. + * c-decl.c (grokdeclarator): Likewise. + * c-typeck.c (build_binary_op): Likewise. + +2017-07-25 Marek Polacek <polacek@redhat.com> + + * c-decl.c (grokfield): Remove local variable. + +2017-07-25 Marek Polacek <polacek@redhat.com> + + PR c/81364 + * c-parser.c (c_parser_else_body): Don't warn about multistatement + macro expansion if the body is in { }. + (c_parser_while_statement): Likewise. + (c_parser_for_statement): Likewise. + +2017-07-18 Nathan Sidwell <nathan@acm.org> + + * c-parser.c (c_parser_array_notation): Use TYPE_{MIN,MAX}_VALUE. + +2017-07-14 David Malcolm <dmalcolm@redhat.com> + + * c-decl.c (implicitly_declare): When suggesting a missing + #include, provide a fix-it hint. + +2017-07-06 David Malcolm <dmalcolm@redhat.com> + + * c-lang.c (selftest::run_c_tests): Move body to c_family_tests, + and call that instead. + * c-tree.h (selftest::run_c_tests): New decl. + +2017-06-26 Marek Polacek <polacek@redhat.com> + + PR c/80116 + * c-parser.c (c_parser_if_body): Set the location of the + body of the conditional after parsing all the labels. Call + warn_for_multistatement_macros. + (c_parser_else_body): Likewise. + (c_parser_switch_statement): Likewise. + (c_parser_while_statement): Likewise. + (c_parser_for_statement): Likewise. + (c_parser_statement): Add a default argument. Save the location + after labels have been parsed. + (c_parser_c99_block_statement): Likewise. + 2017-06-19 Richard Biener <rguenther@suse.de> * gimple-parser.c (c_parser_gimple_postfix_expression): Handle diff --git a/gcc/c/c-convert.c b/gcc/c/c-convert.c index 33c9143e354..bc649178f4c 100644 --- a/gcc/c/c-convert.c +++ b/gcc/c/c-convert.c @@ -108,6 +108,7 @@ convert (tree type, tree expr) case INTEGER_TYPE: case ENUMERAL_TYPE: if (sanitize_flags_p (SANITIZE_FLOAT_CAST) + && current_function_decl != NULL_TREE && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE && COMPLETE_TYPE_P (type)) { diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 317d5cdd099..a54e1218434 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -3386,8 +3386,14 @@ implicitly_declare (location_t loc, tree functionid) const char *header = header_for_builtin_fn (DECL_FUNCTION_CODE (decl)); if (header != NULL && warned) - inform (loc, "include %qs or provide a declaration of %qD", - header, decl); + { + rich_location richloc (line_table, loc); + maybe_add_include_fixit (&richloc, header); + inform_at_rich_loc + (&richloc, + "include %qs or provide a declaration of %qD", + header, decl); + } newtype = TREE_TYPE (decl); } } @@ -6046,6 +6052,7 @@ grokdeclarator (const struct c_declarator *declarator, this_size_varies = size_varies = true; warn_variable_length_array (name, size); if (sanitize_flags_p (SANITIZE_VLA) + && current_function_decl != NULL_TREE && decl_context == NORMAL) { /* Evaluate the array size only once. */ @@ -7553,10 +7560,9 @@ grokfield (location_t loc, that took root before someone noticed the bug... */ tree type = declspecs->type; - bool type_ok = RECORD_OR_UNION_TYPE_P (type); bool ok = false; - if (type_ok + if (RECORD_OR_UNION_TYPE_P (type) && (flag_ms_extensions || flag_plan9_extensions || !declspecs->typedef_p)) diff --git a/gcc/c/c-lang.c b/gcc/c/c-lang.c index 510b7e7de47..e05741dadba 100644 --- a/gcc/c/c-lang.c +++ b/gcc/c/c-lang.c @@ -58,7 +58,10 @@ namespace selftest { void run_c_tests (void) { - c_format_c_tests (); + /* Run selftests shared within the C family. */ + c_family_tests (); + + /* Additional C-specific tests. */ } } // namespace selftest diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 6f954f21fa2..16cd3579972 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1218,9 +1218,11 @@ static void c_parser_initval (c_parser *, struct c_expr *, static tree c_parser_compound_statement (c_parser *); static void c_parser_compound_statement_nostart (c_parser *); static void c_parser_label (c_parser *); -static void c_parser_statement (c_parser *, bool *); +static void c_parser_statement (c_parser *, bool *, location_t * = NULL); static void c_parser_statement_after_labels (c_parser *, bool *, vec<tree> * = NULL); +static tree c_parser_c99_block_statement (c_parser *, bool *, + location_t * = NULL); static void c_parser_if_statement (c_parser *, bool *, vec<tree> *); static void c_parser_switch_statement (c_parser *, bool *); static void c_parser_while_statement (c_parser *, bool, bool *); @@ -5204,9 +5206,11 @@ c_parser_label (c_parser *parser) implement -Wparentheses. */ static void -c_parser_statement (c_parser *parser, bool *if_p) +c_parser_statement (c_parser *parser, bool *if_p, location_t *loc_after_labels) { c_parser_all_labels (parser); + if (loc_after_labels) + *loc_after_labels = c_parser_peek_token (parser)->location; c_parser_statement_after_labels (parser, if_p, NULL); } @@ -5466,11 +5470,12 @@ c_parser_paren_condition (c_parser *parser) implement -Wparentheses. */ static tree -c_parser_c99_block_statement (c_parser *parser, bool *if_p) +c_parser_c99_block_statement (c_parser *parser, bool *if_p, + location_t *loc_after_labels) { tree block = c_begin_compound_stmt (flag_isoc99); location_t loc = c_parser_peek_token (parser)->location; - c_parser_statement (parser, if_p); + c_parser_statement (parser, if_p, loc_after_labels); return c_end_compound_stmt (loc, block, flag_isoc99); } @@ -5492,6 +5497,7 @@ c_parser_if_body (c_parser *parser, bool *if_p, { tree block = c_begin_compound_stmt (flag_isoc99); location_t body_loc = c_parser_peek_token (parser)->location; + location_t body_loc_after_labels = UNKNOWN_LOCATION; token_indent_info body_tinfo = get_token_indent_info (c_parser_peek_token (parser)); @@ -5508,11 +5514,18 @@ c_parser_if_body (c_parser *parser, bool *if_p, else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) add_stmt (c_parser_compound_statement (parser)); else - c_parser_statement_after_labels (parser, if_p); + { + body_loc_after_labels = c_parser_peek_token (parser)->location; + c_parser_statement_after_labels (parser, if_p); + } token_indent_info next_tinfo = get_token_indent_info (c_parser_peek_token (parser)); warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo); + if (body_loc_after_labels != UNKNOWN_LOCATION + && next_tinfo.type != CPP_SEMICOLON) + warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location, + if_tinfo.location, RID_IF); return c_end_compound_stmt (body_loc, block, flag_isoc99); } @@ -5530,6 +5543,7 @@ c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo, tree block = c_begin_compound_stmt (flag_isoc99); token_indent_info body_tinfo = get_token_indent_info (c_parser_peek_token (parser)); + location_t body_loc_after_labels = UNKNOWN_LOCATION; c_parser_all_labels (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) @@ -5542,11 +5556,19 @@ c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo, c_parser_consume_token (parser); } else - c_parser_statement_after_labels (parser, NULL, chain); + { + if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) + body_loc_after_labels = c_parser_peek_token (parser)->location; + c_parser_statement_after_labels (parser, NULL, chain); + } token_indent_info next_tinfo = get_token_indent_info (c_parser_peek_token (parser)); warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo); + if (body_loc_after_labels != UNKNOWN_LOCATION + && next_tinfo.type != CPP_SEMICOLON) + warn_for_multistatement_macros (body_loc_after_labels, next_tinfo.location, + else_tinfo.location, RID_ELSE); return c_end_compound_stmt (body_loc, block, flag_isoc99); } @@ -5732,7 +5754,13 @@ c_parser_switch_statement (c_parser *parser, bool *if_p) c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p); save_break = c_break_label; c_break_label = NULL_TREE; - body = c_parser_c99_block_statement (parser, if_p); + location_t loc_after_labels; + bool open_brace_p = c_parser_peek_token (parser)->type == CPP_OPEN_BRACE; + body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels); + location_t next_loc = c_parser_peek_token (parser)->location; + if (!open_brace_p && c_parser_peek_token (parser)->type != CPP_SEMICOLON) + warn_for_multistatement_macros (loc_after_labels, next_loc, switch_loc, + RID_SWITCH); c_finish_case (body, ce.original_type); if (c_break_label) { @@ -5783,7 +5811,9 @@ c_parser_while_statement (c_parser *parser, bool ivdep, bool *if_p) token_indent_info body_tinfo = get_token_indent_info (c_parser_peek_token (parser)); - body = c_parser_c99_block_statement (parser, if_p); + location_t loc_after_labels; + bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE); + body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels); c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true); add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); c_parser_maybe_reclassify_token (parser); @@ -5792,6 +5822,10 @@ c_parser_while_statement (c_parser *parser, bool ivdep, bool *if_p) = get_token_indent_info (c_parser_peek_token (parser)); warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo); + if (next_tinfo.type != CPP_SEMICOLON && !open_brace) + warn_for_multistatement_macros (loc_after_labels, next_tinfo.location, + while_tinfo.location, RID_WHILE); + c_break_label = save_break; c_cont_label = save_cont; } @@ -6076,7 +6110,9 @@ c_parser_for_statement (c_parser *parser, bool ivdep, bool *if_p) token_indent_info body_tinfo = get_token_indent_info (c_parser_peek_token (parser)); - body = c_parser_c99_block_statement (parser, if_p); + location_t loc_after_labels; + bool open_brace = c_parser_next_token_is (parser, CPP_OPEN_BRACE); + body = c_parser_c99_block_statement (parser, if_p, &loc_after_labels); if (is_foreach_statement) objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label); @@ -6089,6 +6125,10 @@ c_parser_for_statement (c_parser *parser, bool ivdep, bool *if_p) = get_token_indent_info (c_parser_peek_token (parser)); warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo); + if (next_tinfo.type != CPP_SEMICOLON && !open_brace) + warn_for_multistatement_macros (loc_after_labels, next_tinfo.location, + for_tinfo.location, RID_FOR); + c_break_label = save_break; c_cont_label = save_cont; } @@ -18201,18 +18241,18 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index, return error_mark_node; } - start_index = TYPE_MINVAL (array_type_domain); + start_index = TYPE_MIN_VALUE (array_type_domain); start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, start_index); - if (!TYPE_MAXVAL (array_type_domain) - || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain))) + if (!TYPE_MAX_VALUE (array_type_domain) + || !TREE_CONSTANT (TYPE_MAX_VALUE (array_type_domain))) { error_at (loc, "start-index and length fields necessary for " "using array notations in variable-length arrays"); c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); return error_mark_node; } - end_index = TYPE_MAXVAL (array_type_domain); + end_index = TYPE_MAX_VALUE (array_type_domain); end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index), end_index, integer_one_node); end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index); diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index ce25fae0b87..a8197eb768d 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -764,4 +764,11 @@ extern tree decl_constant_value_for_optimization (tree); extern vec<tree> incomplete_record_decls; +#if CHECKING_P +namespace selftest { + extern void run_c_tests (void); +} // namespace selftest +#endif /* #if CHECKING_P */ + + #endif /* ! GCC_C_TREE_H */ diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 4d067e96dd3..71d01350186 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9824,6 +9824,7 @@ c_finish_goto_label (location_t loc, tree label) return NULL_TREE; TREE_USED (decl) = 1; { + add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN)); tree t = build1 (GOTO_EXPR, void_type_node, decl); SET_EXPR_LOCATION (t, loc); return add_stmt (t); @@ -11838,6 +11839,7 @@ build_binary_op (location_t location, enum tree_code code, if (sanitize_flags_p ((SANITIZE_SHIFT | SANITIZE_DIVIDE | SANITIZE_FLOAT_DIVIDE)) + && current_function_decl != NULL_TREE && (doing_div_or_mod || doing_shift) && !require_constant_value) { |