From 47b6a3fe6c65ac31da71a415075a18471452c4c1 Mon Sep 17 00:00:00 2001 From: manu Date: Mon, 30 Apr 2012 16:57:22 +0000 Subject: =?UTF-8?q?2012-04-30=20=20Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez=20?= =?UTF-8?q?=20=20=09=20=20=20=20Dodji=20Seketeli=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR c++/52974 * libcpp/files.c (maybe_shorter_path): New. (find_file_in_dir): Use it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186991 138bc75d-0d04-0410-961f-82ee72b054a4 --- libcpp/ChangeLog | 7 +++++++ libcpp/files.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 271148cc07d..8ab26a92aed 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2012-04-30 Manuel López-Ibáñez + Dodji Seketeli + + PR 5297 + * libcpp/files.c (maybe_shorter_path): New. + (find_file_in_dir): Use it. + 2012-04-30 Dodji Seketeli Switch -ftrack-macro-expansion=2 on by default. diff --git a/libcpp/files.c b/libcpp/files.c index 29ccf3b7013..5b3a37b0279 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -341,6 +341,25 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch) return valid; } +/* Canonicalize the path to FILE. Return the canonical form if it is + shorter, otherwise return NULL. This function does NOT free the + memory pointed by FILE. */ + +static char * +maybe_shorter_path (const char * file) +{ + char * file2 = lrealpath (file); + if (file2 && strlen (file2) < strlen (file)) + { + return file2; + } + else + { + free (file2); + return NULL; + } +} + /* Try to open the path FILE->name appended to FILE->dir. This is where remap and PCH intercept the file lookup process. Return true if the file was found, whether or not the open was successful. @@ -361,10 +380,24 @@ find_file_in_dir (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch) if (path) { - hashval_t hv = htab_hash_string (path); + hashval_t hv; char *copy; void **pp; + /* We try to canonicalize system headers. */ + if (file->dir->sysp) + { + char * canonical_path = maybe_shorter_path (path); + if (canonical_path) + { + /* The canonical path was newly allocated. Let's free the + non-canonical one. */ + free (path); + path = canonical_path; + } + } + + hv = htab_hash_string (path); if (htab_find_with_hash (pfile->nonexistent_file_hash, path, hv) != NULL) { file->err_no = ENOENT; -- cgit v1.2.1