On 4/13/21 10:07 AM, Jeff Law wrote:

On 4/8/2021 4:15 PM, Martin Sebor via Gcc-patches wrote:
The C front end ordinarily merges function type attributes upon
the redeclaration of a function but it doesn't do that for those
at local scope, unless the declaration refers to a built-in.

Because the new -Warray-parameter warning relies on the internal
access attribute on the type of the function added by the C front
end for parameters declared using the array notation, it triggers
when it sees a redeclaration of a function in a local scope even
when both declarations use the same array form, issuing a false
positive.

The same problem affects other similar redeclarations involving
attributes, such as unused_result, causing false negatives there.
(Clang and ICC behave as I expect.)

The attached patch lets the front end propagate the type attributes
for all redeclarations, resolving this class of problems for all
affected attributes.

There's another similar piece of code in pushdecl() that I didn't
touch, although  I couldn't come up with a test case showing it's
necessary.  Both hunks go back ages so I wonder if they might have
been obviated by other improvements.

What I'd want to know is why the code didn't copy the attributes to the redeclarations.  Did the git history provide any hints? Does the hunk of code post-date creation of the public lists?  If so, was there any discussion in the public lists of the change that might give insights?

The conditional the patch removes was added by Joseph in r86636 to
fix PR c/13801.  The bug deals with extern declarations in nested
scopes.  This issue is about declarations in unrelated scopes.

The (very long) discussion of the changes is below but I couldn't
find anything relevant to the problem(s) my change tries to solve:
https://gcc.gnu.org/legacy-ml/gcc-patches/2004-08/msg00085.html

FWIW, with or without my patch, GCC still isn't entirely consistent
in how it handles attributes on extern redeclarations in different
scopes, either with itself or with other compilers.

Martin

Reply via email to