diff mbox

Fix precompiled header for '-' being input file (PR, pch/78970)

Message ID 3f5a5773-959f-1c7d-5263-10ab3d1d3467@suse.cz
State New
Headers show

Commit Message

Martin Liška Jan. 5, 2017, 1:08 p.m. UTC
On 01/05/2017 11:09 AM, Jakub Jelinek wrote:
> On Thu, Jan 05, 2017 at 11:01:37AM +0100, Martin Liška wrote:

>> >From 0e14f21128c7aa67ed0eaa10877323a0b2011b63 Mon Sep 17 00:00:00 2001

>> From: marxin <mliska@suse.cz>

>> Date: Wed, 4 Jan 2017 16:04:44 +0100

>> Subject: [PATCH] Error for '-' as filename of a precompiled header (PR

>>  pch/78970)

>>

>> gcc/ChangeLog:

>>

>> 2017-01-05  Martin Liska  <mliska@suse.cz>

>>

>> 	* gcc.c (lookup_compiler): Reject '-' filename for a precompiled

>> 	header.

>> ---

>>  gcc/gcc.c | 14 +++++++++++++-

>>  1 file changed, 13 insertions(+), 1 deletion(-)

>>

>> diff --git a/gcc/gcc.c b/gcc/gcc.c

>> index 8154953eb1d..ea4af119e73 100644

>> --- a/gcc/gcc.c

>> +++ b/gcc/gcc.c

>> @@ -8325,7 +8325,19 @@ lookup_compiler (const char *name, size_t length, const char *language)

>>      {

>>        for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)

>>  	if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))

>> -	  return cp;

>> +	  {

>> +	    if (name != NULL && strcmp (name, "-") == 0

>> +		&& (strcmp (cp->suffix, "@c-header") == 0

>> +		    || strcmp (cp->suffix, "@c++-header") == 0))

>> +	      {

>> +		fatal_error (input_location,

>> +			     "can't use '-' as input filename for a "

>> +			     "precompiled header");

> 

> That would be can%'t


Change to 'cannot', as Andreas suggested.

> 

> Won't the compiler still ICE if you invoke cc1 or cc1plus rather than the driver?


It ICEs, fixed in the patch that bootstraps and survives regression tests.

Martin

> 

> 	Jakub

>

Comments

Jakub Jelinek Jan. 5, 2017, 1:30 p.m. UTC | #1
On Thu, Jan 05, 2017 at 02:08:40PM +0100, Martin Liška wrote:
> diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c

> index 14e038c02b3..49df9e19157 100644

> --- a/gcc/c-family/c-opts.c

> +++ b/gcc/c-family/c-opts.c

> @@ -744,7 +744,12 @@ c_common_post_options (const char **pfilename)

>        in_fnames[0] = "";

>      }

>    else if (strcmp (in_fnames[0], "-") == 0)

> -    in_fnames[0] = "";

> +    {

> +      if (pch_file)

> +	error ("cannot use '-' as input filename for a precompiled header");


Please use %<-%> instead of '-', in both places.

> diff --git a/gcc/gcc.c b/gcc/gcc.c

> index 8154953eb1d..f42c4ef372e 100644

> --- a/gcc/gcc.c

> +++ b/gcc/gcc.c

> @@ -8325,7 +8325,19 @@ lookup_compiler (const char *name, size_t length, const char *language)

>      {

>        for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)

>  	if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))

> -	  return cp;

