public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67398] New: Segfault when template static references another template
@ 2015-08-30  7:23 jeanmichael.celerier at gmail dot com
  2015-08-30  7:31 ` [Bug c++/67398] " jeanmichael.celerier at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jeanmichael.celerier at gmail dot com @ 2015-08-30  7:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67398

            Bug ID: 67398
           Summary: Segfault when template static references another
                    template
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeanmichael.celerier at gmail dot com
  Target Milestone: ---

Error given by gcc : 
/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp
: dans l'instantiation de ‘const qt_meta_stringdata_NotifyingMap_t
staticStringData<ConstraintModel>’ :
/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp:57:29:
  required from ‘const QMetaObject
NotifyingMap<ConstraintModel>::staticMetaObject’
/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp:73:172:
  required from here
/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp:31:3:
erreur interne du compilateur: Erreur de segmentation
 } staticStringData{};
   ^

Rough translation of the last line : Internal Compiler Error : segmentation
fault.

The relevant part starts at line 196141 of the attached preprocessed source.
It started when I added a template at line 196240 :

      staticStringData<T>.data, 

The "required from here" refers to an usage of staticMetaObject in code.


Requires -fPIC and -std=c++14.
>From gcc-bugs-return-495880-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Aug 30 07:25:29 2015
Return-Path: <gcc-bugs-return-495880-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 53532 invoked by alias); 30 Aug 2015 07:25:28 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 53499 invoked by uid 48); 30 Aug 2015 07:25:24 -0000
From: "jeanmichael.celerier at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67398] Segfault when template static references another template
Date: Sun, 30 Aug 2015 07:25:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.2.1
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jeanmichael.celerier at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-67398-4-viHfbfCG2A@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67398-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67398-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-08/txt/msg02022.txt.bz2
Content-length: 360

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67398

--- Comment #1 from Jean-Michaël Celerier <jeanmichael.celerier at gmail dot com> ---
I couldn't upload the attachment here (>1mb) so here is the preprocessed source
:
https://gist.githubusercontent.com/jcelerier/6e67a053e08188cac07f/raw/b74ad5be0dcc12ff230cc7212fe5fa94b6413686/gccsegfault.cpp
>From gcc-bugs-return-495882-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Aug 30 07:31:36 2015
Return-Path: <gcc-bugs-return-495882-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 67544 invoked by alias); 30 Aug 2015 07:31:36 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 67128 invoked by uid 48); 30 Aug 2015 07:31:32 -0000
From: "egall at gwmail dot gwu.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/67363] [6 Regression] r227188 breaks build for mingw-w64
Date: Sun, 30 Aug 2015 07:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: bootstrap
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: egall at gwmail dot gwu.edu
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: dmalcolm at redhat dot com
X-Bugzilla-Target-Milestone: 6.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-67363-4-WaTbiKDrOQ@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67363-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67363-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-08/txt/msg02024.txt.bz2
Content-length: 774

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg363

--- Comment #2 from Eric Gallager <egall at gwmail dot gwu.edu> ---
Actually on further investigation, libiberty should already provide a strndup
implementation, the issue is just that it's not getting picked up here... I'm
not sure whether it would be better to put a declaration for it in
include/libiberty.h or in gcc/system.h though? Or both? The former seems like
the more correct location, but the latter was the one that actually worked,
so... I guess I should attach a patch for the latter then? Along with the
proper configure changes required for the ifdefs to work properly, that is...

(anyways, that's just the strndup part of the issue; I have no clue about the
setenv/unsetenv part in the original bug...)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/67398] Segfault when template static references another template
  2015-08-30  7:23 [Bug c++/67398] New: Segfault when template static references another template jeanmichael.celerier at gmail dot com
@ 2015-08-30  7:31 ` jeanmichael.celerier at gmail dot com
  2015-08-30  9:30 ` trippels at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jeanmichael.celerier at gmail dot com @ 2015-08-30  7:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67398

--- Comment #2 from Jean-Michaël Celerier <jeanmichael.celerier at gmail dot com> ---
I now get this error :
/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp:63:
internal compiler error: in make_decl_rtl, at varasm.c:1313
 constexpr const QMetaObject NotifyingMap<T>::staticMetaObject{
                             ^

if I change the relevant part of the code to this : 


template<typename T>
struct strdata_t
{
    QByteArrayData data[5]{
        QT_MOC_LITERAL_CUSTOM(0, 0, 12), // "NotifyingMap"
        QT_MOC_LITERAL_CUSTOM(1, 13, 5), // "added"
        QT_MOC_LITERAL_CUSTOM(2, 19, 0), // ""
        QT_MOC_LITERAL_CUSTOM(3, 20, typeLength<T>()), // "T"
        QT_MOC_LITERAL_CUSTOM(4, 21 + typeLength<T>(), 7) // "removed"
    };
    std::array<char, 29 + typeLength<T>()> stringdata0 =
            concat("NotifyingMap\0added\0\0", T::className, "\0removed");
};



static const uint staticMetaData[31]{
 // content:
       7,       // revision
       0,       // classname
       0,    0, // classinfo
       2,   14, // methods
       0,    0, // properties
       0,    0, // enums/sets
       0,    0, // constructors
       0,       // flags
       2,       // signalCount

 // signals: name, argc, parameters, tag, flags
       1,    1,   24,    2, 0x06 /* Public */,
       4,    1,   27,    2, 0x06 /* Public */,

 // signals: parameters
    QMetaType::Void, 0x80000000 | 3,    2,
    QMetaType::Void, 0x80000000 | 3,    2,

       0        // eod
};

template<typename T>
constexpr const QMetaObject NotifyingMap<T>::staticMetaObject{
    { &QObject::staticMetaObject,
      strdata_t<T>{}.data,
      staticMetaData,  qt_static_metacall, Q_NULLPTR, Q_NULLPTR }
};
>From gcc-bugs-return-495883-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Aug 30 08:22:51 2015
Return-Path: <gcc-bugs-return-495883-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 26823 invoked by alias); 30 Aug 2015 08:22:50 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 26749 invoked by uid 48); 30 Aug 2015 08:22:46 -0000
From: "egall at gwmail dot gwu.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/67363] [6 Regression] r227188 breaks build for mingw-w64
Date: Sun, 30 Aug 2015 08:22:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: bootstrap
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: egall at gwmail dot gwu.edu
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: dmalcolm at redhat dot com
X-Bugzilla-Target-Milestone: 6.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-67363-4-sks7ePmn1C@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67363-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67363-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-08/txt/msg02025.txt.bz2
Content-length: 340

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg363

--- Comment #3 from Eric Gallager <egall at gwmail dot gwu.edu> ---
Or actually, an even simpler solution to the strndup part of the bug would be
to just use xstrndup instead of strndup; then there's no worrying about which
header to add a declaration to, or anything related to that...


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/67398] Segfault when template static references another template
  2015-08-30  7:23 [Bug c++/67398] New: Segfault when template static references another template jeanmichael.celerier at gmail dot com
  2015-08-30  7:31 ` [Bug c++/67398] " jeanmichael.celerier at gmail dot com
