Bug 96975 - gcc cannot compile at -O0 but compiles at -O1/-O2/-O3
Summary: gcc cannot compile at -O0 but compiles at -O1/-O2/-O3
Status: RESOLVED DUPLICATE of bug 91241
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-checking, link-failure
Depends on:
Blocks:
 
Reported: 2020-09-08 11:27 UTC by tangyixuan
Modified: 2020-09-11 13:08 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 11.0
Last reconfirmed: 2020-09-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tangyixuan 2020-09-08 11:27:09 UTC
Hi, the following code is not compiled with -O0, but is compiled with -O1/O2/O3.

$ cat s.cpp

typedef void (* A )();
template < A T > struct S { S (){}};
void T (){} S < T > a ;
int main (){
        void T ();
        S < T > a ;
}

$ g++ -c -O0 s.cpp
/tmp/cc1wgC6C.s:73: Error: symbol `_ZN14CXXRecordDeclAIXadL_Z13FunctionDeclAvEEEC2Ev' is already defined

$ g++ -c -O2 s.cpp
success.

$ clang++ -c -O0 s.cpp
success.
Comment 1 Richard Biener 2020-09-08 13:05:43 UTC
It also ICEs on trunk.  I think I've seen this ICE before so there might be a duplicate.

> ./cc1plus  -quiet t.ii -O0
t.ii:7:1: error: Two symbols with same comdat_group are not linked by the same_comdat_group list.
    7 | }
      | ^
_ZN1SIXadL_Z1TvEEEC1Ev/8 (S<T>::S() [with void (* T)() = T]) @0x7f30a353e9d8
  Type: function definition analyzed alias cpp_implicit_alias
  Visibility: public weak comdat comdat_group:_ZN1SIXadL_Z1TvEEEC5Ev one_only
  Same comdat group as: _ZN1SIXadL_Z1TvEEEC2Ev/7
  previous sharing asm name: 5
  References: _ZN1SIXadL_Z1TvEEEC2Ev/7 (alias) 
  Referring: 
  Function flags:
  Called by: main/2 
  Calls: 
_ZN1SIXadL_Z1TvEEEC1Ev/5 (S<T>::S() [with void (* T)() = T]) @0x7f30a353e5a0
  Type: function definition analyzed alias cpp_implicit_alias
  Visibility: public weak comdat comdat_group:_ZN1SIXadL_Z1TvEEEC5Ev one_only
  Same comdat group as: _ZN1SIXadL_Z1TvEEEC2Ev/4
  next sharing asm name: 8
  References: _ZN1SIXadL_Z1TvEEEC2Ev/4 (alias) 
  Referring: 
  Function flags:
  Called by: _Z41__static_initialization_and_destruction_0ii/9 
  Calls: 
t.ii:7:1: internal compiler error: symtab_node::verify failed
0xf55569 symtab_node::verify_symtab_nodes()
        /home/rguenther/src/gcc2/gcc/symtab.c:1368
0xf7f07c symtab_node::checking_verify_symtab_nodes()
        /home/rguenther/src/gcc2/gcc/cgraph.h:667
0xf7cec7 symbol_table::compile()
        /home/rguenther/src/gcc2/gcc/cgraphunit.c:2755
0xf7d4ae symbol_table::finalize_compilation_unit()
        /home/rguenther/src/gcc2/gcc/cgraphunit.c:3017
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 2 Marek Polacek 2020-09-11 13:08:40 UTC
(In reply to Richard Biener from comment #1)
> It also ICEs on trunk.  I think I've seen this ICE before so there might be
> a duplicate.

Yup.  It would be really great if this could be fixed.

*** This bug has been marked as a duplicate of bug 91241 ***