Re: [preprocessor] a few cleanups in c-family

2020-05-21 Thread Nathan Sidwell

On 5/21/20 4:02 AM, Andreas Schwab wrote:

On Mai 20 2020, Nathan Sidwell wrote:


I'm reverting that change.  It is not ready.  The first map has a
different string for the main file name, and we were relying on that not
equalling the later ones via pointer comparison.

I must have become confused over what tree I was testing.  Sorry about that.


What's up with gcc/testsuite/c-c++-common/cpp/cmd-1.c?


aw crap.  and man those were hard to delete.  The commit hooks are FAR 
TOO PICKY NOW.


nathan

--
Nathan Sidwell


Re: [preprocessor] a few cleanups in c-family

2020-05-21 Thread Andreas Schwab
On Mai 20 2020, Nathan Sidwell wrote:

> I'm reverting that change.  It is not ready.  The first map has a
> different string for the main file name, and we were relying on that not 
> equalling the later ones via pointer comparison.
>
> I must have become confused over what tree I was testing.  Sorry about that.

What's up with gcc/testsuite/c-c++-common/cpp/cmd-1.c?

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [preprocessor] a few cleanups in c-family

2020-05-20 Thread Nathan Sidwell

On 5/20/20 2:22 PM, Nathan Sidwell wrote:

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.



I'm reverting that change.  It is not ready.  The first map has a 
different string for the main file name, and we were relying on that not 
equalling the later ones via pointer comparison.


I must have become confused over what tree I was testing.  Sorry about that.

nathan

--
Nathan Sidwell
2020-05-20  Nathan Sidwell  

	* c-common.c (try_to_locate_new_include_insertion_point): Revert change.

diff --git i/gcc/c-family/c-common.c w/gcc/c-family/c-common.c
index 10c0353fe4e..b1379faa412 100644
--- i/gcc/c-family/c-common.c
+++ w/gcc/c-family/c-common.c
@@ -8708,8 +8708,7 @@ try_to_locate_new_include_insertion_point (const char *file, location_t loc)
 	last_ord_map_after_include = NULL;
 	  }
 
-  if (0 == strcmp (ord_map->to_file, file)
-	  && ord_map->to_line)
+  if (ord_map->to_file == file)
 	{
 	  if (!first_ord_map_in_file)
 	first_ord_map_in_file = ord_map;


[preprocessor] a few cleanups in c-family

2020-05-20 Thread Nathan Sidwell

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  

	* 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 = _opts[i];
+  if (mkdeps *deps = cpp_get_deps (parse_in))
+for (unsigned i = 0; i < deferred_count; i++)
+  {
+	struct deferred_opt *opt = _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