aboutsummaryrefslogtreecommitdiff
path: root/libcpp/files.c
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2012-04-30 16:57:22 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2012-04-30 16:57:22 +0000
commitb193dfa8991cc20e4a9702e0570243622af35d41 (patch)
tree581955b1c8c4cd0feeefcba220d84666458ed1c7 /libcpp/files.c
parenta7b8107f8ee99629c28ab9e0e5b00c589d8577db (diff)
downloadgcc-b193dfa8991cc20e4a9702e0570243622af35d41.zip
gcc-b193dfa8991cc20e4a9702e0570243622af35d41.tar.gz
gcc-b193dfa8991cc20e4a9702e0570243622af35d41.tar.bz2
re PR c++/52974 (Canonicalize include paths in diagnostics)
2012-04-30 Manuel López-Ibáñez <manu@gcc.gnu.org> Dodji Seketeli <dodji@seketeli.org> PR c++/52974 * libcpp/files.c (maybe_shorter_path): New. (find_file_in_dir): Use it. Co-Authored-By: Dodji Seketeli <dodji@seketeli.org> From-SVN: r186991
Diffstat (limited to 'libcpp/files.c')
-rw-r--r--libcpp/files.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/libcpp/files.c b/libcpp/files.c
index 29ccf3b..5b3a37b 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;