This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: PR preprocessor/39533: -MM may list a header file twice
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 24 Mar 2009 10:23:12 -0700
- Subject: PATCH: PR preprocessor/39533: -MM may list a header file twice
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
-MM may list a header file twice. It is caused by duplicated cpp_dir
entry in file hash. make_cpp_dir may create a cpp_dir for "foo/"
when pfile->quote_include is set to "foo" by -I. We wind up creating
a cpp_dir entry for "foo/" with the next cpp_dir entry points to "foo".
This patch checks if pfile->quote_include points to the same directory
as DIR_NAME. OK for 4.5?
Thanks.
H.J.
---
2009-03-24 H.J. Lu <hongjiu.lu@intel.com>
PR preprocessor/39533
* files.c (make_cpp_dir): Check duplicated cpp_dir entry
against pfile->quote_include.
Index: libcpp/files.c
===================================================================
--- libcpp/files.c (revision 145000)
+++ libcpp/files.c (working copy)
@@ -1007,6 +1007,7 @@ make_cpp_dir (cpp_reader *pfile, const c
{
struct file_hash_entry *entry, **hash_slot;
cpp_dir *dir;
+ unsigned int dir_len;
hash_slot = (struct file_hash_entry **)
htab_find_slot_with_hash (pfile->dir_hash, dir_name,
@@ -1018,12 +1019,23 @@ make_cpp_dir (cpp_reader *pfile, const c
if (entry->start_dir == NULL)
return entry->u.dir;
- dir = XCNEW (cpp_dir);
- dir->next = pfile->quote_include;
- dir->name = (char *) dir_name;
- dir->len = strlen (dir_name);
- dir->sysp = sysp;
- dir->construct = 0;
+ /* All non-empty directory names should end in a '/'. Check if
+ pfile->quote_include is the same as DIR_NAME. We don't want to
+ add an duplicated cpp_dir entry here. */
+ dir_len = strlen (dir_name);
+ if (dir_len == (pfile->quote_include->len + 1)
+ && strncmp (dir_name, pfile->quote_include->name,
+ pfile->quote_include->len) == 0)
+ dir = pfile->quote_include;
+ else
+ {
+ dir = XCNEW (cpp_dir);
+ dir->next = pfile->quote_include;
+ dir->name = (char *) dir_name;
+ dir->len = dir_len;
+ dir->sysp = sysp;
+ dir->construct = 0;
+ }
/* Store this new result in the hash table. */
entry = new_file_hash_entry (pfile);