@ 2015-08-30  9:30 ` trippels at gcc dot gnu.org
  2015-08-30 11:38 ` miyuki at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: trippels at gcc dot gnu.org @ 2015-08-30  9:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67398

Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
                 CC|                            |trippels at gcc dot gnu.org

--- Comment #3 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
Might be related to PR63508.

Also gcc accepts this invalid code (starting with gcc-5):

template <typename T> struct A {
} a{};

Clang and EDG reject it.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/67398] Segfault when template static references another template
  2015-08-30  7:23 [Bug c++/67398] New: Segfault when template static references another template jeanmichael.celerier at gmail dot com
  2015-08-30  7:31 ` [Bug c++/67398] " jeanmichael.celerier at gmail dot com
  2015-08-30  9:30 ` trippels at gcc dot gnu.org
@ 2015-08-30 11:38 ` miyuki at gcc dot gnu.org
  2015-08-30 12:08 ` miyuki at gcc dot gnu.org
  2015-08-30 14:32 ` miyuki at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: miyuki at gcc dot gnu.org @ 2015-08-30 11:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67398

Mikhail Maltsev <miyuki at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-08-30
                 CC|                            |miyuki at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #4 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
For the second testcase (ICE in varasm.c) Clang says:

/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp:57:46:
error: constexpr variable 'staticMetaObject' must be initialized by a constant
expression
constexpr const QMetaObject NotifyingMap<T>::staticMetaObject{
                                             ^               ~
/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp:57:46:
note: pointer to subobject of temporary is not a constant expression
/home/jcelerier/i-score/base/plugins/iscore-plugin-scenario/source/Process/ScenarioModel.cpp:59:22:
note: temporary created here
      strdata_t<T>{}.data,

Thus, also ICE on invalid, and it does not reproduce on trunk (but looks like
it turned into accepts-invalid). The first ICE does reproduce.

I'll post a reduced testcase shortly.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/67398] Segfault when template static references another template
  2015-08-30  7:23 [Bug c++/67398] New: Segfault when template static references another template jeanmichael.celerier at gmail dot com
                   ` (2 preceding siblings ...)
  2015-08-30 11:38 ` miyuki at gcc dot gnu.org
@ 2015-08-30 12:08 ` miyuki at gcc dot gnu.org
  2015-08-30 14:32 ` miyuki at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: miyuki at gcc dot gnu.org @ 2015-08-30 12:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67398

--- Comment #5 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
$ cat test3.cc 
template <typename>
struct B {
    static const int staticMetaObject;
};

template <typename T>
struct D {
    int stringdata0 = T::className;
} staticStringData{};

template <typename T>
const int B<T>::staticMetaObject{staticStringData<T>};

void foo()
{
    B<int> constraints;
    constraints.staticMetaObject;
}

$ cc1plus test3.cc                                                              
test3.cc: In instantiation of 'D staticStringData<int>':
test3.cc:12:50:   required from 'const int B<int>::staticMetaObject'
test3.cc:17:17:   required from here
test3.cc:9:3: internal compiler error: Segmentation fault
 } staticStringData{};
   ^
0xc847bf crash_signal
        /home/miyuki/gcc/src/gcc/toplev.c:352
0x5e36b3 extend_ref_init_temps(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**)
        /home/miyuki/gcc/src/gcc/cp/call.c:9892
0x5e3724 extend_ref_init_temps(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**)
        /home/miyuki/gcc/src/gcc/cp/call.c:9914
0x6868d9 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        /home/miyuki/gcc/src/gcc/cp/typeck2.c:806
0x5ef6ae check_initializer
        /home/miyuki/gcc/src/gcc/cp/decl.c:6089


$ clang++ -std=c++14 -S test3.cc 
test3.cc:9:2: error: expected ';' after struct
} staticStringData{};
 ^
 ;
test3.cc:9:3: error: C++ requires a type specifier for all declarations
} staticStringData{};


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/67398] Segfault when template static references another template
  2015-08-30  7:23 [Bug c++/67398] New: Segfault when template static references another template jeanmichael.celerier at gmail dot com
                   ` (3 preceding siblings ...)
  2015-08-30 12:08 ` miyuki at gcc dot gnu.org
@ 2015-08-30 14:32 ` miyuki at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: miyuki at gcc dot gnu.org @ 2015-08-30 14:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67398

