diff options
author | Martin Uecker <uecker@tugraz.at> | 2023-07-27 13:41:33 +0200 |
---|---|---|
committer | Martin Uecker <uecker@tugraz.at> | 2023-11-11 10:37:46 +0100 |
commit | c58b426d64ac2513dc0ed19165740604e891e9df (patch) | |
tree | fb0ed672a677d1053af234821420b7460cd61504 /gcc/c-family/c-attribs.cc | |
parent | 391f9798b35ec75c1a49fb04610db5ab347e9d0d (diff) | |
download | gcc-c58b426d64ac2513dc0ed19165740604e891e9df.zip gcc-c58b426d64ac2513dc0ed19165740604e891e9df.tar.gz gcc-c58b426d64ac2513dc0ed19165740604e891e9df.tar.bz2 |
c: Synthesize nonnull attribute for parameters declared with static [PR110815]
Parameters declared with `static` are nonnull. We synthesize
an artifical nonnull attribute for such parameters to get the
same warnings and optimizations.
Bootstrapped and regression tested on x86.
PR c/110815
PR c/112428
gcc/c-family:
* c-attribs.cc (build_attr_access_from_parms): Synthesize
nonnull attribute for parameters declared with `static`.
gcc:
* gimple-ssa-warn-access.cc (pass_waccess::maybe_check_access_sizes):
remove warning for parameters declared with `static`.
gcc/testsuite:
* gcc.dg/Wnonnull-8.c: Adapt test.
* gcc.dg/Wnonnull-9.c: New test.
Diffstat (limited to 'gcc/c-family/c-attribs.cc')
-rw-r--r-- | gcc/c-family/c-attribs.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 754cdab..461732f 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -5349,6 +5349,7 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) arg2pos.put (arg, argpos); } + tree nnlist = NULL_TREE; argpos = 0; for (tree arg = parms; arg; arg = TREE_CHAIN (arg), ++argpos) { @@ -5382,6 +5383,11 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) tree str = TREE_VALUE (argspec); const char *s = TREE_STRING_POINTER (str); + /* Collect the list of nonnull arguments which use "[static ..]". */ + if (s != NULL && s[0] == '[' && s[1] == 's') + nnlist = tree_cons (NULL_TREE, build_int_cst (integer_type_node, + argpos + 1), nnlist); + /* Create the attribute access string from the arg spec string, optionally followed by position of the VLA bound argument if it is one. */ @@ -5449,6 +5455,10 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) if (!spec.length ()) return NULL_TREE; + /* If we have nonnull arguments, synthesize an attribute. */ + if (nnlist != NULL_TREE) + nnlist = build_tree_list (get_identifier ("nonnull"), nnlist); + /* 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); @@ -5459,7 +5469,7 @@ build_attr_access_from_parms (tree parms, bool skip_voidptr) tree str = build_string (spec.length (), spec.c_str ()); tree attrargs = tree_cons (NULL_TREE, str, vblist); tree name = get_identifier ("access"); - return build_tree_list (name, attrargs); + return tree_cons (name, attrargs, nnlist); } /* Handle a "nothrow" attribute; arguments as in |