> +	  {

> +	    if (name != NULL && strcmp (name, "-") == 0

> +		&& (strcmp (cp->suffix, "@c-header") == 0

> +		    || strcmp (cp->suffix, "@c++-header") == 0))

> +	      {

> +		fatal_error (input_location,

> +			     "cannot use '-' as input filename for a "

> +			     "precompiled header");

> +		return 0;

> +	      }


Isn't fatal_error noreturn?  Then it doesn't make sense to do return 0
after it, so perhaps remove {} and return 0; ?

Ok with those changes.

	Jakub
Martin Liška Jan. 5, 2017, 2:17 p.m. UTC | #2
On 01/05/2017 02:30 PM, Jakub Jelinek wrote:
> On Thu, Jan 05, 2017 at 02:08:40PM +0100, Martin Liška wrote:

>> diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c

>> index 14e038c02b3..49df9e19157 100644

>> --- a/gcc/c-family/c-opts.c

>> +++ b/gcc/c-family/c-opts.c

>> @@ -744,7 +744,12 @@ c_common_post_options (const char **pfilename)

>>        in_fnames[0] = "";

>>      }

>>    else if (strcmp (in_fnames[0], "-") == 0)

>> -    in_fnames[0] = "";

>> +    {

>> +      if (pch_file)

>> +	error ("cannot use '-' as input filename for a precompiled header");

> 

> Please use %<-%> instead of '-', in both places.


Done.

> 

>> diff --git a/gcc/gcc.c b/gcc/gcc.c

>> index 8154953eb1d..f42c4ef372e 100644

>> --- a/gcc/gcc.c

>> +++ b/gcc/gcc.c

>> @@ -8325,7 +8325,19 @@ lookup_compiler (const char *name, size_t length, const char *language)

>>      {

>>        for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)

>>  	if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))

>> -	  return cp;

>> +	  {

>> +	    if (name != NULL && strcmp (name, "-") == 0

>> +		&& (strcmp (cp->suffix, "@c-header") == 0

>> +		    || strcmp (cp->suffix, "@c++-header") == 0))

>> +	      {

>> +		fatal_error (input_location,

>> +			     "cannot use '-' as input filename for a "

>> +			     "precompiled header");

>> +		return 0;

>> +	      }

> 

> Isn't fatal_error noreturn?  Then it doesn't make sense to do return 0

> after it, so perhaps remove {} and return 0; ?

> 

> Ok with those changes.


Likewise, installed as r244103. Is it fine to backport to both active branches?

Thanks,
Martin


> 

> 	Jakub

>
diff mbox

Patch

From c2d521336f6c2d8d0048352dde6e690de7dc1ddd Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 4 Jan 2017 16:04:44 +0100
Subject: [PATCH] Error for '-' as filename of a precompiled header (PR
 pch/78970)

gcc/c-family/ChangeLog:

2017-01-05  Martin Liska  <mliska@suse.cz>

	* c-opts.c (c_common_post_options): Reject '-' filename for a precompiled
	header.

gcc/ChangeLog:

2017-01-05  Martin Liska  <mliska@suse.cz>

	* gcc.c (lookup_compiler): Reject '-' filename for a precompiled
	header.
---
 gcc/c-family/c-opts.c |  7 ++++++-
 gcc/gcc.c             | 14 +++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 14e038c02b3..49df9e19157 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -744,7 +744,12 @@  c_common_post_options (const char **pfilename)
       in_fnames[0] = "";
     }
   else if (strcmp (in_fnames[0], "-") == 0)
-    in_fnames[0] = "";
+    {
+      if (pch_file)
+	error ("cannot use '-' as input filename for a precompiled header");
+
+      in_fnames[0] = "";
+    }
 
   if (out_fname == NULL || !strcmp (out_fname, "-"))
     out_fname = "";
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 8154953eb1d..f42c4ef372e 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -8325,7 +8325,19 @@  lookup_compiler (const char *name, size_t length, const char *language)
     {
       for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
 	if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
-	  return cp;
+	  {
+	    if (name != NULL && strcmp (name, "-") == 0
+		&& (strcmp (cp->suffix, "@c-header") == 0
+		    || strcmp (cp->suffix, "@c++-header") == 0))
+	      {
+		fatal_error (input_location,
+			     "cannot use '-' as input filename for a "
+			     "precompiled header");
+		return 0;
+	      }
+
+	    return cp;
+	  }
 
       error ("language %s not recognized", language);
       return 0;
-- 
2.11.0