Bug 72813 - [6 Regression] atomic header cannot be compiled into translation unit with -fkeep-inline-functions
Summary: [6 Regression] atomic header cannot be compiled into translation unit with -f...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-08-05 12:13 UTC by Matthias Klose
Modified: 2018-10-26 11:17 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.4.0
Known to fail: 6.1.1, 7.0
Last reconfirmed: 2016-08-05 00:00:00


Attachments
gcc7-pr72813.patch (573 bytes, patch)
2017-01-10 09:19 UTC, Jakub Jelinek
Details | Diff
gcc7-pr72813-2.patch (718 bytes, patch)
2017-01-10 09:55 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2016-08-05 12:13:40 UTC
$ echo '#include <atomic>' > foo.h

$ gcc-6 -std=c++11 -fdump-translation-unit -fkeep-inline-functions -c -x c++-header -fpermissive -w -fPIC foo.h
In file included from /usr/include/c++/6/atomic:41:0,
                 from foo.h:1:
/usr/include/c++/6/bits/atomic_base.h: In member function 'std::atomic<bool>::operator bool() const':
/usr/include/c++/6/bits/atomic_base.h:390:7: error: inlining failed in call to always_inline 'std::__atomic_base<_IntTp>::__int_type std::__atomic_base<_IntTp>::load(std::memory_order) const noexcept [with _ITp = bool; std::__atomic_base<_IntTp>::__int_type = bool; std::memory_order = std::memory_order]': function body not available
       load(memory_order __m = memory_order_seq_cst) const noexcept
       ^~~~
In file included from foo.h:1:0:
/usr/include/c++/6/atomic:81:27: note: called from here
     { return _M_base.load(); }
                           ^

$ gcc-5 -std=c++11 -fdump-translation-unit -fkeep-inline-functions -c -x c++-header -fpermissive -w -fPIC foo.h
Comment 1 Jonathan Wakely 2016-08-05 12:20:22 UTC
The always_inline attributes were added by r198733
Comment 2 Jan Hubicka 2016-08-05 13:19:07 UTC
OK, the callee in question is:


std::__atomic_base<_IntTp>::__int_type std::__atomic_base<_IntTp>::load(std::memory_order) const [with _ITp = bool; std::__atomic_base<_IntTp>::__int_type = bool; std::memory_order = std::memory_order]/139 (std::__atomic_base<_IntTp>::__int_type std::__atomic_base<_IntTp>::load(std::memory_order) const [with _ITp = bool; std::__atomic_base<_IntTp>::__int_type = bool; std::memory_order = std::memory_order]) @0x7ffff6625e60
  Type: function
  Visibility: external public comdat visibility_specified
  References: 
  Referring: 
  First run: 0
  Function flags:
  Called by: 
  Calls: 

and it is indeed not defined. So it seems C++ FE thinks that the function is unused and never does cgraph_finalize?

Honza
Comment 3 Richard Biener 2016-08-22 08:26:36 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 4 Richard Biener 2016-08-22 08:27:42 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 5 Richard Biener 2016-08-22 08:48:43 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 6 Richard Biener 2016-08-22 08:50:08 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 7 Jakub Jelinek 2016-12-21 10:59:19 UTC
GCC 6.3 is being released, adjusting target milestone.
Comment 8 Jakub Jelinek 2017-01-10 09:19:48 UTC
Created attachment 40485 [details]
gcc7-pr72813.patch

I guess the resolution of this PR depends on what exactly should happen when creating PCH files.
On -x c-header or -x c++-header, with -E we just preprocess, nothing unexpected.
For -S without -o it has been broken for many years, only partially "fixed" in r237955, but that change only affected the non-save-temps path, with -save-temps -S still fails:
error: output filename specified twice
For -S with -o, or -save-temps and say -c or none of -E/-S/-c, we produced some assembly.

Now, the sources say:
/* This is the point to write out a PCH if we're doing that.
   In that case we do not want to do anything else.  */
and bails out early from those functions, but actually in the caller the compilation happily continues.

So, either the comment is wrong and we just want to produce full assembly (sometimes thrown away, because it is written into a temporary file, sometimes user visible), then we need something like the attached untested patch (plus perhaps the fixes for the -S -save-temps case).  This choice means creating of *.gch files might be slightly slower than now, but not significantly, because most of the work is done anyway, and also means that if there are some post-parsing reported errors, they will be diagnosed.

Or, we do what the comment says and e.g. set flag_syntax_only at that point before the early return, which means that even callers would do nothing else.  Compilation of PCH files would be faster, the assembly written would need to be declared to be unusable for anything, and perhaps some diagnostics would not be emitted if it would normally happen after the spot where we write the PCH file.
Comment 9 Jakub Jelinek 2017-01-10 09:55:26 UTC
Created attachment 40486 [details]
gcc7-pr72813-2.patch

The other option (on IRC Richard says *.s file for PCH doesn't make sense).
In the case the file remains (i.e. -S or -save-temps), it will contain just .file directive and nothing else.
Comment 10 Jakub Jelinek 2017-01-11 18:09:29 UTC
Author: jakub
Date: Wed Jan 11 18:08:57 2017
New Revision: 244328

URL: https://gcc.gnu.org/viewcvs?rev=244328&root=gcc&view=rev
Log:
	PR c++/72813
	* gcc.c (default_compilers): Don't add -o %g.s for -S -save-temps
	of c-header.

	* c-decl.c (pop_file_scope): Set flag_syntax_only to 1 after writing
	PCH file.

	* decl2.c (c_parse_final_cleanups): Set flag_syntax_only to 1 after
	writing PCH file.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-decl.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
    trunk/gcc/gcc.c
Comment 11 Jakub Jelinek 2017-01-11 20:32:17 UTC
Fixed on the trunk.
Comment 12 Richard Biener 2017-07-04 08:50:17 UTC
GCC 6.4 is being released, adjusting target milestone.
Comment 13 Jakub Jelinek 2018-10-26 11:17:04 UTC
GCC 6 branch is being closed, fixed in 7.x.