Bug 91740 - [9 Regression] ICE in fold_convert_loc, at fold-const.c:2429
Summary: [9 Regression] ICE in fold_convert_loc, at fold-const.c:2429
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.0
: P2 normal
Target Milestone: 9.3
Assignee: Marek Polacek
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2019-09-11 15:11 UTC by Julien Vivenot
Modified: 2019-10-08 13:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-09-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Vivenot 2019-09-11 15:11:59 UTC
The following causes an internal compiler error on gcc 9.2.0 on x86-64.
I do not have access to other versions myself but tested on godbolt: It seems to say that 9.1, 9.2 and current trunk are affected, while 8.3 is unaffected.

$ cat test.cpp
constexpr bool f(const char*) { return true; }
template<typename T> const char c = "FOO"[f("BAR") ? 1 : 0];


$ g++ test.cpp
test.cpp:2:59: internal compiler error: in fold_convert_loc, at fold-const.c:2429
    2 | template<typename T> const char c = "FOO"[f("BAR") ? 1 : 0];
      |                                                           ^

The current code is obviously meaningless because it has been slowly scaled down from production code.
I have noted that any of the following changes make the issue disappear :
  - removing the argument to f()
  - removing the templatization
  - removing the ternary operator
Comment 1 Marek Polacek 2019-09-11 15:16:35 UTC
Confirmed.
Comment 2 Marek Polacek 2019-09-11 15:19:15 UTC
Started with r267272.  Will take a look.
Comment 4 Marek Polacek 2019-09-15 20:22:59 UTC
Author: mpolacek
Date: Sun Sep 15 20:22:27 2019
New Revision: 275736

URL: https://gcc.gnu.org/viewcvs?rev=275736&root=gcc&view=rev
Log:
	PR c++/91740 - ICE with constexpr call and ?: in ARRAY_REF.
	* pt.c (build_non_dependent_expr): Call build_non_dependent_expr for
	the first operand.

	* g++.dg/cpp1y/var-templ63.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/var-templ63.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Marek Polacek 2019-09-15 20:23:19 UTC
Fixed on trunk so far.
Comment 6 Marek Polacek 2019-10-08 13:39:07 UTC
Author: mpolacek
Date: Tue Oct  8 13:38:35 2019
New Revision: 276699

URL: https://gcc.gnu.org/viewcvs?rev=276699&root=gcc&view=rev
Log:
	PR c++/91740 - ICE with constexpr call and ?: in ARRAY_REF.
	* pt.c (build_non_dependent_expr): Call build_non_dependent_expr for
	the first operand.

Added:
    branches/gcc-9-branch/gcc/testsuite/g++.dg/cpp1y/var-templ63.C
Modified:
    branches/gcc-9-branch/gcc/cp/ChangeLog
    branches/gcc-9-branch/gcc/cp/pt.c
Comment 7 Marek Polacek 2019-10-08 13:39:18 UTC
Fixed.