Bug 52399 - -Wclobbered should be a common option rather than a C family specific option
Summary: -Wclobbered should be a common option rather than a C family specific option
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, lto
Depends on:
Blocks:
 
Reported: 2012-02-27 10:06 UTC by Dmitry Gorbachev
Modified: 2021-08-25 23:36 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-02-27 00:00:00


Attachments
Invalid code (162 bytes, text/plain)
2012-02-27 10:06 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2012-02-27 10:06:26 UTC
Created attachment 26761 [details]
Invalid code

$ gcc -flto -O -Wall -Wno-clobbered pr52399.c
In file included from pr52399.c:3:0,
                 from :6:
pr52399.c: In function 'main':
pr52399.c:8:7: warning: variable 'i' might be clobbered by 'longjmp' or 'vfork' [-Wclobbered]
Comment 1 Richard Biener 2012-02-27 11:16:47 UTC
Confirmed.  This is because Wclobbered is a C family option but the warning
is generated by middle-end code.  lto1 would simply ignore -Wno-clobbered.
-Wall is also a C family option and so ignored by lto1 btw. -Wall would need
to be split up in parts for lto option processing.
Comment 2 Manuel López-Ibáñez 2012-02-27 14:03:06 UTC
(In reply to comment #1)
> Confirmed.  This is because Wclobbered is a C family option but the warning
> is generated by middle-end code.  lto1 would simply ignore -Wno-clobbered.
> -Wall is also a C family option and so ignored by lto1 btw. -Wall would need
> to be split up in parts for lto option processing.

In this testcase, -Wall is a red-herring, it doesn't affect -Wclobbered.

You get the same warning with:
$ gcc -flto -O pr52399.c

the reason is that -Wclobbered is initialized to -1, but only set to its default value in c_common_post_options, which I guess lto1 does not call.

I guess the simplest fix is to make it a Common option and move the initialization to finish_options. I am not sure whether it is possible to make an option C/C++/LTO only.

In an ideal world, GCC options would have some kind of namespace, so one could not use an option in the middle-end without specifying that it is handled by LTO.

Ideally, GCC should also initialize options to their default value, instead of using the -1 trick to check whether the option was set by the user. I am not sure there is a mechanism yet to do this. This will have avoided this bug.
Comment 3 Andrew Pinski 2021-08-25 23:36:51 UTC
So the warning does not happen any more with -flto but does -W does not enable it either.

c-family/c.opt has:
Wclobbered
C ObjC C++ ObjC++ Var(warn_clobbered) Warning EnabledBy(Wextra)
Warn about variables that might be changed by \"longjmp\" or \"vfork\".

Maybe this should move to common.opt like the other middle-end warnings.