Infrastructure & C front end changes for array parameter checking (PR c/50584).
authorMartin Sebor <msebor@redhat.com>
Sat, 19 Sep 2020 23:21:52 +0000 (17:21 -0600)
committerMartin Sebor <msebor@redhat.com>
Sat, 19 Sep 2020 23:34:31 +0000 (17:34 -0600)
commit6450f07388f9fe575a489c9309c36012b17b88b0
tree929351afdf436f119f15a3d37da96d3a0e3ae27c
parent3696a50beeb73f4ded8a584e76ee16f0bde109b9
Infrastructure & C front end changes for array parameter checking (PR c/50584).

gcc/ChangeLog:

PR c/50584
* attribs.c (decl_attributes): Also pass decl along with type
attributes to handlers.
(init_attr_rdwr_indices): Change second argument to attribute chain.
Handle internal attribute representation in addition to external.
(get_parm_access): New function.
(attr_access::to_internal_string): Define new member function.
(attr_access::to_external_string): Define new member function.
(attr_access::vla_bounds): Define new member function.
* attribs.h (struct attr_access): Declare new members.
(attr_access::from_mode_char): Define new member function.
(get_parm_access): Declare new function.
* calls.c (initialize_argument_information): Pass function type
attributes to init_attr_rdwr_indices.
* doc/invoke.texi (-Warray-parameter, -Wvla-parameter): Document.
* tree-pretty-print.c (dump_generic_node): Correct handling of
qualifiers.
* tree-ssa-uninit.c (maybe_warn_pass_by_reference): Same.
* tree.h (access_mode): Add new enumerator.

gcc/c-family/ChangeLog:

PR c/50584
* c-attribs.c (c_common_attribute_table): Add "arg spec" attribute.
(handle_argspec_attribute): New function.
(get_argument, get_argument_type): New functions.
(append_access_attrs): Add overload.  Handle internal attribute
representation in addition to external.
(handle_access_attribute): Handle internal attribute representation
in addition to external.
(build_attr_access_from_parms): New function.

gcc/c-family/ChangeLog:

PR c/50584
* c-common.h (warn_parm_array_mismatch): Declare new function.
(has_attribute): Move declaration of an existing function.
(build_attr_access_from_parms): Declare new function.
* c-warn.c (parm_array_as_string): Define new function.
(plus_one):  Define new function.
(warn_parm_ptrarray_mismatch): Define new function.
(warn_parm_array_mismatch):  Define new function.
(vla_bound_parm_decl): New function.
* c.opt (-Warray-parameter, -Wvla-parameter): New options.
* c-pretty-print.c (pp_c_type_qualifier_list): Don't print array type
qualifiers here...
(c_pretty_printer::direct_abstract_declarator): ...but instead print
them in brackets here.  Also print [static].  Strip extraneous
expressions from VLA bounds.

gcc/c/ChangeLog:

PR c/50584
* c-decl.c (lookup_last_decl): Define new function.
(c_decl_attributes): Call it.
(start_decl): Add argument and use it.
(finish_decl): Call build_attr_access_from_parms and decl_attributes.
(get_parm_array_spec): Define new function.
(push_parm_decl): Call get_parm_array_spec.
(start_function): Call warn_parm_array_mismatch.  Build attribute
access and add it to current function.
* c-parser.c (c_parser_declaration_or_fndef): Diagnose mismatches
in forms of array parameters.
* c-tree.h (start_decl): Add argument.

gcc/testsuite/ChangeLog:

PR c/50584
* gcc.dg/attr-access-read-write-2.c: Adjust text of expected message.
* c-c++-common/Warray-bounds-6.c: Correct C++ declaration, adjust
text of expected diagnostics.
* gcc.dg/Wbuiltin-declaration-mismatch-9.c: Prune expected warning.
* gcc.dg/Warray-parameter-2.c: New test.
* gcc.dg/Warray-parameter-3.c: New test.
* gcc.dg/Warray-parameter-4.c: New test.
* gcc.dg/Warray-parameter-5.c: New test.
* gcc.dg/Warray-parameter.c: New test.
* gcc.dg/Wvla-parameter-2.c: New test.
* gcc.dg/Wvla-parameter-3.c: New test.
* gcc.dg/Wvla-parameter.c: New test.
27 files changed:
gcc/attribs.c
gcc/attribs.h
gcc/c-family/c-attribs.c
gcc/c-family/c-common.h
gcc/c-family/c-pretty-print.c
gcc/c-family/c-warn.c
gcc/c-family/c.opt
gcc/c/c-decl.c
gcc/c/c-parser.c
gcc/c/c-tree.h
gcc/calls.c
gcc/doc/invoke.texi
gcc/testsuite/c-c++-common/Warray-bounds-6.c
gcc/testsuite/gcc.dg/Warray-parameter-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-parameter-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-parameter-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-parameter-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-parameter.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-9.c
gcc/testsuite/gcc.dg/Wvla-parameter-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wvla-parameter-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wvla-parameter-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wvla-parameter.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/attr-access-read-write-2.c
gcc/tree-pretty-print.c
gcc/tree-ssa-uninit.c
gcc/tree.h