public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110822] New: ICE on constexpr initialized with non-constant expression also accepts-invalid
@ 2023-07-26 19:27 stevenxia990430 at gmail dot com
  2023-07-26 19:35 ` [Bug c++/110822] [13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: stevenxia990430 at gmail dot com @ 2023-07-26 19:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110822
           Summary: ICE on constexpr initialized with non-constant
                    expression also accepts-invalid
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stevenxia990430 at gmail dot com
  Target Milestone: ---

The following invalid program reports an internal compiler error: verify_gimple
failed on gcc-trunk with -O1, -O2 or -O3 optimization

To quickly reproduce: https://gcc.godbolt.org/z/s5aP44sKb
```
#include <iostream>
using namespace std::string_literals;
constexpr std::string text = "Some text here"s;
int main()
{
    std::cout << "The text is: " << text << '\n';
}
```

Note that compiling without optimization is successful, but is rejected on
clang-trunk

See this link: https://gcc.godbolt.org/z/G8vYhbe9E

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

* [Bug c++/110822] [13/14 Regression] ICE on constexpr initialized with non-constant expression also accepts-invalid
  2023-07-26 19:27 [Bug c++/110822] New: ICE on constexpr initialized with non-constant expression also accepts-invalid stevenxia990430 at gmail dot com
@ 2023-07-26 19:35 ` pinskia at gcc dot gnu.org
  2023-07-27  9:27 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-26 19:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ICE on constexpr            |[13/14 Regression] ICE on
                   |initialized with            |constexpr initialized with
                   |non-constant expression     |non-constant expression
                   |also accepts-invalid        |also accepts-invalid
   Target Milestone|---                         |13.2
      Known to fail|                            |13.1.0
      Known to work|                            |12.1.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I think GCC accepts this because the string fits in the (local) buffer of
std::string.

That is a longer string like:
constexpr std::string text = "012345678901234567890"s;

is rejected ....

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

* [Bug c++/110822] [13/14 Regression] ICE on constexpr initialized with non-constant expression also accepts-invalid
  2023-07-26 19:27 [Bug c++/110822] New: ICE on constexpr initialized with non-constant expression also accepts-invalid stevenxia990430 at gmail dot com
  2023-07-26 19:35 ` [Bug c++/110822] [13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-07-27  9:27 ` rguenth at gcc dot gnu.org
  2023-07-28  8:34 ` de34 at live dot cn
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27  9:27 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.2                        |13.3

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.

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

* [Bug c++/110822] [13/14 Regression] ICE on constexpr initialized with non-constant expression also accepts-invalid
  2023-07-26 19:27 [Bug c++/110822] New: ICE on constexpr initialized with non-constant expression also accepts-invalid stevenxia990430 at gmail dot com
  2023-07-26 19:35 ` [Bug c++/110822] [13/14 Regression] " pinskia at gcc dot gnu.org
  2023-07-27  9:27 ` rguenth at gcc dot gnu.org
@ 2023-07-28  8:34 ` de34 at live dot cn
  2023-08-01 18:01 ` ppalka at gcc dot gnu.org
  2023-08-01 18:02 ` [Bug c++/110822] " ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: de34 at live dot cn @ 2023-07-28  8:34 UTC (permalink / raw)
  To: gcc-bugs

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

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #3 from Jiang An <de34 at live dot cn> ---
This example is valid (or should be) for libstdc++.

Given `constexpr std::string text = "Some text here"s;` in namespace scope
("being a global variable"), the std::string object, which has static storage
duration, contains a pointer to its subobject, and doesn't hold any pointer to
a dynamically allocated storage.

Clang complains that the _M_construct function is not defined at the call point
so a call to it should make constant evalution fail. _M_construct is actually
defined later (in basic_string.tcc IIUC).

There's an unreolved CWG issue about this.
https://cplusplus.github.io/CWG/issues/2166.html

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

* [Bug c++/110822] [13/14 Regression] ICE on constexpr initialized with non-constant expression also accepts-invalid
  2023-07-26 19:27 [Bug c++/110822] New: ICE on constexpr initialized with non-constant expression also accepts-invalid stevenxia990430 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-07-28  8:34 ` de34 at live dot cn
@ 2023-08-01 18:01 ` ppalka at gcc dot gnu.org
  2023-08-01 18:02 ` [Bug c++/110822] " ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-08-01 18:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-08-01
                 CC|                            |ppalka at gcc dot gnu.org
           Keywords|accepts-invalid,            |ice-checking,
                   |ice-on-invalid-code         |ice-on-valid-code

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jiang An from comment #3)
> This example is valid (or should be) for libstdc++.
Thanks, I adjusted the PR to reflect this.

This seems to be a checking-only ICE and not a regression.  Reduced:

void __ostream_insert(const char*);
struct basic_string {
  const char* _M_p;
  char _M_local_buf[16] = {};
  constexpr basic_string() : _M_p(_M_local_buf) {}
  const char *data() const { return _M_p; }
};
constexpr basic_string f() { return {}; }
constexpr basic_string text = f();
int main() {
  __ostream_insert(text._M_p);
}

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

* [Bug c++/110822] ICE on constexpr initialized with non-constant expression also accepts-invalid
  2023-07-26 19:27 [Bug c++/110822] New: ICE on constexpr initialized with non-constant expression also accepts-invalid stevenxia990430 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-08-01 18:01 ` ppalka at gcc dot gnu.org
@ 2023-08-01 18:02 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-08-01 18:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|12.1.0                      |
            Summary|[13/14 Regression] ICE on   |ICE on constexpr
                   |constexpr initialized with  |initialized with
                   |non-constant expression     |non-constant expression
                   |also accepts-invalid        |also accepts-invalid
      Known to fail|13.1.0                      |14.0
   Target Milestone|13.3                        |---

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

end of thread, other threads:[~2023-08-01 18:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 19:27 [Bug c++/110822] New: ICE on constexpr initialized with non-constant expression also accepts-invalid stevenxia990430 at gmail dot com
2023-07-26 19:35 ` [Bug c++/110822] [13/14 Regression] " pinskia at gcc dot gnu.org
2023-07-27  9:27 ` rguenth at gcc dot gnu.org
2023-07-28  8:34 ` de34 at live dot cn
2023-08-01 18:01 ` ppalka at gcc dot gnu.org
2023-08-01 18:02 ` [Bug c++/110822] " 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).