Bug 79641 - [5 Regression] ICE with const variable and attribute
Summary: [5 Regression] ICE with const variable and attribute
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 5.5
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2017-02-20 21:30 UTC by Volker Reichelt
Modified: 2017-05-30 09:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build: [
Known to work: 6.3.1, 7.1.0
Known to fail: 5.1.0, 5.4.0, 6.1.0, 6.3.0
Last reconfirmed: 2017-02-20 00:00:00


Attachments
gcc7-pr79641.patch (434 bytes, patch)
2017-02-21 11:46 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 2017-02-20 21:30:19 UTC
The following valid line of code triggers an ICE since GCC 4.2.0:

==============================================
const int __attribute__((mode (QI))) i = 0;
==============================================

bug.cc:1:38: internal compiler error: in start_decl, at cp/decl.c:5150
 const int __attribute__((mode (QI))) i = 0;
                                      ^
0x63673f start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**)
        ../../gcc/gcc/cp/decl.c:5150
0x7195d7 cp_parser_init_declarator
        ../../gcc/gcc/cp/parser.c:19273
0x73dc1c cp_parser_simple_declaration
        ../../gcc/gcc/cp/parser.c:12795
0x73e9c5 cp_parser_block_declaration
        ../../gcc/gcc/cp/parser.c:12620
0x743d94 cp_parser_declaration
        ../../gcc/gcc/cp/parser.c:12518
0x7459bb cp_parser_declaration_seq_opt
        ../../gcc/gcc/cp/parser.c:12394
0x745c9a cp_parser_translation_unit
        ../../gcc/gcc/cp/parser.c:4366
0x745c9a c_parse_file()
        ../../gcc/gcc/cp/parser.c:38430
0x8a4de3 c_common_parse_file()
        ../../gcc/gcc/c-family/c-opts.c:1107
Please submit a full bug report, [etc.]

The C-frontend compiles the code without problem.
Comment 1 Marek Polacek 2017-02-20 22:05:13 UTC
Confirmed.
Comment 2 Jakub Jelinek 2017-02-21 11:30:19 UTC
Started most likely with r123432 (r123407 works, r123477 ICEs).
Looks like a bug in handle_mode_attribute, looking into it.
Comment 3 Jakub Jelinek 2017-02-21 11:46:32 UTC
Created attachment 40802 [details]
gcc7-pr79641.patch

Untested fix.
Comment 4 Jakub Jelinek 2017-02-21 16:55:32 UTC
Author: jakub
Date: Tue Feb 21 16:55:00 2017
New Revision: 245632

URL: https://gcc.gnu.org/viewcvs?rev=245632&root=gcc&view=rev
Log:
	PR c++/79641
	* c-attribs.c (handle_mode_attribute): Use build_qualified_type to
	preserve quals.

	* c-c++-common/pr79641.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/pr79641.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-attribs.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2017-02-21 16:57:47 UTC
Fixed on the trunk so far.
Comment 6 Jakub Jelinek 2017-05-05 21:28:41 UTC
Author: jakub
Date: Fri May  5 21:28:09 2017
New Revision: 247672

URL: https://gcc.gnu.org/viewcvs?rev=247672&root=gcc&view=rev
Log:
	Backported from mainline
	2017-02-21  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79641
	* c-common.c (handle_mode_attribute): Use build_qualified_type to
	preserve quals.

	* c-c++-common/pr79641.c: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/c-c++-common/pr79641.c
Modified:
    branches/gcc-6-branch/gcc/c-family/ChangeLog
    branches/gcc-6-branch/gcc/c-family/c-common.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2017-05-30 08:02:50 UTC
Author: jakub
Date: Tue May 30 08:02:18 2017
New Revision: 248648

URL: https://gcc.gnu.org/viewcvs?rev=248648&root=gcc&view=rev
Log:
	Backported from mainline
	2017-02-21  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79641
	* c-common.c (handle_mode_attribute): Use build_qualified_type to
	preserve quals.

	* c-c++-common/pr79641.c: New test.

Added:
    branches/gcc-5-branch/gcc/testsuite/c-c++-common/pr79641.c
Modified:
    branches/gcc-5-branch/gcc/c-family/ChangeLog
    branches/gcc-5-branch/gcc/c-family/c-common.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 8 Jakub Jelinek 2017-05-30 09:25:55 UTC
Fixed.