diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2020-10-28 18:41:24 +0100 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2020-10-28 18:41:24 +0100 |
commit | bf6dad60c338a42a7fb85f7b2a5870c0fb2e20f8 (patch) | |
tree | e513781ef717465e7db0358e987a5a6cbef5665c /gcc/c-family | |
parent | 0c261d5b5c931d9e9214d06531bdc7e9e16aeaab (diff) | |
parent | 47d13acbda9a5d8eb57ff169ba74857cd54108e4 (diff) | |
download | gcc-bf6dad60c338a42a7fb85f7b2a5870c0fb2e20f8.zip gcc-bf6dad60c338a42a7fb85f7b2a5870c0fb2e20f8.tar.gz gcc-bf6dad60c338a42a7fb85f7b2a5870c0fb2e20f8.tar.bz2 |
Merge branch 'master' into devel/coarray_native.
Merge into devel/coarray_native to prepare for later merging of
coarray_native with master.
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 84 | ||||
-rw-r--r-- | gcc/c-family/c-attribs.c | 63 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 4 | ||||
-rw-r--r-- | gcc/c-family/c-common.def | 3 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 1 | ||||
-rw-r--r-- | gcc/c-family/c-cppbuiltin.c | 8 | ||||
-rw-r--r-- | gcc/c-family/c-gimplify.c | 12 | ||||
-rw-r--r-- | gcc/c-family/c-pretty-print.c | 59 | ||||
-rw-r--r-- | gcc/c-family/c-warn.c | 52 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 16 |
10 files changed, 274 insertions, 28 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index bc002cf..27a59c2 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,87 @@ +2020-10-23 Jan Hubicka <hubicka@ucw.cz> + + * c-common.c (c_common_finalize_early_debug): Update for new thunk api. + +2020-10-23 Marek Polacek <polacek@redhat.com> + + PR c++/91741 + * c-common.c (verify_tree): Handle PAREN_SIZEOF_EXPR. + (c_common_init_ts): Likewise. + * c-common.def (PAREN_SIZEOF_EXPR): New tree code. + * c-common.h (maybe_warn_sizeof_array_div): Declare. + * c-warn.c (sizeof_pointer_memaccess_warning): Unwrap NOP_EXPRs. + (maybe_warn_sizeof_array_div): New function. + * c.opt (Wsizeof-array-div): New option. + +2020-10-23 Martin Sebor <msebor@redhat.com> + + PR c/97463 + * c-warn.c (warn_parm_ptrarray_mismatch): Move null test earlier. + +2020-10-22 Martin Liska <mliska@suse.cz> + + PR c/94722 + * c-attribs.c (handle_no_stack_protect_function_attribute): New. + (handle_stack_protect_attribute): Add error message for a + no_stack_protector function. + +2020-10-22 Martin Liska <mliska@suse.cz> + + * c-cppbuiltin.c (c_cpp_builtins): Use the stack_protector enum. + +2020-10-22 Jan Hubicka <hubicka@ucw.cz> + + * c-gimplify.c: Include tree-nested.h + (c_genericize): Update for new nested function info. + +2020-10-14 Martin Sebor <msebor@redhat.com> + + PR c/97413 + * c-attribs.c (build_attr_access_from_parms): Wrap chain of VLA + bounds in an extra list. + +2020-10-05 Richard Biener <rguenther@suse.de> + Jakub Jelinek <jakub@redhat.com> + + PR c++/97197 + * c-pretty-print.c: Include langhooks.h. + (c_pretty_printer::postfix_expression): Handle TARGET_MEM_REF as + expression. + (c_pretty_printer::expression): Handle TARGET_MEM_REF as + unary_expression. + (c_pretty_printer::unary_expression): Handle TARGET_MEM_REF. + +2020-09-30 Martin Sebor <msebor@redhat.com> + + PR middle-end/97189 + * c-attribs.c (append_access_attr): Use the function declaration + location for a warning about an attribute access argument. + +2020-09-29 Marek Polacek <polacek@redhat.com> + + PR c++/94695 + * c.opt (Wrange-loop-construct): New option. + +2020-09-23 Martin Sebor <msebor@redhat.com> + + PR c/97131 + * c-warn.c (warn_parm_ptrarray_mismatch): Handle more invalid input. + +2020-09-23 Marek Polacek <polacek@redhat.com> + + PR c/97125 + * c-gimplify.c (c_genericize): Only call do_warn_duplicated_branches_r + after loops and other structured control constructs have been lowered. + +2020-09-22 Jakub Jelinek <jakub@redhat.com> + + * c.opt (Wbuiltin-declaration-mismatch): Fix typo in variable name: + warn_builtin_declaraion_mismatch -> warn_builtin_declaration_mismatch. + +2020-09-21 Marek Polacek <polacek@redhat.com> + + * c.opt (Wctad-maybe-unsupported): New option. + 2020-09-19 Martin Sebor <msebor@redhat.com> PR c/50584 diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 70b0003..a3b2b3d 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -65,6 +65,8 @@ static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int, static tree handle_asan_odr_indicator_attribute (tree *, tree, tree, int, bool *); static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *); +static tree handle_no_stack_protector_function_attribute (tree *, tree, + tree, int, bool *); static tree handle_noinline_attribute (tree *, tree, tree, int, bool *); static tree handle_noclone_attribute (tree *, tree, tree, int, bool *); static tree handle_nocf_check_attribute (tree *, tree, tree, int, bool *); @@ -248,6 +250,14 @@ static const struct attribute_spec::exclusions attr_noinit_exclusions[] = ATTR_EXCL (NULL, false, false, false), }; +static const struct attribute_spec::exclusions attr_stack_protect_exclusions[] = +{ + ATTR_EXCL ("stack_protect", true, false, false), + ATTR_EXCL ("no_stack_protector", true, false, false), + ATTR_EXCL (NULL, false, false, false), +}; + + /* Table of machine-independent attributes common to all C-like languages. Current list of processed common attributes: nonnull. */ @@ -275,7 +285,11 @@ const struct attribute_spec c_common_attribute_table[] = { "volatile", 0, 0, true, false, false, false, handle_noreturn_attribute, NULL }, { "stack_protect", 0, 0, true, false, false, false, - handle_stack_protect_attribute, NULL }, + handle_stack_protect_attribute, + attr_stack_protect_exclusions }, + { "no_stack_protector", 0, 0, true, false, false, false, + handle_no_stack_protector_function_attribute, + attr_stack_protect_exclusions }, { "noinline", 0, 0, true, false, false, false, handle_noinline_attribute, attr_noinline_exclusions }, @@ -1156,6 +1170,22 @@ handle_stack_protect_attribute (tree *node, tree name, tree, int, return NULL_TREE; } +/* Handle a "no_stack_protector" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_no_stack_protector_function_attribute (tree *node, tree name, tree, + int, bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle a "noipa" attribute; arguments as in struct attribute_spec.handler. */ @@ -4151,18 +4181,12 @@ append_access_attr (tree node[3], tree attrs, const char *attrstr, "missing in previous designation", attrstr); else if (newa->internal_p || cura->internal_p) - { - /* Mismatch in the value of the size argument and a VLA - bound. */ - location_t argloc = curloc; - if (tree arg = get_argument (node[2], newa->sizarg)) - argloc = DECL_SOURCE_LOCATION (arg); - warned = warning_at (argloc, OPT_Wattributes, - "attribute %qs positional argument 2 " - "conflicts with previous designation " - "by argument %u", - attrstr, cura->sizarg + 1); - } + /* Mismatch in the value of the size argument and a VLA bound. */ + warned = warning_at (curloc, OPT_Wattributes, + "attribute %qs positional argument 2 " + "conflicts with previous designation " + "by argument %u", + attrstr, cura->sizarg + 1); else /* Mismatch in the value of the size argument between two explicit access attributes. */ @@ -4553,10 +4577,11 @@ handle_access_attribute (tree node[3], tree name, tree args, result in the following attribute access: value: "+^2[*],$0$1^3[*],$1$1" - chain: <0, x> <1, y> + list: < <0, x> <1, y> > - where each <node> on the chain corresponds to one VLA bound for each - of the two parameters. */ + where the list has a single value which itself is is a list each + of whose <node>s corresponds to one VLA bound for each of the two + parameters. */ tree build_attr_access_from_parms (tree parms, bool skip_voidptr) @@ -4660,13 +4685,17 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) if (!spec.length ()) return NULL_TREE; + /* Attribute access takes a two or three arguments. Wrap VBLIST in + another list in case it has more nodes than would otherwise fit. */ + vblist = build_tree_list (NULL_TREE, vblist); + /* Build a single attribute access with the string describing all array arguments and an optional list of any non-parameter VLA bounds in order. */ tree str = build_string (spec.length (), spec.c_str ()); tree attrargs = tree_cons (NULL_TREE, str, vblist); tree name = get_identifier ("access"); - return tree_cons (name, attrargs, NULL_TREE); + return build_tree_list (name, attrargs); } /* Handle a "nothrow" attribute; arguments as in diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index e16ca38..1787dfd 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1854,6 +1854,7 @@ verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp, { case CONSTRUCTOR: case SIZEOF_EXPR: + case PAREN_SIZEOF_EXPR: return; case COMPOUND_EXPR: @@ -8142,6 +8143,7 @@ void c_common_init_ts (void) { MARK_TS_EXP (SIZEOF_EXPR); + MARK_TS_EXP (PAREN_SIZEOF_EXPR); MARK_TS_EXP (C_MAYBE_CONST_EXPR); MARK_TS_EXP (EXCESS_PRECISION_EXPR); MARK_TS_EXP (BREAK_STMT); @@ -9132,7 +9134,7 @@ c_common_finalize_early_debug (void) functions that are still reachable at this point. */ struct cgraph_node *cnode; FOR_EACH_FUNCTION (cnode) - if (!cnode->alias && !cnode->thunk.thunk_p + if (!cnode->alias && !cnode->thunk && (cnode->has_gimple_body_p () || !DECL_IS_BUILTIN (cnode->decl))) (*debug_hooks->early_global_decl) (cnode->decl); } diff --git a/gcc/c-family/c-common.def b/gcc/c-family/c-common.def index 1954bfe..3d3e497 100644 --- a/gcc/c-family/c-common.def +++ b/gcc/c-family/c-common.def @@ -55,6 +55,9 @@ DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3) or for the purpose of -Wsizeof-pointer-memaccess warning. */ DEFTREECODE (SIZEOF_EXPR, "sizeof_expr", tcc_expression, 1) +/* Like above, but enclosed in parentheses. Used to suppress warnings. */ +DEFTREECODE (PAREN_SIZEOF_EXPR, "paren_sizeof_expr", tcc_expression, 1) + /* Used to represent a `for' statement. The operands are FOR_INIT_STMT, FOR_COND, FOR_EXPR, FOR_BODY, and FOR_SCOPE, respectively. */ diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 3d96092..bb38e6c 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1373,6 +1373,7 @@ extern void warn_for_omitted_condop (location_t, tree); extern bool warn_for_restrict (unsigned, tree *, unsigned); extern void warn_for_address_or_pointer_of_packed_member (tree, tree); extern void warn_parm_array_mismatch (location_t, tree, tree); +extern void maybe_warn_sizeof_array_div (location_t, tree, tree, tree, tree); /* Places where an lvalue, or modifiable lvalue, may be required. Used to select diagnostic messages in lvalue_error and diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index 74ecca8..e5ebb79 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -1427,13 +1427,13 @@ c_cpp_builtins (cpp_reader *pfile) /* Make the choice of the stack protector runtime visible to source code. The macro names and values here were chosen for compatibility with an earlier implementation, i.e. ProPolice. */ - if (flag_stack_protect == 4) + if (flag_stack_protect == SPCT_FLAG_EXPLICIT) cpp_define (pfile, "__SSP_EXPLICIT__=4"); - if (flag_stack_protect == 3) + if (flag_stack_protect == SPCT_FLAG_STRONG) cpp_define (pfile, "__SSP_STRONG__=3"); - if (flag_stack_protect == 2) + if (flag_stack_protect == SPCT_FLAG_ALL) cpp_define (pfile, "__SSP_ALL__=2"); - else if (flag_stack_protect == 1) + else if (flag_stack_protect == SPCT_FLAG_DEFAULT) cpp_define (pfile, "__SSP__=1"); if (flag_openacc) diff --git a/gcc/c-family/c-gimplify.c b/gcc/c-family/c-gimplify.c index 8b326c9..a7c0ec3 100644 --- a/gcc/c-family/c-gimplify.c +++ b/gcc/c-family/c-gimplify.c @@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "dumpfile.h" #include "c-ubsan.h" +#include "tree-nested.h" /* The gimplification pass converts the language-dependent trees (ld-trees) emitted by the parser into language-independent trees @@ -533,10 +534,6 @@ c_genericize (tree fndecl) &pset); } - if (warn_duplicated_branches) - walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl), - do_warn_duplicated_branches_r, NULL); - /* Genericize loops and other structured control constructs. The C++ front end has already done this in lang-specific code. */ if (!c_dialect_cxx ()) @@ -550,6 +547,10 @@ c_genericize (tree fndecl) pop_cfun (); } + if (warn_duplicated_branches) + walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl), + do_warn_duplicated_branches_r, NULL); + /* Dump the C-specific tree IR. */ dump_orig = get_dump_info (TDI_original, &local_dump_flags); if (dump_orig) @@ -572,7 +573,8 @@ c_genericize (tree fndecl) /* Dump all nested functions now. */ cgn = cgraph_node::get_create (fndecl); - for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested) + for (cgn = first_nested_function (cgn); + cgn; cgn = next_nested_function (cgn)) c_genericize (cgn->decl); } diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index acffd7b..8953e3b 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "tree-pretty-print.h" #include "selftest.h" +#include "langhooks.h" /* The pretty-printer code is primarily designed to closely follow (GNU) C and C++ grammars. That is to be contrasted with spaghetti @@ -1693,6 +1694,7 @@ c_pretty_printer::postfix_expression (tree e) break; case MEM_REF: + case TARGET_MEM_REF: expression (e); break; @@ -1859,6 +1861,62 @@ c_pretty_printer::unary_expression (tree e) } break; + case TARGET_MEM_REF: + /* TARGET_MEM_REF can't appear directly from source, but can appear + during late GIMPLE optimizations and through late diagnostic we might + need to support it. Print it as dereferencing of a pointer after + cast to the TARGET_MEM_REF type, with pointer arithmetics on some + pointer to single byte types, so + *(type *)((char *) ptr + step * index + index2) if all the operands + are present and the casts are needed. */ + pp_c_star (this); + if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (e)))) == NULL_TREE + || !integer_onep (TYPE_SIZE_UNIT + (TREE_TYPE (TREE_TYPE (TMR_BASE (e)))))) + { + if (TYPE_SIZE_UNIT (TREE_TYPE (e)) + && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (e)))) + { + pp_c_left_paren (this); + pp_c_type_cast (this, build_pointer_type (TREE_TYPE (e))); + } + else + { + pp_c_type_cast (this, build_pointer_type (TREE_TYPE (e))); + pp_c_left_paren (this); + pp_c_type_cast (this, build_pointer_type (char_type_node)); + } + } + else if (!lang_hooks.types_compatible_p + (TREE_TYPE (e), TREE_TYPE (TREE_TYPE (TMR_BASE (e))))) + { + pp_c_type_cast (this, build_pointer_type (TREE_TYPE (e))); + pp_c_left_paren (this); + } + else + pp_c_left_paren (this); + pp_c_cast_expression (this, TMR_BASE (e)); + if (TMR_STEP (e) && TMR_INDEX (e)) + { + pp_plus (this); + pp_c_cast_expression (this, TMR_INDEX (e)); + pp_c_star (this); + pp_c_cast_expression (this, TMR_STEP (e)); + } + if (TMR_INDEX2 (e)) + { + pp_plus (this); + pp_c_cast_expression (this, TMR_INDEX2 (e)); + } + if (!integer_zerop (TMR_OFFSET (e))) + { + pp_plus (this); + pp_c_integer_constant (this, + fold_convert (ssizetype, TMR_OFFSET (e))); + } + pp_c_right_paren (this); + break; + case REALPART_EXPR: case IMAGPART_EXPR: pp_c_ws_string (this, code == REALPART_EXPR ? "__real__" : "__imag__"); @@ -2295,6 +2353,7 @@ c_pretty_printer::expression (tree e) case ADDR_EXPR: case INDIRECT_REF: case MEM_REF: + case TARGET_MEM_REF: case NEGATE_EXPR: case BIT_NOT_EXPR: case TRUTH_NOT_EXPR: diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index d6db85b..68b093e 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -3177,6 +3177,10 @@ warn_parm_ptrarray_mismatch (location_t origloc, tree curparms, tree newparms) { curtyp = TREE_TYPE (curtyp); newtyp = TREE_TYPE (newtyp); + + if (!newtyp) + /* Bail on error. */ + return; } while (TREE_CODE (curtyp) == POINTER_TYPE && TREE_CODE (newtyp) == POINTER_TYPE); @@ -3186,6 +3190,7 @@ warn_parm_ptrarray_mismatch (location_t origloc, tree curparms, tree newparms) { if (curtyp == error_mark_node || newtyp == error_mark_node) + /* Bail on error. */ return; continue; @@ -3660,3 +3665,50 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms) inform (origloc, "previously declared as %s", curparmstr.c_str ()); } } + +/* Warn about divisions of two sizeof operators when the first one is applied + to an array and the divisor does not equal the size of the array element. + For instance: + + sizeof (ARR) / sizeof (OP) + + ARR is the array argument of the first sizeof, ARR_TYPE is its ARRAY_TYPE. + OP1 is the whole second SIZEOF_EXPR, or its argument; TYPE1 is the type + of the second argument. */ + +void +maybe_warn_sizeof_array_div (location_t loc, tree arr, tree arr_type, + tree op1, tree type1) +{ + tree elt_type = TREE_TYPE (arr_type); + + if (!warn_sizeof_array_div + /* Don't warn on multidimensional arrays. */ + || TREE_CODE (elt_type) == ARRAY_TYPE) + return; + + if (!tree_int_cst_equal (TYPE_SIZE (elt_type), TYPE_SIZE (type1))) + { + auto_diagnostic_group d; + if (warning_at (loc, OPT_Wsizeof_array_div, + "expression does not compute the number of " + "elements in this array; element type is " + "%qT, not %qT", elt_type, type1)) + { + if (EXPR_HAS_LOCATION (op1)) + { + location_t op1_loc = EXPR_LOCATION (op1); + gcc_rich_location richloc (op1_loc); + richloc.add_fixit_insert_before (op1_loc, "("); + richloc.add_fixit_insert_after (op1_loc, ")"); + inform (&richloc, "add parentheses around %qE to " + "silence this warning", op1); + } + else + inform (loc, "add parentheses around the second %<sizeof%> " + "to silence this warning"); + if (DECL_P (arr)) + inform (DECL_SOURCE_LOCATION (arr), "array %qD declared here", arr); + } + } +} diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 7a61351..1009def 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -371,7 +371,7 @@ C ObjC C++ ObjC++ Var(warn_frame_address) Warning LangEnabledBy(C ObjC C++ ObjC+ Warn when __builtin_frame_address or __builtin_return_address is used unsafely. Wbuiltin-declaration-mismatch -C ObjC C++ ObjC++ Var(warn_builtin_declaraion_mismatch) Init(1) Warning +C ObjC C++ ObjC++ Var(warn_builtin_declaration_mismatch) Init(1) Warning Warn when a built-in function is declared with the wrong signature. Wbuiltin-macro-redefined @@ -475,6 +475,11 @@ Wcpp C ObjC C++ ObjC++ CppReason(CPP_W_WARNING_DIRECTIVE) ; Documented in common.opt +Wctad-maybe-unsupported +C++ ObjC++ Var(warn_ctad_maybe_unsupported) Warning +Warn when performing class template argument deduction on a type with no +deduction guides. + Wctor-dtor-privacy C++ ObjC++ Var(warn_ctor_dtor_privacy) Warning Warn when all constructors and destructors are private. @@ -795,6 +800,10 @@ Wpacked-not-aligned C ObjC C++ ObjC++ Var(warn_packed_not_aligned) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn when fields in a struct with the packed attribute are misaligned. +Wrange-loop-construct +C++ ObjC++ Var(warn_range_loop_construct) Warning LangEnabledBy(C++ ObjC++,Wall) +Warn when a range-based for-loop is creating unnecessary copies. + Wredundant-tags C++ ObjC++ Var(warn_redundant_tags) Warning Warn when a class or enumerated type is referenced using a redundant class-key. @@ -807,6 +816,11 @@ Wsizeof-pointer-div C ObjC C++ ObjC++ Var(warn_sizeof_pointer_div) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn about suspicious divisions of two sizeof expressions that don't work correctly with pointers. +Wsizeof-array-div +C ObjC C++ ObjC++ Var(warn_sizeof_array_div) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) +Warn about divisions of two sizeof operators when the first one is applied +to an array and the divisor does not equal the size of the array element. + Wsizeof-pointer-memaccess C ObjC C++ ObjC++ Var(warn_sizeof_pointer_memaccess) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn about suspicious length parameters to certain string functions if the argument uses sizeof. |