Bug 84596 - [8 Regression] internal compiler error: unexpected expression '(bool)c' of kind implicit_conv_expr (cxx_eval_constant_expression)
Summary: [8 Regression] internal compiler error: unexpected expression '(bool)c' of ki...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0.1
: P3 normal
Target Milestone: 8.0
Assignee: Marek Polacek
URL:
Keywords: error-recovery, ice-on-invalid-code, patch
Depends on:
Blocks: 84582
  Show dependency treegraph
 
Reported: 2018-02-27 15:27 UTC by Vegard Nossum
Modified: 2018-03-14 06:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-27 00:00:00


Attachments
candidate patch (636 bytes, patch)
2018-02-28 08:17 UTC, Alexandre Oliva
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vegard Nossum 2018-02-27 15:27:42 UTC
Input:

template<int x>
void b(int c) {
        static_assert(c);
}

Output:

$ xgcc -x c++ -std=c++14 -O3 -c -
<stdin>: In function 'void b(int)':
<stdin>:3:16: error: non-constant condition for static assertion
<stdin>:3:16: internal compiler error: unexpected expression '(bool)c' of kind implicit_conv_expr
0xa3811b cxx_eval_constant_expression
	/home/vegard/git/gcc/gcc/cp/constexpr.c:4730
0xa4a9da cxx_eval_outermost_constant_expr
	/home/vegard/git/gcc/gcc/cp/constexpr.c:4790
0x12a074d finish_static_assert(tree_node*, tree_node*, unsigned int, bool)
	/home/vegard/git/gcc/gcc/cp/semantics.c:8674
0xec9191 cp_parser_static_assert
	/home/vegard/git/gcc/gcc/cp/parser.c:13893
0xfa9bd1 cp_parser_block_declaration
	/home/vegard/git/gcc/gcc/cp/parser.c:12823
0xfab154 cp_parser_declaration_statement
	/home/vegard/git/gcc/gcc/cp/parser.c:12420
0xef6e13 cp_parser_statement
	/home/vegard/git/gcc/gcc/cp/parser.c:10869
0xefb1eb cp_parser_statement_seq_opt
	/home/vegard/git/gcc/gcc/cp/parser.c:11218
0xefbc8a cp_parser_compound_statement
	/home/vegard/git/gcc/gcc/cp/parser.c:11172
0xf8fb9b cp_parser_function_body
	/home/vegard/git/gcc/gcc/cp/parser.c:21712
0xf8fb9b cp_parser_ctor_initializer_opt_and_function_body
	/home/vegard/git/gcc/gcc/cp/parser.c:21747
0xf98da5 cp_parser_function_definition_after_declarator
	/home/vegard/git/gcc/gcc/cp/parser.c:26648
0xf9f305 cp_parser_function_definition_from_specifiers_and_declarator
	/home/vegard/git/gcc/gcc/cp/parser.c:26565
0xf9f305 cp_parser_init_declarator
	/home/vegard/git/gcc/gcc/cp/parser.c:19436
0xfa0909 cp_parser_single_declaration
	/home/vegard/git/gcc/gcc/cp/parser.c:27111
0xfc2718 cp_parser_template_declaration_after_parameters
	/home/vegard/git/gcc/gcc/cp/parser.c:26706
0xfc0d1b cp_parser_explicit_template_declaration
	/home/vegard/git/gcc/gcc/cp/parser.c:26944
0xfc0d1b cp_parser_template_declaration_after_export
	/home/vegard/git/gcc/gcc/cp/parser.c:26962
0xffbd51 cp_parser_declaration
	/home/vegard/git/gcc/gcc/cp/parser.c:12673
0xff298b cp_parser_declaration_seq_opt
	/home/vegard/git/gcc/gcc/cp/parser.c:12600
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.

Version:

xgcc (GCC) 8.0.1 20180204 (experimental)

built from git fdae6180ad24fa6303fa046114f3e4b66b8db34d

Version 7.3.0 don't seem to be affected AFAICS. gcc trunk on godbolt.org (8.0.1 20180227) gives:

<source>: In function 'void b(int)':
<source>:3:23: error: non-constant condition for static assertion
         static_assert(c);
                       ^
<source>:3:23: internal compiler error: unexpected expression '(bool)c' of kind implicit_conv_expr
mmap: Invalid argument
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

Test case was reduced using C-Reduce.
Comment 1 Marek Polacek 2018-02-27 15:35:12 UTC
Started with r256550.
Comment 2 Marek Polacek 2018-02-27 15:36:36 UTC
I'm looking into the same kind of ICE (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84582#c4) but this one is invalid.
Comment 3 Alexandre Oliva 2018-02-28 08:17:32 UTC
Created attachment 43526 [details]
candidate patch

