From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116040 invoked by alias); 7 Apr 2015 10:55:59 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 115984 invoked by uid 48); 7 Apr 2015 10:55:51 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug pch/65550] [4.8/4.9/5 Regression] ICE (segfault) with pch Date: Tue, 07 Apr 2015 10:55:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: pch X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: ice-on-invalid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: keywords priority cc cf_known_to_work target_milestone short_desc cf_known_to_fail Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg00399.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65550 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|ice-on-valid-code |ice-on-invalid-code Priority|P3 |P2 CC| |jsm28 at gcc dot gnu.org, | |sje at gcc dot gnu.org Known to work|4.9.2 |4.7.4 Target Milestone|5.0 |4.8.5 Summary|[5 Regression] ICE |[4.8/4.9/5 Regression] ICE |(segfault) with pch |(segfault) with pch Known to fail| |4.8.3, 4.9.2 --- Comment #6 from Richard Biener --- Confirmed. 0xfb7742 crash_signal /space/rguenther/src/svn/trunk2/gcc/toplev.c:383 0x197315c linemap_add(line_maps*, lc_reason, unsigned int, char const*, unsigned int) /space/rguenther/src/svn/trunk2/libcpp/line-map.c:303 0x1973b1e linemap_line_start(line_maps*, unsigned int, unsigned int) /space/rguenther/src/svn/trunk2/libcpp/line-map.c:566 0x1973d55 linemap_position_for_column(line_maps*, unsigned int) /space/rguenther/src/svn/trunk2/libcpp/line-map.c:611 0x1970744 _cpp_lex_direct /space/rguenther/src/svn/trunk2/libcpp/lex.c:2340 0x197029a _cpp_lex_token /space/rguenther/src/svn/trunk2/libcpp/lex.c:2176 0x197996f cpp_get_token_1 /space/rguenther/src/svn/trunk2/libcpp/macro.c:2442 0x1979db7 cpp_get_token_with_location(cpp_reader*, unsigned int*) /space/rguenther/src/svn/trunk2/libcpp/macro.c:2628 0x9e2ea3 c_lex_with_flags(tree_node**, unsigned int*, unsigned char*, int) /space/rguenther/src/svn/trunk2/gcc/c-family/c-lex.c:408 #2 0x000000000197315d in linemap_add (set=0x10000fe000, reason=LC_RENAME, sysp=0, to_file=0x24ad430 "../src/include.h", to_line=3) at /space/rguenther/src/svn/trunk2/libcpp/line-map.c:303 303 linemap_assert (!(set->depth == 0 && reason == LC_RENAME)); (gdb) p set->depth $2 = 0 It's correctly initialized by PCH but re-set at Hardware watchpoint 1: *$10 Old value = 1 New value = 0 linemap_add (set=0x10000fe000, reason=LC_LEAVE, sysp=0, to_file=0x0, to_line=0) at /space/rguenther/src/svn/trunk2/libcpp/line-map.c:311 311 return NULL; (gdb) bt #0 linemap_add (set=0x10000fe000, reason=LC_LEAVE, sysp=0, to_file=0x0, to_line=0) at /space/rguenther/src/svn/trunk2/libcpp/line-map.c:311 #1 0x000000000195e29f in _cpp_do_file_change (pfile=0x249a670, reason=LC_LEAVE, to_file=0x0, file_line=0, sysp=0) at /space/rguenther/src/svn/trunk2/libcpp/directives.c:1067 #2 0x0000000001961a5d in _cpp_pop_buffer (pfile=0x249a670) at /space/rguenther/src/svn/trunk2/libcpp/directives.c:2606 #3 0x00000000019704a7 in _cpp_get_fresh_line (pfile=0x249a670) at /space/rguenther/src/svn/trunk2/libcpp/lex.c:2255 #4 0x0000000001970587 in _cpp_lex_direct (pfile=0x249a670) at /space/rguenther/src/svn/trunk2/libcpp/lex.c:2302 #5 0x000000000197029b in _cpp_lex_token (pfile=0x249a670) at /space/rguenther/src/svn/trunk2/libcpp/lex.c:2176 #6 0x0000000001979970 in cpp_get_token_1 (pfile=0x249a670, location=0x7fffffffdc58) ... #10 0x000000000086afd3 in cp_parser_initial_pragma (first_token=0x7fffffffdc50) at /space/rguenther/src/svn/trunk2/gcc/cp/parser.c:32854 #11 0x000000000082eaf7 in cp_lexer_new_main () at /space/rguenther/src/svn/trunk2/gcc/cp/parser.c:650 #12 0x0000000000831d4a in cp_parser_new () at /space/rguenther/src/svn/trunk2/gcc/cp/parser.c:3484 #13 0x000000000086b787 in c_parse_file () at /space/rguenther/src/svn/trunk2/gcc/cp/parser.c:33189 But note that this is an usupported use of PCH - it's included indirectly. We should have rejected it but we don't. Appearantly my fix for that doesn't trigger: 2009-09-22 Richard Guenther PR pch/38987 * files.c (pch_open_file): Disallow non-toplevel PCH inclusion. because of the implicit-preinclude check. (gdb) p pfile->all_files->implicit_preinclude $30 = false (gdb) p pfile->all_files->next_file->implicit_preinclude $31 = true I don't understand why we check two files here... (gdb) p pfile->all_files->name $33 = 0x24ad0c0 "include.h" (gdb) p pfile->all_files->next_file->name $34 = 0x24ac120 "stdc-predef.h" (gdb) p pfile->all_files->next_file->next_file->name $35 = 0x24e3be0 "../src/source.cpp" note how the main file is "last". My patch got two revisions - r192715 by Joseph and r193709 by Steve. I think the code should be changed to sth like /* If the file is not included as first include from either the toplevel file or the command-line it is not a valid use of PCH. */ for (_cpp_file *f = pfile->all_files; f; f = f->next_file) if (f->implicit_preinclude) continue; else if (f->main_file) break; else return false; note the change triggering this bug is in GCC 4.8 already (but not in 4.7). Index: libcpp/files.c =================================================================== --- libcpp/files.c (revision 221891) +++ libcpp/files.c (working copy) @@ -291,11 +291,13 @@ pch_open_file (cpp_reader *pfile, _cpp_f /* If the file is not included as first include from either the toplevel file or the command-line it is not a valid use of PCH. */ - if (pfile->all_files - && pfile->all_files->next_file - && !(pfile->all_files->implicit_preinclude - || pfile->all_files->next_file->implicit_preinclude)) - return false; + for (_cpp_file *f = pfile->all_files; f; f = f->next_file) + if (f->implicit_preinclude) + continue; + else if (f->main_file) + break; + else + return false; flen = strlen (path); len = flen + sizeof (extension);