Bug 114833 - --suggest-attribute=returns_nonnull misdiagnoses functions with __attribute__((returns_nonnull))
Summary: --suggest-attribute=returns_nonnull misdiagnoses functions with __attribute__...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2024-04-24 05:36 UTC by Paul Eggert
Modified: 2024-04-24 18:11 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Eggert 2024-04-24 05:36:40 UTC
This is gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0) on Fedora 40 x86-64. Put this code into the file t.i:

  extern char const *foo () __attribute__ ((returns_nonnull));
  char const *
  foo ()
  {
    return "abc";
  }

and compile it with:

  gcc -S -O2 -Wsuggest-attribute=returns_nonnull t.i

The output is:

  t.i: In function ‘foo’:
  t.i:3:3: warning: function might be candidate for attribute ‘returns_nonnull’ [-Wsuggest-attribute=returns_nonnull]
      3 |   foo ()
        |   ^~~

This diagnostic is obviously wrong, as foo is already declared with the suggested attribute.
Comment 1 Andrew Pinski 2024-04-24 17:32:05 UTC
Confirmed. The code which calls warn_function_returns_nonnull (or maybe warn_function_returns_nonnull should do the check) does not check for the attribute already there.
Comment 2 Andrew Pinski 2024-04-24 17:32:50 UTC
The code to do the warning was added with r14-5628-g53ba8d669550d3 .