Mine, here's what I'm testing.
Comment 4 Marek Polacek 2018-03-01 17:09:06 UTC
Author: mpolacek
Date: Thu Mar  1 17:08:35 2018
New Revision: 258107

URL: https://gcc.gnu.org/viewcvs?rev=258107&root=gcc&view=rev
Log:
	PR c++/84596
	* constexpr.c (require_rvalue_constant_expression): New function.
	* cp-tree.h: Declare it.
	* semantics.c (finish_static_assert): Use it instead of
	require_potential_rvalue_constant_expression.

	* g++.dg/cpp0x/static_assert14.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/static_assert14.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Marek Polacek 2018-03-01 17:09:14 UTC
Fixed.
Comment 6 Vegard Nossum 2018-03-03 20:27:44 UTC
I see a similar ICE on r258221 using this test case:

template<int x>
struct a {
  constexpr int b() {
    int c;
    static_assert(c %= 1);
  }
};

Output:

$ xgcc -x c++ -S -
<stdin>: In member function 'constexpr int a<x>::b()':
<stdin>:5:21: error: non-constant condition for static assertion
<stdin>:5:21: internal compiler error: unexpected expression '(bool)c %=1' of kind implicit_conv_expr
0xa3cfab cxx_eval_constant_expression
        /home/vegard/git/gcc/gcc/cp/constexpr.c:4770
0xa4de8a cxx_eval_outermost_constant_expr
        /home/vegard/git/gcc/gcc/cp/constexpr.c:4830
0x12a6a7d finish_static_assert(tree_node*, tree_node*, unsigned int, bool)
        /home/vegard/git/gcc/gcc/cp/semantics.c:8678
0xed0a31 cp_parser_static_assert
        /home/vegard/git/gcc/gcc/cp/parser.c:13947
0xfb0b11 cp_parser_block_declaration
        /home/vegard/git/gcc/gcc/cp/parser.c:12877
0xfb2094 cp_parser_declaration_statement
        /home/vegard/git/gcc/gcc/cp/parser.c:12474
0xefef9b cp_parser_statement
        /home/vegard/git/gcc/gcc/cp/parser.c:10923
0xf02a5b cp_parser_statement_seq_opt
        /home/vegard/git/gcc/gcc/cp/parser.c:11272
0xf034fa cp_parser_compound_statement
        /home/vegard/git/gcc/gcc/cp/parser.c:11226
0xf96a6b cp_parser_function_body
        /home/vegard/git/gcc/gcc/cp/parser.c:21776
0xf96a6b cp_parser_ctor_initializer_opt_and_function_body
        /home/vegard/git/gcc/gcc/cp/parser.c:21811
0xf9fc75 cp_parser_function_definition_after_declarator
        /home/vegard/git/gcc/gcc/cp/parser.c:26816
0xfa1f3c cp_parser_late_parsing_for_member
        /home/vegard/git/gcc/gcc/cp/parser.c:27697
0xf1c0e5 cp_parser_class_specifier_1
        /home/vegard/git/gcc/gcc/cp/parser.c:22740
0xf2763b cp_parser_class_specifier
        /home/vegard/git/gcc/gcc/cp/parser.c:22766
0xf2763b cp_parser_type_specifier
        /home/vegard/git/gcc/gcc/cp/parser.c:16772
0xf8c7ba cp_parser_decl_specifier_seq
        /home/vegard/git/gcc/gcc/cp/parser.c:13627
0xfa6ddf cp_parser_single_declaration
        /home/vegard/git/gcc/gcc/cp/parser.c:27185
0xfc9658 cp_parser_template_declaration_after_parameters
        /home/vegard/git/gcc/gcc/cp/parser.c:26874
0xfc7c5b cp_parser_explicit_template_declaration
        /home/vegard/git/gcc/gcc/cp/parser.c:27112
Comment 7 Alexandre Oliva 2018-03-08 05:41:46 UTC
Vegard, this PR is already resolved, I suggest filing a new PR for the bug you detected with the testcase in comment 6, and linking back to this one there, for reference.
Comment 8 Marek Polacek 2018-03-14 06:15:30 UTC
Author: mpolacek
Date: Wed Mar 14 06:14:57 2018
New Revision: 258513

URL: https://gcc.gnu.org/viewcvs?rev=258513&root=gcc&view=rev
Log:
	PR c++/84596
	* semantics.c (finish_static_assert): Check
	instantiation_dependent_expression_p instead of
	{type,value}_dependent_expression_p.

	* g++.dg/cpp0x/static_assert15.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/static_assert15.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Marek Polacek 2018-03-14 06:16:27 UTC
Fixed the second testcase too.