Bug 89709 - [9 Regression] ICE with constexpr and "-O"
Summary: [9 Regression] ICE with constexpr and "-O"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P1 normal
Target Milestone: 9.0
Assignee: Jakub Jelinek
URL:
Keywords: ice-checking, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2019-03-13 22:33 UTC by Volker Reichelt
Modified: 2019-03-15 09:26 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-03-13 00:00:00


Attachments
gcc9-pr89709.patch (858 bytes, patch)
2019-03-14 10:52 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2019-03-13 22:33:49 UTC
The following valid code snippet (compiled with "-O") triggers an ICE on trunk:

=============================
struct A
{
  int i;
};

A a;

constexpr int* foo()
{
  return &a.i;
}

bool bar()
{
  return foo() == &a.i;
}
=============================

bug.cc: In function 'bool bar()':
bug.cc:15:22: internal compiler error: in operand_equal_p, at fold-const.c:2962
   15 |   return foo() == &a.i;
      |                      ^
0x6e8344 operand_equal_p(tree_node const*, tree_node const*, unsigned int)
	../../gcc/gcc/fold-const.c:2962
0x141f84d generic_simplify_EQ_EXPR
	/tmp/gccbuild/src-9/build/gcc/generic-match.c:41813
0x144dc1d generic_simplify(unsigned int, tree_code, tree_node*, tree_node*, tree_node*)
	/tmp/gccbuild/src-9/build/gcc/generic-match.c:52806
0xc4e885 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*)
	../../gcc/gcc/fold-const.c:9378
0xc56c99 fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*)
	../../gcc/gcc/fold-const.c:12350
0x8c112a cp_fold
	../../gcc/gcc/cp/cp-gimplify.c:2448
0x8c30ec cp_fold_maybe_rvalue(tree_node*, bool)
	../../gcc/gcc/cp/cp-gimplify.c:2126
0xa29908 maybe_warn_about_returning_address_of_local
	../../gcc/gcc/cp/typeck.c:9183
0xa3f9c6 check_return_expr(tree_node*, bool*)
	../../gcc/gcc/cp/typeck.c:9751
0x9f955f finish_return_stmt(tree_node*)
	../../gcc/gcc/cp/semantics.c:895
0x979f77 cp_parser_jump_statement
	../../gcc/gcc/cp/parser.c:12848
0x979f77 cp_parser_statement
	../../gcc/gcc/cp/parser.c:11120
0x97a678 cp_parser_statement_seq_opt
	../../gcc/gcc/cp/parser.c:11586
0x97a758 cp_parser_compound_statement
	../../gcc/gcc/cp/parser.c:11540
0x992c95 cp_parser_function_body
	../../gcc/gcc/cp/parser.c:22521
0x992c95 cp_parser_ctor_initializer_opt_and_function_body
	../../gcc/gcc/cp/parser.c:22558
0x99351b cp_parser_function_definition_after_declarator
	../../gcc/gcc/cp/parser.c:27621
0x994269 cp_parser_function_definition_from_specifiers_and_declarator
	../../gcc/gcc/cp/parser.c:27537
0x994269 cp_parser_init_declarator
	../../gcc/gcc/cp/parser.c:20196
0x976f62 cp_parser_simple_declaration
	../../gcc/gcc/cp/parser.c:13470
Please submit a full bug report, [etc.]

The regression was introduced between 2018-12-14 and 2019-01-12.
Comment 1 Jakub Jelinek 2019-03-13 22:55:40 UTC
Started with r267272.
Comment 2 Jakub Jelinek 2019-03-14 10:52:01 UTC
Created attachment 45965 [details]
gcc9-pr89709.patch

Untested fix.  The above mentioned revision added STRIP_ANY_LOCATION_WRAPPERS to the beginning of operand_equal_p for both arg0 and arg1, but didn't adjust inchash::add_expr that needs to match that.  When not OEP_ADDRESS_OF, we'd strip it anyway through STRIP_NOPS, but not otherwise.

I've also moved the STRIP_ANY_LOCATION_WRAPPERS later in operand_equal_p, so that the hash checking would check this more often.
Comment 3 Jakub Jelinek 2019-03-15 09:23:43 UTC
Author: jakub
Date: Fri Mar 15 09:23:11 2019
New Revision: 269702

URL: https://gcc.gnu.org/viewcvs?rev=269702&root=gcc&view=rev
Log:
	PR c++/89709
	* tree.c (inchash::add_expr): Strip any location wrappers.
	* fold-const.c (operand_equal_p): Move stripping of location wrapper
	after hash verification.

	* g++.dg/cpp0x/constexpr-89709.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-89709.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.c
Comment 4 Jakub Jelinek 2019-03-15 09:26:16 UTC
Fixed.