Here are some small cleanups.

The one bug fix is try_to_locate_new_include_insertion_point was using pointer comparison to compare strings. This usually works, because the line table doesn't duplicate file names. Except when reading preprocessed input. In that case this was failing horribly. I do not add a pointer comparison on the, possibly rash, assumption strcmp does that already.

The other two are merely moving local var decls to their point of initialization, and using the c++ idiom of allowing that as an if condition.

pushed to master

nathan

--
Nathan Sidwell
2020-05-20  Nathan Sidwell  <nat...@acm.org>

	* c-common.c (try_to_locate_new_include_insertion_point): Use
	strcmp to compare filenames.
	* c-lex.c (init_c_lex): Move declaration to initialization.
	* c-opts.c (handle_deferred_opts): Move cpp_get_deps call into
	deferred count loop.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index b1379faa412..10c0353fe4e 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -8708,7 +8708,8 @@ try_to_locate_new_include_insertion_point (const char *file, location_t loc)
 	    last_ord_map_after_include = NULL;
 	  }
 
-      if (ord_map->to_file == file)
+      if (0 == strcmp (ord_map->to_file, file)
+	  && ord_map->to_line)
 	{
 	  if (!first_ord_map_in_file)
 	    first_ord_map_in_file = ord_map;
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index f0fa9683b0a..b1cef2345f4 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -60,7 +60,6 @@ static void cb_undef (cpp_reader *, unsigned int, cpp_hashnode *);
 void
 init_c_lex (void)
 {
-  struct cpp_callbacks *cb;
   struct c_fileinfo *toplevel;
 
   /* The get_fileinfo data structure must be initialized before
@@ -73,7 +72,7 @@ init_c_lex (void)
       toplevel->time = body_time;
     }
 
-  cb = cpp_get_callbacks (parse_in);
+  struct cpp_callbacks *cb = cpp_get_callbacks (parse_in);
 
   cb->line_change = cb_line_change;
   cb->ident = cb_ident;
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 7695e88c130..8a5131b8ac6 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1317,15 +1317,14 @@ handle_deferred_opts (void)
   if (!deps_seen)
     return;
 
-  mkdeps *deps = cpp_get_deps (parse_in);
-
-  for (size_t i = 0; i < deferred_count; i++)
-    {
-      struct deferred_opt *opt = &deferred_opts[i];
+  if (mkdeps *deps = cpp_get_deps (parse_in))
+    for (unsigned i = 0; i < deferred_count; i++)
+      {
+	struct deferred_opt *opt = &deferred_opts[i];
 
-      if (opt->code == OPT_MT || opt->code == OPT_MQ)
-	deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
-    }
+	if (opt->code == OPT_MT || opt->code == OPT_MQ)
+	  deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
+      }
 }
 
 /* These settings are appropriate for GCC, but not necessarily so for

Reply via email to