On Sun, Nov 13, 2022 at 10:41 AM Andrew Pinski <pins...@gmail.com> wrote: > > On Sun, Nov 13, 2022 at 10:40 AM Andrew Pinski <pins...@gmail.com> wrote: > > > > On Sun, Nov 13, 2022 at 10:36 AM Alejandro Colomar via Gcc > > <gcc@gcc.gnu.org> wrote: > > > > > > Hi, > > > > > > While discussing some idea for a new feature, I tested the following > > > example > > > program: > > > > > > > > > int main(void) > > > { > > > int i = i; > > > return i; > > > } > > > > This is NOT a bug but a documented way of having the warning not being > > there. > > See > > https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index-Winit-self > > https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index-Wuninitialized > > "If you want to warn about code that uses the uninitialized value of > > the variable in its own initializer, use the -Winit-self option." > > I should note the main reason why I Know about this is because I fixed > this feature years ago (at least for C front-end) > and added the option to disable the feature.
When I says years, it was 19 years ago even, see https://gcc.gnu.org/PR5582 and https://gcc.gnu.org/PR10538 and https://gcc.gnu.org/r0-52301-g3390f9c9bef0be Thanks, > > > > > Thanks, > > Andrew Pinski > > > > > > > > > > > It seems obvious that it should give a warning, and in Clang it does: > > > > > > > > > $ clang --version | head -n1 > > > Debian clang version 14.0.6 > > > > > > $ clang -Wall -Wextra foo.c > > > foo.c:3:10: warning: variable 'i' is uninitialized when used within > > > its own > > > initialization [-Wuninitialized] > > > int i = i; > > > ~ ^ > > > 1 warning generated. > > > > > > > > > But for GCC it looks fine: > > > > > > $ gcc --version | head -n1 > > > gcc (Debian 12.2.0-9) 12.2.0 > > > > > > $ gcc -Wall -Wextra foo.c > > > $ > > > > > > > > > Until you enable the analyzer, which catches the uninitialized use: > > > > > > > > > $ gcc -fanalyzer foo.c > > > foo.c: In function ‘main’: > > > foo.c:3:13: warning: use of uninitialized value ‘i’ [CWE-457] > > > [-Wanalyzer-use-of-uninitialized-value] > > > 3 | int i = i; > > > | ^ > > > ‘main’: events 1-2 > > > | > > > | 3 | int i = i; > > > | | ^ > > > | | | > > > | | (1) region created on stack here > > > | | (2) use of uninitialized value ‘i’ here > > > | > > > > > > > > > > > > I expect that GCC should be able to detect this bug with a simple > > > warning. The > > > analyzer is quite unreadable compared to normal warnings. > > > > > > Cheers, > > > Alex > > > > > > -- > > > <http://www.alejandro-colomar.es/>