Bug 109792 - RFE: Warn about misuse of "pure" attribute
Summary: RFE: Warn about misuse of "pure" attribute
Status: RESOLVED DUPLICATE of bug 18487
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 14.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2023-05-09 18:05 UTC by Xi Ruoyao
Modified: 2023-05-09 18:07 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Xi Ruoyao 2023-05-09 18:05:39 UTC
I've spent several hours on https://github.com/systemd/systemd/pull/27595, which fixes a wrong use of the "pure" attribute.  Consider the following:

$ cat t.c
extern int t(const char *, int *);

int t(const char *a, int *b)
{
  if (!a)
    return 114;

  *b = __builtin_strlen(a);
  return 0;
}

$ gcc t.c -S -Wall -Wextra -Werror && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O1 && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O2 && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O3 && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O3 -fanalyzer && echo "no warning"
no warning

If we had a warning here, it would have saved me several hours :).
Comment 1 Andrew Pinski 2023-05-09 18:07:00 UTC
Dup of bug 18487.

*** This bug has been marked as a duplicate of bug 18487 ***