Bug 82600 - [8 Regression] Address of local variable returned [-Werror=return-local-addr] when building mozilla-central
Summary: [8 Regression] Address of local variable returned [-Werror=return-local-addr]...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Jakub Jelinek
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2017-10-18 07:54 UTC by Andi
Modified: 2017-10-19 14:25 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-10-18 00:00:00


Attachments
preprocessed file (160.98 KB, application/gzip)
2017-10-18 09:05 UTC, Sylvestre Ledru
Details
gcc8-pr82600.patch (610 bytes, patch)
2017-10-18 10:30 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andi 2017-10-18 07:54:54 UTC
Building firefox with gcc8 trunk i get this error:

In file included from /root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/memory/build/Unified_cpp_memory_build0.cpp:2:0:
 /root/firefox-gcc-last/memory/build/mozjemalloc.cpp: In member function 'void** AddressRadixTree<Bits>::GetSlot(void*, bool)':
 /root/firefox-gcc-last/memory/build/mozjemalloc.cpp:1695:10: error: address of local variable 'node' returned [-Werror=return-local-addr]
    void** node;
           ^~~~
 cc1plus: all warnings being treated as errors

The entire context can be found here:
[1] http://searchfox.org/mozilla-central/rev/a984558fa2bbde6492d3fb918496fc0b0835b2ce/memory/build/mozjemalloc.cpp#1721
[2] http://searchfox.org/mozilla-central/rev/a984558fa2bbde6492d3fb918496fc0b0835b2ce/memory/build/mozjemalloc.cpp#1698 It can easily be seen that by just analysing [2] 'node' only points somewhere in 'mRoot'.
Comment 1 Jakub Jelinek 2017-10-18 08:01:25 UTC
Can you please attach preprocessed source + full g++ command line?  Thanks.
Comment 2 Sylvestre Ledru 2017-10-18 08:47:17 UTC
the command line:
/usr/bin/g++-8 -std=gnu++11 -o Unified_cpp_memory_build0.o -c -I/root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/dist/system_wrappers -include /root/firefox-gcc-last/config/gcc_hidden.h -DDEBUG=1 -DMOZ_MEMORY_IMPL -DMOZ_HAS_MOZGLUE -I/root/firefox-gcc-last/memory/build -I/root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/memory/build -I/root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/dist/include -I/root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/dist/include/nspr -I/root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/dist/include/nss  -fPIC  -DMOZILLA_CLIENT -include /root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/mozilla-config.h -MD -MP -MF .deps/Unified_cpp_memory_build0.o.pp  -Wall -Wc++11-compat -Wempty-body -Wignored-qualifiers -Woverloaded-virtual -Wpointer-arith -Wsign-compare -Wtype-limits -Wunreachable-code -Wwrite-strings -Wno-invalid-offsetof -Wc++14-compat -Wc++1z-compat -Wduplicated-cond -Wimplicit-fallthrough -Wno-error=maybe-uninitialized -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wformat -Wformat-overflow=2 -fno-exceptions -fno-strict-aliasing -fno-rtti -fno-exceptions -fno-math-errno -pthread -pipe  -g -freorder-blocks -Os -fno-omit-frame-pointer  -Werror -Wno-unused-function -Wno-error=uninitialized  -fdiagnostics-color  /root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/memory/build/Unified_cpp_memory_build0.cpp
Comment 3 Sylvestre Ledru 2017-10-18 09:05:08 UTC
Created attachment 42389 [details]
preprocessed file
Comment 4 Jakub Jelinek 2017-10-18 09:38:37 UTC
Seems to have started with r253599.  Will try to reduce it now.
Comment 5 Jakub Jelinek 2017-10-18 10:07:40 UTC
Reduced testcase:
void *b[10];

template <int N>
void **
foo (int x)
{
  void **a = b;
  return &a[x];
}

void **
bar (int x)
{
  return foo <0> (x);
}
Comment 6 Jakub Jelinek 2017-10-18 10:30:33 UTC
Created attachment 42392 [details]
gcc8-pr82600.patch

Untested fix.  The problem is that the -Wreturn-local-addr implementation requires full folding of the expressions such that it will actually not see
an ARRAY_REF if the corresponding DECL isn't an array, but a pointer.
Such folding isn't performed if processing_template_decl though (no folding is done, cp_fully_fold just returns the passed argument immediately).
Comment 7 Jonathan Wakely 2017-10-18 12:58:16 UTC
(In reply to Andi from comment #0)
> Building firefox with gcc8 trunk i get this error:

This is a warning, not an error. 

If you use -Werror to cause compilation to fail that's your choice, but it's still just a warning as far as we're concerned.

If you can't build because you choose to use -Werror then don't use -Werror.
Comment 8 Andi 2017-10-18 13:18:36 UTC
(In reply to Jonathan Wakely from comment #7)
> (In reply to Andi from comment #0)
> > Building firefox with gcc8 trunk i get this error:
> 
> This is a warning, not an error. 
> 
> If you use -Werror to cause compilation to fail that's your choice, but it's
> still just a warning as far as we're concerned.
> 
> If you can't build because you choose to use -Werror then don't use -Werror.
Indeed the build was ran with -Werror since we wanted to see what are our blockers.
Comment 9 Jakub Jelinek 2017-10-19 14:25:10 UTC
Author: jakub
Date: Thu Oct 19 14:24:39 2017
New Revision: 253899

URL: https://gcc.gnu.org/viewcvs?rev=253899&root=gcc&view=rev
Log:
	PR c++/82600
	* typeck.c (check_return_expr): Don't call
	maybe_warn_about_returning_address_of_local in templates.

	* g++.dg/warn/Wreturn-local-addr-4.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wreturn-local-addr-4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 10 Jakub Jelinek 2017-10-19 14:25:41 UTC
Fixed.