--- Comment #6 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
$ cat test4_min.cc 
struct B {
  void *extradata;
};

template <typename>
class C {
  static const B b;
  virtual void m_fn1() { (void)b; }
};

template <typename>
struct strdata_t {
    int data[];
};

template <typename T>
const B C<T>::b{strdata_t<T>{}.data};

C<int> c;

$ cc1plus test4_min.cc                                                          
test4_min.cc: In function 'void __static_initialization_and_destruction_0(int,
int)':
test4_min.cc:17:9: internal compiler error: in make_decl_rtl, at varasm.c:1306
 const B C<T>::b{strdata_t<T>{}.data};
         ^
0xf53495 make_decl_rtl(tree_node*)
        /home/miyuki/gcc/src/gcc/varasm.c:1302
0x9cfb79 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
        /home/miyuki/gcc/src/gcc/expr.c:9525
0x9d9dc6 expand_expr
        /home/miyuki/gcc/src/gcc/expr.h:255
0x9d9dc6 expand_expr_addr_expr_1
        /home/miyuki/gcc/src/gcc/expr.c:7600

Reproduced on trunk. BTW, Clang accepts it, but issues a warning (apparently, I
overlooked that the error in my previous comment was caused by invalid
constexpr initialization):

test4_min.cc:17:17: warning: pointer is initialized by a temporary array, which
will be destroyed at the end of the full-expression
[-Waddress-of-array-temporary]
const B C<T>::b{strdata_t<T>{}.data};


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-08-30 14:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-30  7:23 [Bug c++/67398] New: Segfault when template static references another template jeanmichael.celerier at gmail dot com
2015-08-30  7:31 ` [Bug c++/67398] " jeanmichael.celerier at gmail dot com
2015-08-30  9:30 ` trippels at gcc dot gnu.org
2015-08-30 11:38 ` miyuki at gcc dot gnu.org
2015-08-30 12:08 ` miyuki at gcc dot gnu.org
2015-08-30 14:32 ` miyuki at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).