Bug 90382 - [10 Regression] ICE in linemap_macro_map_loc_to_exp_point, at libcpp/line-map.c:1061
Summary: [10 Regression] ICE in linemap_macro_map_loc_to_exp_point, at libcpp/line-map...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Martin Liška
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2019-05-07 20:19 UTC by Stephan Bergmann
Modified: 2019-05-14 11:49 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Bergmann 2019-05-07 20:19:03 UTC
I encountered this ICE with recent GCC trunk with

  #include "boost/spirit/include/phoenix.hpp"

but could only strip it down to the following reproducer that still includes some boost/preprocessor/ include files (from boost-devel-1.69.0-6.fc30.x86_64 on Fedora 30 in my case).  The failure was not reproducible with -E preprocessed sources.

$ cat test.cc
> #include "boost/preprocessor/repetition/enum_params.hpp"
> #include "boost/preprocessor/repetition/repeat_from_to.hpp"
> 
> template<typename = void> struct S {};
> 
> #define N S
> 
> #define M(z, n, d) template<BOOST_PP_ENUM_PARAMS(n, typename A)> void f(N<BOOST_PP_ENUM_PARAMS(n, A)> const &);
> 
> BOOST_PP_REPEAT_FROM_TO(0, 1, M,)

$ gcc/trunk/inst/bin/g++ -c test.cc
> test.cc:8:109: internal compiler error: in linemap_macro_map_loc_to_exp_point, at libcpp/line-map.c:1061
>     8 |  d) template<BOOST_PP_ENUM_PARAMS(n, typename A)> void f(N<BOOST_PP_ENUM_PARAMS(n, A)> const &);
>       |                                                                                              ^
> 
> /usr/include/boost/preprocessor/repetition/repeat_from_to.hpp:83:54: note: in expansion of macro ‘M’
>    83 | # define BOOST_PP_REPEAT_FROM_TO_M_1_II(z, n, m, dt) m(z, n, dt)
>       |                                                      ^
> 0x18ecbef linemap_macro_map_loc_to_exp_point
> 	../../src/libcpp/line-map.c:1061
> 0x18ecbef linemap_macro_map_loc_to_exp_point
> 	../../src/libcpp/line-map.c:1054
> 0x18ee6a7 first_map_in_common_1
> 	../../src/libcpp/line-map.c:1269
> 0x18ee6a7 first_map_in_common
> 	../../src/libcpp/line-map.c:1306
> 0x18ee6a7 linemap_compare_locations(line_maps*, unsigned int, unsigned int)
> 	../../src/libcpp/line-map.c:1349
> 0x905d8d linemap_location_before_p(line_maps*, unsigned int, unsigned int)
> 	../../src/gcc/../libcpp/include/line-map.h:1273
> 0x905d8d min_location
> 	../../src/gcc/cp/decl.c:10069
> 0x91cdbb grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, decl_context, int, tree_node**)
> 	../../src/gcc/cp/decl.c:10427
> 0x9c3e0e cp_parser_parameter_declaration_list
> 	../../src/gcc/cp/parser.c:22197
> 0x9c41ab cp_parser_parameter_declaration_clause
> 	../../src/gcc/cp/parser.c:22114
> 0x9b8d9d cp_parser_direct_declarator
> 	../../src/gcc/cp/parser.c:20806
> 0x9b8d9d cp_parser_declarator
> 	../../src/gcc/cp/parser.c:20674
> 0x9c6bb5 cp_parser_init_declarator
> 	../../src/gcc/cp/parser.c:20184
> 0x9ca294 cp_parser_single_declaration
> 	../../src/gcc/cp/parser.c:28268
> 0x9caed7 cp_parser_explicit_specialization
> 	../../src/gcc/cp/parser.c:17323
> 0x9cd826 cp_parser_declaration
> 	../../src/gcc/cp/parser.c:13184
> 0x9cde1f cp_parser_translation_unit
> 	../../src/gcc/cp/parser.c:4701
> 0x9cde1f c_parse_file()
> 	../../src/gcc/cp/parser.c:41181
> 0xad3beb c_common_parse_file()
> 	../../src/gcc/c-family/c-opts.c:1156
> 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.
Comment 1 Martin Liška 2019-05-09 08:46:23 UTC
Started with r270597.
Comment 2 Paolo Carlini 2019-05-09 10:01:13 UTC
Oh my, let's immediately remove that little tweak, I have no idea how it could have caused a regression but isn't worth the trouble. Maybe another time...
Comment 3 paolo@gcc.gnu.org 2019-05-09 10:18:54 UTC
Author: paolo
Date: Thu May  9 10:18:23 2019
New Revision: 271032

URL: https://gcc.gnu.org/viewcvs?rev=271032&root=gcc&view=rev
Log:
/cp
2019-05-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/90382
	Revert:
	2018-04-26  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (grokdeclarator): Fix value assigned to typespec_loc, use
	min_location.

