[Bug c/45821] Missed -Wreturn-local-addr when local variable address comes from within a statement expression

2020-10-28 Thread philiprbrenan at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45821

Philip R Brenan  changed:

   What|Removed |Added

 CC||philiprbrenan at gmail dot com

--- Comment #7 from Philip R Brenan  ---
A more compact example:

#include 
int * aaa() {return ({int a = 2;});} // no warning unless -O2
int * bbb() { int b = 3; return }//warning

int main(void)
 {int *a = aaa(), *b = bbb();
  fprintf(stderr, " %d\n", *a);
  fprintf(stderr, " %d\n", *b);
  return 0;
 }
//  3
// Segmentation fault (core dumped)

Please provide the warning for line 2 (aaa) regardless of the level of
optimization?

[Bug c/97598] -Wself-init alone fails to warn of a pointless assignment

2020-10-27 Thread philiprbrenan at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97598

--- Comment #1 from Philip R Brenan  ---
Created attachment 49454
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49454=edit
Test case

[Bug c/97598] New: -Wself-init alone fails to warn of a pointless assignment

2020-10-27 Thread philiprbrenan at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97598

Bug ID: 97598
   Summary: -Wself-init alone fails to warn of a pointless
assignment
   Product: gcc
   Version: 10.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: philiprbrenan at gmail dot com
  Target Milestone: ---

Created attachment 49453
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49453=edit
-Wself-init alone fails to warn of a pointless assignment

The assignment int a = a; below does not create a warning to let me know that
the assignment is pointless even when I use -Winit-self  xor -Wall as per the
attached image.  The warning only appears if I enable both options.  This leads
to subtle errors in generated  ({ code ...}) constructs that are difficult to
debug.  Please add a warning for such pointless assignments that is enabled
with -Wall.

#include 
int main(void)
 {int   a = 1;
   {int a = a; // Pointless
printf(" %d\n", a);
   }
  printf(" %d\n", a);
 }
//  0
//  1

GCC details:

gcc -v -save-temps -Winit-self assign.c  
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
10.1.0-2ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-10-eDoCEC/gcc-10-10.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-eDoCEC/gcc-10-10.1.0/debian/tmp-gcn/usr,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.0 (Ubuntu 10.1.0-2ubuntu1~18.04) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Winit-self' '-mtune=generic'
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu
assign.c -mtune=generic -march=x86-64 -Winit-self -fpch-preprocess
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -o assign.i
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/10/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Winit-self' '-mtune=generic'
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/cc1 -fpreprocessed assign.i -quiet -dumpbase
assign.c -mtune=generic -march=x86-64 -auxbase assign -Winit-self -version
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -o assign.s
GNU C17 (Ubuntu 10.1.0-2ubuntu1~18.04) version 10.1.0 (x86_64-linux-gnu)
compiled by GNU C version 10.1.0, GMP version 6.1.2, MPFR version
4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (Ubuntu 10.1.0-2ubuntu1~18.04) version 10.1.0 (x86_64-linux-gnu)
compiled by GNU C version 10.1.0, GMP version 6.1.2, MPFR version
4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 797ff541be7d2acc7d0ced3c057e002c
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Winit-self' '-mtune=generic'
'-march=x86-64'
 as -v --64 -o assign.o assign.s
GNU assembler version 2.30 (x86_64-linux-gnu) using BFD version (GNU Binutils
for Ubuntu) 2.30
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/