public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106304] New: [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183)
@ 2022-07-14 17:15 johelegp at gmail dot com
  2022-07-26 10:03 ` [Bug c++/106304] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: johelegp at gmail dot com @ 2022-07-14 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106304
           Summary: [modules] ICE compiling dynamic_cast in constexpr
                    function (in tree_node, at cp/module.cc:9183)
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/xz4Mhd8Wc, which Clang accepts:
https://godbolt.org/z/saachff5d.

mod.cpp:
```C++
export module mod;

template<class T> struct A : T {
  constexpr A(T v) : T{v} { }
  ~A() = default; // Fixes GCC.
};

struct B {
  virtual ~B() = default;
};

export inline constexpr auto x = A{B{}};

export constexpr const A<B>* y(const B& b) {
  return dynamic_cast<const A<B>*>(&b);
}
```

test.cpp:
```C++
import mod;
static_assert(&x == y(x));
int main() { }
```

Output:
```
[ 50%] Building CXX object CMakeFiles/mod.dir/mod.cpp.o
mod.cpp:1:8: internal compiler error: in tree_node, at cp/module.cc:9183
    1 | export module mod;
      |        ^~~~~~
0x221f229 internal_error(char const*, ...)
        ???:0
0x74c10d fancy_abort(char const*, int, char const*)
        ???:0
0x8fd00f trees_out::tree_node(tree_node*)
        ???:0
0x8fde5f trees_out::core_vals(tree_node*)
        ???:0
0x902d6d trees_out::tree_value(tree_node*)
        ???:0
0x8fcf41 trees_out::tree_node(tree_node*)
        ???:0
0x8fde5f trees_out::core_vals(tree_node*)
        ???:0
0x902d6d trees_out::tree_value(tree_node*)
        ???:0
0x8fcf41 trees_out::tree_node(tree_node*)
        ???:0
0x8fde5f trees_out::core_vals(tree_node*)
        ???:0
0x902d6d trees_out::tree_value(tree_node*)
        ???:0
0x8fcf41 trees_out::tree_node(tree_node*)
        ???:0
0x8fde5f trees_out::core_vals(tree_node*)
        ???:0
0x902d6d trees_out::tree_value(tree_node*)
        ???:0
0x8fcf41 trees_out::tree_node(tree_node*)
        ???:0
0x8fde5f trees_out::core_vals(tree_node*)
        ???:0
0x902d6d trees_out::tree_value(tree_node*)
        ???:0
0x8fcf41 trees_out::tree_node(tree_node*)
        ???:0
0x8fde5f trees_out::core_vals(tree_node*)
        ???:0
0x902d6d trees_out::tree_value(tree_node*)
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
```

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

* [Bug c++/106304] [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183)
  2022-07-14 17:15 [Bug c++/106304] New: [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183) johelegp at gmail dot com
@ 2022-07-26 10:03 ` redi at gcc dot gnu.org
  2022-07-26 14:57 ` johelegp at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-26 10:03 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-07-26
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=99769
           Keywords|rejects-valid               |ice-on-valid-code

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please provide the compiler commands, not just a link to a cmake project on
godbolt, which is a pain to see what it's doing.

Only one file and one command is needed to reproduce this:

export module mod;

template<class T> struct A : T {
  constexpr A(T v) : T{v} { }
  ~A() = default; // Fixes GCC.
};

struct B {
  virtual ~B() = default;
};

export inline constexpr auto x = A{B{}};

export constexpr const A<B>* y(const B& b) {
  return dynamic_cast<const A<B>*>(&b);
}


$ g++ -std=c++20 mod.cpp -fmodules-ts -c
mod.cpp:1:8: internal compiler error: in tree_node, at cp/module.cc:9078
    1 | export module mod;
      |        ^~~~~~
Please submit a full bug report, with preprocessed source.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccYLb5i0.out file, please attach this to
your bugreport.


Maybe a dup of PR 99769 which fails at the same place in a typeid expression.

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

* [Bug c++/106304] [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183)
  2022-07-14 17:15 [Bug c++/106304] New: [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183) johelegp at gmail dot com
  2022-07-26 10:03 ` [Bug c++/106304] " redi at gcc dot gnu.org
@ 2022-07-26 14:57 ` johelegp at gmail dot com
  2022-10-14 13:07 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: johelegp at gmail dot com @ 2022-07-26 14:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
This is the best I can do without having to manually de-noise CMake's compile
commands: https://godbolt.org/z/6s1GGYhM4.

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

* [Bug c++/106304] [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183)
  2022-07-14 17:15 [Bug c++/106304] New: [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183) johelegp at gmail dot com
  2022-07-26 10:03 ` [Bug c++/106304] " redi at gcc dot gnu.org
  2022-07-26 14:57 ` johelegp at gmail dot com
@ 2022-10-14 13:07 ` cvs-commit at gcc dot gnu.org
  2022-10-14 13:10 ` ppalka at gcc dot gnu.org
  2022-10-14 13:22 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-14 13:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:d6a488f243acfac4bdbbb0eefbee3ae916159cf5

commit r13-3299-gd6a488f243acfac4bdbbb0eefbee3ae916159cf5
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Oct 14 09:07:01 2022 -0400

    c++ modules: ICE with dynamic_cast [PR106304]

    The FUNCTION_DECL we build for __dynamic_cast has an empty DECL_CONTEXT
    but trees_out::tree_node expects FUNCTION_DECLs to have non-empty
    DECL_CONTEXT, thus we crash when streaming out the dynamic_cast in the
    below testcase.

    This patch naively fixes this by setting DECL_CONTEXT for __dynamic_cast
    appropriately.  I suppose we should push it into the namespace too, like
    we do for __cxa_atexit which is similarly lazily declared.

            PR c++/106304

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_dynamic_cast_fn_p): Check for abi_node
            instead of global_namespace.
            * rtti.cc (build_dynamic_cast_1): Set DECL_CONTEXT and
            DECL_SOURCE_LOCATION when building dynamic_cast_node.  Push
            it into the namespace.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/pr106304_a.C: New test.
            * g++.dg/modules/pr106304_b.C: New test.

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

* [Bug c++/106304] [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183)
  2022-07-14 17:15 [Bug c++/106304] New: [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183) johelegp at gmail dot com
                   ` (2 preceding siblings ...)
  2022-10-14 13:07 ` cvs-commit at gcc dot gnu.org
@ 2022-10-14 13:10 ` ppalka at gcc dot gnu.org
  2022-10-14 13:22 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-10-14 13:10 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
             Status|NEW                         |RESOLVED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Should be fixed on trunk

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

* [Bug c++/106304] [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183)
  2022-07-14 17:15 [Bug c++/106304] New: [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183) johelegp at gmail dot com
                   ` (3 preceding siblings ...)
  2022-10-14 13:10 ` ppalka at gcc dot gnu.org
@ 2022-10-14 13:22 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-10-14 13:22 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|https://gcc.gnu.org/bugzill |
                   |a/show_bug.cgi?id=99769     |
                 CC|                            |owt5008137 at live dot com

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 99769 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2022-10-14 13:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 17:15 [Bug c++/106304] New: [modules] ICE compiling dynamic_cast in constexpr function (in tree_node, at cp/module.cc:9183) johelegp at gmail dot com
2022-07-26 10:03 ` [Bug c++/106304] " redi at gcc dot gnu.org
2022-07-26 14:57 ` johelegp at gmail dot com
2022-10-14 13:07 ` cvs-commit at gcc dot gnu.org
2022-10-14 13:10 ` ppalka at gcc dot gnu.org
2022-10-14 13:22 ` ppalka 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).