/testsuite
2019-05-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/90382
	2018-04-26  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/diagnostic/trailing1.C: New.

Removed:
    trunk/gcc/testsuite/g++.dg/diagnostic/trailing1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2019-05-09 10:23:55 UTC
Done. Somebody should however look into linemap_location_before_p & co a bit more, because frankly my patchlet should not have caused a problem, likely it just uncovered a latent issue of some sort: it simply uses min_location, which, in turn, only calls linemap_location_before_p when both the passed locations are != UNKNOWN_LOCATION, thus safe AFAICS.
Comment 5 Martin Liška 2019-05-09 10:26:33 UTC
(In reply to Paolo Carlini from comment #4)
> Done. Somebody should however look into linemap_location_before_p & co a bit
> more, because frankly my patchlet should not have caused a problem, likely
> it just uncovered a latent issue of some sort: it simply uses min_location,
> which, in turn, only calls linemap_location_before_p when both the passed
> locations are != UNKNOWN_LOCATION, thus safe AFAICS.

David, can you please take a look?
Comment 6 Martin Liška 2019-05-13 11:12:20 UTC
(In reply to Martin Liška from comment #5)
> (In reply to Paolo Carlini from comment #4)
> > Done. Somebody should however look into linemap_location_before_p & co a bit
> > more, because frankly my patchlet should not have caused a problem, likely
> > it just uncovered a latent issue of some sort: it simply uses min_location,
> > which, in turn, only calls linemap_location_before_p when both the passed
> > locations are != UNKNOWN_LOCATION, thus safe AFAICS.
> 
> David, can you please take a look?

I'm working on that and I have a patch candidate. Let me test it ..
Comment 7 Paolo Carlini 2019-05-13 13:27:58 UTC
Beautiful, thanks Martin.
Comment 8 Martin Liška 2019-05-14 11:42:12 UTC
Author: marxin
Date: Tue May 14 11:41:40 2019
New Revision: 271162

URL: https://gcc.gnu.org/viewcvs?rev=271162&root=gcc&view=rev
Log:
Do a refactoring in linemap (PR preprocessor/90382).

2019-05-14  Martin Liska  <mliska@suse.cz>

	PR preprocessor/90382
	* include/line-map.h (get_data_from_adhoc_loc): Add const to
	the first argument.
	(get_location_from_adhoc_loc): Likewise.
	* line-map.c(get_data_from_adhoc_loc):  Add const to
	the first argument.
	(get_location_from_adhoc_loc): Likewise.
	(get_combined_adhoc_loc): Use get_location_from_adhoc_loc
	(or get_data_from_adhoc_loc).
	(get_range_from_adhoc_loc): Likewise.
	(get_pure_location): Likewise.
	(linemap_position_for_loc_and_offset): Likewise.
	(linemap_lookup): Likewise.
	(linemap_ordinary_map_lookup): Likewise.
	(linemap_macro_map_lookup): Likewise.
	(linemap_get_expansion_line): Likewise.
	(linemap_get_expansion_filename): Likewise.
	(linemap_location_in_system_header_p): Likewise.
	(linemap_location_from_macro_expansion_p): Likewise.
	(linemap_macro_loc_to_exp_point): Likewise.
	(linemap_resolve_location): Likewise.
	(linemap_unwind_toward_expansion): Likewise.
	(linemap_unwind_to_first_non_reserved_loc): Likewise.
	(linemap_expand_location): Likewise.
	(linemap_dump_location): Likewise.

Modified:
    trunk/libcpp/ChangeLog
    trunk/libcpp/include/line-map.h
    trunk/libcpp/line-map.c
Comment 9 Martin Liška 2019-05-14 11:42:24 UTC
Author: marxin
Date: Tue May 14 11:41:53 2019
New Revision: 271163

URL: https://gcc.gnu.org/viewcvs?rev=271163&root=gcc&view=rev
Log:
Fix min_location usage in line-map.c (PR preprocessor/90382).

2019-05-14  Martin Liska  <mliska@suse.cz>

	PR preprocessor/90382
	* line-map.c (first_map_in_common_1): Handle ADHOC
	locations.

Modified:
    trunk/libcpp/ChangeLog
    trunk/libcpp/line-map.c
Comment 10 Martin Liška 2019-05-14 11:44:26 UTC
Author: marxin
Date: Tue May 14 11:43:55 2019
New Revision: 271164

URL: https://gcc.gnu.org/viewcvs?rev=271164&root=gcc&view=rev
Log:
Reapply r270597.

2019-05-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR preprocessor/90382
	* decl.c (grokdeclarator): Fix value assigned to typespec_loc, use
	min_location.
2019-05-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR preprocessor/90382
	* g++.dg/diagnostic/trailing1.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/diagnostic/trailing1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 11 Martin Liška 2019-05-14 11:49:48 UTC
Fixed.