Gentoo Archives: gentoo-dev

From: Richard Yao <ryao@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Changing policy about -Werror
Date: Fri, 14 Sep 2018 17:09:17
Message-Id: 83a143b2-6e45-a01d-9820-533129789727@gentoo.org
In Reply to: Re: [gentoo-dev] Changing policy about -Werror by Georg Rudoy <0xd34df00d@gmail.com>
1 > On Sep 13, 2018, at 8:54 PM, Georg Rudoy <0xd34df00d@×××××.com> wrote:
2 >
3 >> On 14.09.2018 at 0:44 user Richard Yao <ryao@g.o> wrote:
4 >> This is a really odd design decision by the GCC developers. With other compilers, the separation between front end and backend is strong enough that you will never have this sort of thing. It does not seem necessary to me either. :/
5 I didn't want to get into this, but GCC's backend is actually split into
6 a middle-end, that does architecture independent optimizations and a
7 backend, that generates assembly code (and likely does architecture
8 specific optimization):
9
10 https://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Architecture
11
12 You can get it to dump what appears to be the input to the middle end by
13 doing -fdump-translation-unit. You can get GCC to dump each stage of the
14 middle end using -fdump-tree-all. Presumably, any warnings that depend
15 on optimization won't be generated, although someone would need to study
16 the code to verify that.
17
18 I suspect quite a few people talking about what -Werror -Wall does have
19 never actually touched the internals of a compiler and perhaps that
20 should change. I won't claim to be an expert, but I have minor
21 experience with front-end development, writing code to do error
22 generation, etcetera. Honestly, when I first looked at GCC's sources, I
23 decided that I would be happier never looking at them ever again, but I
24 am starting to reconsider that decision.
25 >
26 > You might be able to perform certain additional data/control flow analysis after things like inlining, dead code removal or devirtualization.
27 Do you have any examples? I am having some trouble making a test case
28 that shows a different in behavior at different optimization levels
29 either way.
30
31 Here is an example:
32
33 __attribute__((always_inline))
34 static inline int
35 test(int x) {
36 return x;
37 }
38
39 int main() {
40 int x;
41
42 return (test(x)*0);
43 }
44
45 GCC 7.3.0 will emit a warning regardless of optimization level provided
46 that -Wall is passed. However, it will not emit a warning for this at
47 any optimization level:
48
49 int main() {
50 int x;
51
52 return (x*0);
53 }
54
55 >
56 > Moving that logic to the frontend would require essentially duplicating what's the optimizer's gonna do anyway, which might have negative effects on compilation times (both with and without optimizations) and compiler code maintenance.
57 If it is easier to use the optimizer's infrastructure to figure this
58 out, then the code could be written to call it to do analysis as a
59 pseudo-optimization pass, which GCC actually appears to do when it runs
60 its "Function test" "optimization" pass. There is no code maintenance
61 burden.
62
63 Fabian was right about needing -Wall for -Werror to catch many things
64 because most warnings are off by default. However, I am extremely
65 skeptical that the optimization level has significant error. -Wall gives
66 us whatever we need and so far, I cannot find a code example showing
67 differences in warning generation at different optimization levels. I'll
68 accept the idea that the warning quality might change (although I don't
69 fully understand the reasoning for it) by the GCC documentation.
70
71 However, I find the idea that -O3 will make a warning appear that didn't
72 otherwise appear to be very difficult to accept. The documentation
73 claims that optimization passes can effect emission of warnings for
74 uninitialized variables, but the only way that I could imagine that
75 happening would be if an optimization pass made x*0 into 0 before the
76 code generating the warning is run. This is the complete opposite of
77 what is being claimed here. In some actual tests, I am unable to get GCC
78 to emit a warning for that at any optimization level. I am also unable
79 to get it to behave differently for uninitialized variables at different
80 optimization levels no matter what idea I try.
81 >
82 >
83 >
84 > --
85 > Georg Rudoy
86 >
87 >

Attachments

File name MIME type
signature.asc application/pgp-signature