https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71101
Bug ID: 71101 Summary: ICE in libcpp/line-map.c:linemap_macro_map_lookup very early in offloading compilation lto1 front end Product: gcc Version: 7.0 Status: UNCONFIRMED Keywords: openacc, openmp Severity: minor Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: tschwinge at gcc dot gnu.org CC: dmalcolm at gcc dot gnu.org Target Milestone: --- I'm running into an ICE in libcpp/line-map code, when in GDB doing a "call debug_tree(decl)", very early in a lto1 front end that is reading in an offloading compilation stream. That setting will be a bit difficult to reproduce, but perhaps the following information gives enough clues already? (Putting David in CC as he's done a lot of line-map changes recently -- but I'm not claiming that any of his changes are actually related to this.) Is it maybe just "too early" to call debug_tree in that situation, or should that be handled in some way or another? Breakpoint 2, lto_register_function_decl_in_symtab (data_in=data_in@entry=0x15832b0, decl=0x7ffff6989d20, ix=ix@entry=175) at [...]/source-gcc/gcc/lto/lto.c:871 871 { Here I manually call: (gdb) call debug_tree(decl) <function_decl 0x7ffff6989d20 main._omp_fn.0 type <function_type 0x7ffff695dd20 type <void_type 0x7ffff68dd000 void VOID align 8 symtab 0 alias set -1 structural equality pointer_to_this <pointer_type 0x7ffff68dd150>> QI size <integer_cst 0x7ffff68cd468 constant 8> unit size <integer_cst 0x7ffff68cd480 constant 1> align 8 symtab 0 alias set -1 structural equality arg-types <tree_list 0x7ffff6986de8 value <pointer_type 0x7ffff68dd150> chain <tree_list 0x7ffff68d0a50 value <void_type 0x7ffff68dd000 void>>>> addressable nothrow staticlto1: internal compiler error: in linemap_macro_map_lookup, at libcpp/line-map.c:984 (Notice the ICE message starting after "addressable nothrow static".) That's the following linemap_assert: /* Given a source location yielded by a macro map, returns that map. Since the set is built chronologically, the logical lines are monotonic decreasing, and so the list is sorted and we can use a binary search. */ static const line_map_macro * linemap_macro_map_lookup (struct line_maps *set, source_location line) { unsigned int md, mn, mx; const struct line_map_macro *cached, *result; if (IS_ADHOC_LOC (line)) line = set->location_adhoc_data_map.data[line & MAX_SOURCE_LOCATION].locus; linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set)); Rebuilding that part with "-O0", I see the following backtrace: #1 0x0000000000fd4373 in linemap_macro_map_lookup (set=set@entry=0x7ffff7ff5000, line=line@entry=2) at [...]/source-gcc/libcpp/line-map.c:986 #2 0x0000000000fd5131 in linemap_lookup (set=set@entry=0x7ffff7ff5000, line=line@entry=2) at [...]/source-gcc/libcpp/line-map.c:920 #3 0x0000000000fd62c4 in linemap_location_in_system_header_p (set=0x7ffff7ff5000, location=2) at [...]/source-gcc/libcpp/line-map.c:1191 #4 0x00000000009a2202 in print_node (file=0x7ffff6e91640 <_IO_2_1_stderr_>, prefix=prefix@entry=0x1105de0 "", node=node@entry=0x7ffff6989d20, indent=indent@entry=0) at [...]/source-gcc/gcc/print-tree.c:373 #5 0x00000000009a6380 in debug_tree (node=0x7ffff6989d20) at [...]/source-gcc/gcc/print-tree.c:976 #6 <function called from gdb> [...] (gdb) frame 1 #1 0x0000000000fd4373 in linemap_macro_map_lookup (set=set@entry=0x7ffff7ff5000, line=line@entry=2) at [...]/source-gcc/libcpp/line-map.c:986 986 linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set)); (gdb) print line $1 = 2 (gdb) print set $2 = (line_maps *) 0x7ffff7ff5000 (gdb) print *set $3 = {info_ordinary = {maps = 0x0, allocated = 0, used = 0, cache = 0}, info_macro = {maps = 0x0, allocated = 0, used = 0, cache = 0}, depth = 0, trace_includes = false, highest_location = 1, highest_line = 1, max_column_hint = 0, reallocator = 0xa403b0 <realloc_for_line_map(void*, size_t)>, round_alloc_size = 0x5a9b10 <ggc_round_alloc_size(unsigned long)>, location_adhoc_data_map = {htab = 0x157e550, curr_loc = 0, allocated = 0, data = 0x0}, builtin_location = 1, seen_line_directive = false, default_range_bits = 5, num_optimized_ranges = 0, num_unoptimized_ranges = 0} (gdb) call line_table_dump(0,set,-1,-1) # of ordinary maps: 0 # of macro maps: 0 Include stack depth: 0 Highest location: 1 Ordinary line maps Macro line maps If that helps any: running through this again, I see "line" is not considered "IS_ADHOC_LOC": (gdb) list 974 monotonic decreasing, and so the list is sorted and we can use a 975 binary search. */ 976 977 static const line_map_macro * 978 linemap_macro_map_lookup (struct line_maps *set, source_location line) 979 { 980 unsigned int md, mn, mx; 981 const struct line_map_macro *cached, *result; 982 983 if (IS_ADHOC_LOC (line)) (gdb) n 983 if (IS_ADHOC_LOC (line)) (gdb) s IS_ADHOC_LOC (loc=loc@entry=2) at [...]/source-gcc/gcc/../libcpp/include/line-map.h:975 975 { (gdb) print loc $4 = 2 (gdb) s 976 return (loc & MAX_SOURCE_LOCATION) != loc; (gdb) finish Run till exit from #0 IS_ADHOC_LOC (loc=loc@entry=2) at [...]/source-gcc/gcc/../libcpp/include/line-map.h:976 0x0000000000fd4318 in linemap_macro_map_lookup (set=set@entry=0x7ffff7ff5000, line=line@entry=2) at [...]/source-gcc/libcpp/line-map.c:983 983 if (IS_ADHOC_LOC (line)) Value returned is $5 = false (gdb) s 986 linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set)); (gdb) s LINEMAPS_MACRO_LOWEST_LOCATION (set=set@entry=0x7ffff7ff5000) at [...]/source-gcc/libcpp/include/line-map.h:947 947 { (gdb) list 942 943 /* Returns the lowest location [of a token resulting from macro 944 expansion] encoded in this line table. */ 945 inline source_location 946 LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set) 947 { 948 return LINEMAPS_MACRO_USED (set) 949 ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set)) 950 : MAX_SOURCE_LOCATION; 951 } (gdb) finish Run till exit from #0 LINEMAPS_MACRO_LOWEST_LOCATION (set=set@entry=0x7ffff7ff5000) at [...]/source-gcc/libcpp/include/line-map.h:947 0x0000000000fd4354 in linemap_macro_map_lookup (set=set@entry=0x7ffff7ff5000, line=line@entry=2) at [...]/source-gcc/libcpp/line-map.c:986 986 linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set)); Value returned is $6 = 2147483647 (gdb) s Breakpoint 1, fancy_abort ( [...] And, here is the original source code; the "function_decl 0x7ffff6989d20 main._omp_fn.0" is an outlined function corresponding to the offloaded code (the structured block/statement after the "#pragma acc parallel"): #include <math.h> int main(int argc, char *argv[]) { double t1, t2; t1 = 7.07 * argc; #pragma acc parallel copyout(t2) t2 = sin(t1) * cos(t1) + sqrt(-2.0 * logf(t1) / t1); return t2 < 0; }