cpp crash with gcc-2.95.2 and cpplib

Neil Booth neil@daikokuya.demon.co.uk
Wed Dec 13 11:13:00 GMT 2000


Niels Möller wrote:-

> It doesn't quite work. But if I add some more initialization,
> 
> --- /usr/local/src/prc-tools-2.0/gcc/gcc/cppfiles.c~	Fri Dec  8 15:21:39 2000
> +++ /usr/local/src/prc-tools-2.0/gcc/gcc/cppfiles.c	Wed Dec 13 10:27:46 2000
> @@ -481,16 +481,17 @@

I don't know what code you're using, but CVS has the initialization
code you posted and its line number is in the 800's.  So I don't think
your results are meaningful for CVS.

I'm committing the patch below.  It tidies things up and it looks
right to me.

> But I'm wondering why -1 was used in the first place. Perhaps storing
> -1 in loc->name_map is a way to cache negative results, "I already
> looked for header.gcc here, and there's no point trying again"? If
> so, the change will cause a lot of unnesseccary syscalls.

No, it doesn't save a syscall, it just saves a lookup in a linked list
(starting at CPP_OPTION (pfile, map_list)).  With the complications it
brought it's not worth it.

If you can test the exact code below, let me know the results.
Clearly, no-one until you has tested CVS -remap for over 8 months.
Secondary look-up code at the end of remap_filename was completely
broken too, and no-one had noticed.  I've fixed that below.

Neil.

	* cppfiles.c (read_name_map): Return null if open () fails.
	(remap_filename): Simplify logic.  Add ICE if it doesn't work
	as expected. Perform secondary lookup attempt on base filename
	only.

Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.92
diff -u -p -r1.92 cppfiles.c
--- cppfiles.c	2000/12/11 07:45:15	1.92
+++ cppfiles.c	2000/12/13 19:06:50
@@ -859,6 +859,7 @@ read_name_map (pfile, dirname)
   char *name;
   FILE *f;
 
+  /* Check the cache of directories, and mappings in their remap file.  */
   for (map_list_ptr = CPP_OPTION (pfile, map_list); map_list_ptr;
        map_list_ptr = map_list_ptr->map_list_next)
     if (! strcmp (map_list_ptr->map_list_name, dirname))
@@ -867,6 +868,8 @@ read_name_map (pfile, dirname)
   map_list_ptr = ((struct file_name_map_list *)
 		  xmalloc (sizeof (struct file_name_map_list)));
   map_list_ptr->map_list_name = xstrdup (dirname);
+
+  /* The end of the list ends in NULL.  */
   map_list_ptr->map_list_map = NULL;
 
   name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
@@ -875,9 +878,9 @@ read_name_map (pfile, dirname)
     strcat (name, "/");
   strcat (name, FILE_NAME_MAP_FILE);
   f = fopen (name, "r");
-  if (!f)
-    map_list_ptr->map_list_map = (struct file_name_map *)-1;
-  else
+
+  /* Silently return NULL if we cannot open.  */
+  if (f)
     {
       int ch;
       int dirlen = strlen (dirname);
@@ -920,6 +923,7 @@ read_name_map (pfile, dirname)
       fclose (f);
     }
   
+  /* Add this information to the cache.  */
   map_list_ptr->map_list_next = CPP_OPTION (pfile, map_list);
   CPP_OPTION (pfile, map_list) = map_list_ptr;
 
@@ -935,15 +939,15 @@ remap_filename (pfile, name, loc)
      struct file_name_list *loc;
 {
   struct file_name_map *map;
-  const char *from, *p, *dir;
+  const char *from, *p;
+  char *dir;
 
   if (! loc->name_map)
-    loc->name_map = read_name_map (pfile,
-				   loc->name
-				   ? loc->name : ".");
-
-  if (loc->name_map == (struct file_name_map *)-1)
-    return name;
+    {
+      loc->name_map = read_name_map (pfile, loc->name ? loc->name : ".");
+      if (! loc->name_map)
+	return name;
+    }
   
   from = name + strlen (loc->name) + 1;
   
@@ -957,29 +961,19 @@ remap_filename (pfile, name, loc)
      /usr/include/sys/header.gcc.  */
   p = strrchr (name, '/');
   if (!p)
-    p = name;
-  if (loc && loc->name
-      && strlen (loc->name) == (size_t) (p - name)
-      && !strncmp (loc->name, name, p - name))
-    /* FILENAME is in SEARCHPTR, which we've already checked.  */
     return name;
 
+  /* We know p != name as absolute paths don't call remap_filename.  */
   if (p == name)
-    {
-      dir = ".";
-      from = name;
-    }
-  else
-    {
-      char * newdir = (char *) alloca (p - name + 1);
-      memcpy (newdir, name, p - name);
-      newdir[p - name] = '\0';
-      dir = newdir;
-      from = p + 1;
-    }
+    cpp_ice (pfile, "absolute file name in remap_filename");
+
+  dir = (char *) alloca (p - name + 1);
+  memcpy (dir, name, p - name);
+  dir[p - name] = '\0';
+  from = p + 1;
   
   for (map = read_name_map (pfile, dir); map; map = map->map_next)
-    if (! strcmp (map->map_from, name))
+    if (! strcmp (map->map_from, from))
       return map->map_to;
 
   return name;


More information about the Gcc-bugs mailing list