From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E01FC388187D; Mon, 30 Nov 2020 12:51:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E01FC388187D From: "jruffin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug pch/56549] #pragma once ineffective with BOM in include file Date: Mon, 30 Nov 2020 12:51:38 +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: 4.6.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jruffin at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Nov 2020 12:51:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D56549 --- Comment #7 from Julien Ruffin --- Here is the patch for the current master. I have tested it on large C++ code bases. So far, it builds successfully and significantly faster. diff --git a/libcpp/files.c b/libcpp/files.c index 301b2379a23..cbc2b0f4540 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1978,25 +1978,28 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *fp) result->entries[count].once_only =3D f->once_only; /* |=3D is avoided in the next line because of an HP C compiler bug = */ result->have_once_only =3D result->have_once_only | f->once_only; + if (f->buffer_valid) - md5_buffer ((const char *)f->buffer, - f->st.st_size, result->entries[count].sum); + { + md5_buffer ((const char *)f->buffer, + f->st.st_size, result->entries[count].sum); + } else - { - FILE *ff; - int oldfd =3D f->fd; - - if (!open_file (f)) - { - open_file_failed (pfile, f, 0, 0); - free (result); - return false; - } - ff =3D fdopen (f->fd, "rb"); - md5_stream (ff, result->entries[count].sum); - fclose (ff); - f->fd =3D oldfd; - } + { + if (!read_file (pfile, f, 0)) + { + return false; + } + + md5_buffer ((const char *)f->buffer, + f->st.st_size, result->entries[count].sum); + + const void* to_free =3D f->buffer_start; + f->buffer_start =3D NULL; + f->buffer =3D NULL; + f->buffer_valid =3D false; + free ((void*) to_free); + } result->entries[count].size =3D f->st.st_size; }=