Gentoo Archives: gentoo-dev

From: Richard Yao <ryao@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Changing policy about -Werror
Date: Fri, 14 Sep 2018 23:27:46
Message-Id: 60E4E63B-6582-4C4D-B20D-A791874ADE63@gentoo.org
In Reply to: Re: [gentoo-dev] Changing policy about -Werror by Sergei Trofimovich
1 > On Sep 14, 2018, at 7:07 PM, Sergei Trofimovich <slyfox@g.o> wrote:
2 >
3 > On Fri, 14 Sep 2018 11:54:57 -0400
4 > Richard Yao <ryao@g.o> wrote:
5 >
6 >>>> My read of this is that the warning occurs regardless of optimization level, but it could somehow be improved by optimization.
7 >>>>
8 >>>> As for the last, it is for uninitialized variable reads. However, I think you are misinterpreting the claim. The way that optimization level could affect warning generation would be if the warning generation came after optimization passes that could hide reads. That means that -O3 would prevent the warning.
9 > ...
10 >> Either provide code examples that generate warnings in a way that demonstrates that I am incorrect
11 >
12 > To make code behave differently it needs substantial amount of code
13 > to provide you an example. You need to him O2<->O3 behaviour delta
14 > after all. But I will try (for a different warning, it should not matter
15 > much).
16 Thanks. I had been incorrect about -O3 giving not us some additional information for warnings. My apologies for the confusion.
17 >
18 > Below is a reduced example of a larger C++ program.
19 > Many thanks to Ulya for providing recent example!
20 >
21 > In this example -O3 manages to inline/const-propagate deep enough
22 > and find out potential null-deref. -O2 was not able to do it.
23 >
24 > $ bash -x ./mk_.sh
25 > + LANG=C
26 > + g++-8.2.0 -O2 -c 1.cc -Wnull-dereference
27 > + g++-8.2.0 -O3 -c 1.cc -Wnull-dereference
28 > 1.cc: In function 'bool foo(std::vector<int>)':
29 > 1.cc:3:22: warning: null pointer dereference [-Wnull-dereference]
30 > typename h = e - d >> *g;
31 > ~~~~~~^~~~~
32 > 1.cc:3:22: warning: null pointer dereference [-Wnull-dereference]
33 > typename h = e - d >> *g;
34 > ~~~~~~^~~~~
35 >
36 > $ cat 1.cc
37 > #include <vector>
38 > template <typename a, typename b> a c(a d, a e, b f, int *g) {
39 > typename h = e - d >> *g;
40 > for (; h;) if (f(*d)) if (f(*d)) return d;
41 > return d;
42 > }
43 > template <typename i, typename b> i o(i d, i e, b f, int *g) {
44 > return c(d, e, f, g);
45 > }
46 > template <typename i, typename b> i oo(i d, i e, b f, int *g) {
47 > return c(d, e, f, g);
48 > }
49 > template <typename j, typename b> j k(j d, j e, b f, int *g) {
50 > return o(d, e, f, g);
51 > }
52 > template <typename j, typename b> j kk(j d, j e, b f, int *g) {
53 > return oo(d, e, f, g);
54 > }
55 > bool cmpp(int);
56 > bool foo(std::vector<int> l) {
57 > std::vector<int>::const_iterator ib,
58 > ie = l.end(), m, n = k(ib, ie, cmpp, 0) = kk(m, ie, cmpp, 0);
59 > return m == n;
60 > }
61 >
62 > --
63 >
64 > Sergei
65 >

Replies

Subject Author
Re: [gentoo-dev] Changing policy about -Werror "Chí-Thanh Christopher Nguyễn" <chithanh@g.o>