public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] Fix -I ""
@ 2010-12-15 15:17 Jie Zhang
  2010-12-16 21:51 ` Joseph S. Myers
  0 siblings, 1 reply; 10+ messages in thread
From: Jie Zhang @ 2010-12-15 15:17 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1212 bytes --]

Currently gcc behaves weirdly when an empty string argument passed to -I 
option.

On x86_64-linux-gnu, the latest gcc from trunk:
$ gcc -I "" -c -o t.o t.c
cc1: warning: t.c: not a directory [enabled by default]
[hang]

$ gcc-4.5 -I "" -c -o t.o t.c
[hang]

$ gcc-4.4 -I "" -c -o t.o t.c
cc1: error: t.c: not a directory
[hang]

$ gcc-4.3 -I "" -c -o t.o t.c
cc1: error: t.c: not a directory

For cross compiler from latest trunk:
$ arm-none-linux-gnueabi-gcc -I "" -c t.c -o t.o
cc1: fatal error: 
/scratch/jie/fsf-arm-linux-gnueabi/install/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.0/: 
No such file or directory
compilation terminated.

This issue occurs because do_spec_1 drops the empty string argument.

The attached patch changes do_spec_1 not to drop empty string argument 
and change other places to print "" for such argument when verbose.

Another way to fix this issue might change gcc to error out for -I "". 
But I think accepting it and passing it down is better. If empty string 
argument is an error, subcommands should report it. In this case, the 
compiler don't think it's an error

Bootstrapped on x86_64-linux-gnu and regression tested with c,c++,lto.

Is it OK?


Regards,
-- 
Jie Zhang


[-- Attachment #2: gcc-empty-include-dir.diff --]
[-- Type: text/x-diff, Size: 2387 bytes --]


	* opts-common.c (decode_cmdline_option): Print empty string
	argument as "" in decoded->orig_option_with_args_text.
	* gcc.c (execute): Print empty string argument as ""
	in the verbose output.
	(do_spec_1): Keep empty string argument.

	testsuite/
	* gcc.dg/cpp/include7.c: New test.

Index: opts-common.c
===================================================================
--- opts-common.c	(revision 167855)
+++ opts-common.c	(working copy)
@@ -637,7 +637,14 @@ decode_cmdline_option (const char **argv
     {
       size_t len = strlen (argv[i]);
 
-      memcpy (p, argv[i], len);
+      /* Print the empty string verbally.  */
+      if (len == 0)
+	{
+	  *p++ = '"';
+	  *p++ = '"';
+	}
+      else
+	memcpy (p, argv[i], len);
       p += len;
       if (i == result - 1)
 	*p++ = 0;
Index: gcc.c
===================================================================
--- gcc.c	(revision 167855)
+++ gcc.c	(working copy)
@@ -2521,13 +2521,20 @@ execute (void)
 			}
 		      fputc ('"', stderr);
 		    }
+		  /* If it's empty, print "".  */
+		  else if (!**j)
+		    fprintf (stderr, " \"\"");
 		  else
 		    fprintf (stderr, " %s", *j);
 		}
 	    }
 	  else
 	    for (j = commands[i].argv; *j; j++)
-	      fprintf (stderr, " %s", *j);
+	      /* If it's empty, print "".  */
+	      if (!**j)
+		fprintf (stderr, " \"\"");
+	      else
+		fprintf (stderr, " %s", *j);
 
 	  /* Print a pipe symbol after all but the last command.  */
 	  if (i + 1 != n_commands)
@@ -4398,6 +4405,10 @@ do_spec_1 (const char *spec, int inswitc
   int i;
   int value;
 
+  /* If it's an empty string argument to a switch, keep it as is.  */
+  if (inswitch && !*p)
+    arg_going = 1;
+
   while ((c = *p++))
     /* If substituting a switch, treat all chars like letters.
        Otherwise, NL, SPC, TAB and % are special.  */
@@ -5117,7 +5128,8 @@ do_spec_1 (const char *spec, int inswitc
 	  case '*':
 	    if (soft_matched_part)
 	      {
-		do_spec_1 (soft_matched_part, 1, NULL);
+		if (soft_matched_part[0])
+		  do_spec_1 (soft_matched_part, 1, NULL);
 		do_spec_1 (" ", 0, NULL);
 	      }
 	    else
Index: testsuite/gcc.dg/cpp/include7.c
===================================================================
--- testsuite/gcc.dg/cpp/include7.c	(revision 0)
+++ testsuite/gcc.dg/cpp/include7.c	(revision 0)
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "-I \"\"" } */
+

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Fix -I ""
  2010-12-15 15:17 [RFC] Fix -I "" Jie Zhang
@ 2010-12-16 21:51 ` Joseph S. Myers
  2010-12-17  5:57   ` Jie Zhang
  0 siblings, 1 reply; 10+ messages in thread
From: Joseph S. Myers @ 2010-12-16 21:51 UTC (permalink / raw)
  To: Jie Zhang; +Cc: gcc-patches

The gcc.c changes in this patch are OK if there are no objections within 
48 hours.

The opts-common.c changes aren't correct by themselves; if you increase 
the amount of text going in orig_option_with_args_text then you also need 
to update the earlier loop computing how much memory to allocate for that 
string.  (Note also I can't approve changes to opts-common.c.)

Have you confirmed the testcase actually tests what you want it to test - 
that is, that it fails before the rest of the patch is applied and passes 
afterwards?  I don't know if passing empty arguments through DejaGnu is 
reliable.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Fix -I ""
  2010-12-16 21:51 ` Joseph S. Myers
@ 2010-12-17  5:57   ` Jie Zhang
  2010-12-23  7:10     ` PING " Jie Zhang
  0 siblings, 1 reply; 10+ messages in thread
From: Jie Zhang @ 2010-12-17  5:57 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1923 bytes --]

On 12/17/2010 04:37 AM, Joseph S. Myers wrote:
> The gcc.c changes in this patch are OK if there are no objections within
> 48 hours.
>
> The opts-common.c changes aren't correct by themselves; if you increase
> the amount of text going in orig_option_with_args_text then you also need
> to update the earlier loop computing how much memory to allocate for that
> string.  (Note also I can't approve changes to opts-common.c.)
>
Oops! Thanks! The attached updated patch has this fixed.

> Have you confirmed the testcase actually tests what you want it to test -
> that is, that it fails before the rest of the patch is applied and passes
> afterwards?  I don't know if passing empty arguments through DejaGnu is
> reliable.
>
Yes, I have confirmed. Since you asked, I took a closer look. One thing 
strange I observed is: in the gcc.log

Executing on host: /home/jie/sources/gcc/builds/build.svn-trunk/gcc/xgcc 
-B/home/jie/sources/gcc/builds/build.svn-trunk/gcc/ 
/home/jie/sources/gcc/svn/trunk/gcc/testsuite/gcc.dg/cpp/include7.c   -I 
"" -S  -o include7.s    (timeout = 300)
spawn /home/jie/sources/gcc/builds/build.svn-trunk/gcc/xgcc 
-B/home/jie/sources/gcc/builds/build.svn-trunk/gcc/ 
/home/jie/sources/gcc/svn/trunk/gcc/testsuite/gcc.dg/cpp/include7.c -I 
-S -o include7.s

you can see there is no "" after -I in "spawn" line but there is in 
"Executing" line. But I'm sure xgcc got '-I ""' instead of just '-I', 
since there are these lines just following the above two lines without 
this patch:

cc1: fatal error: 
/home/jie/installs/x86_64/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/: No 
such file or directory
compilation terminated.
compiler exited with status 1

but everything is OK with this patch.

I don't know how was the above "spawn" line printed out. I grep in 
/usr/share/dejagnu, but found nothing related. It's from

set result [catch "eval spawn \{${commandline}\}" pid]


Regards,
-- 
Jie Zhang


[-- Attachment #2: gcc-empty-include-dir-2.diff --]
[-- Type: text/x-diff, Size: 2913 bytes --]


	* opts-common.c (decode_cmdline_option): Print empty string
	argument as "" in decoded->orig_option_with_args_text.
	* gcc.c (execute): Print empty string argument as ""
	in the verbose output.
	(do_spec_1): Keep empty string argument.

	testsuite/
	* gcc.dg/cpp/include7.c: New test.

Index: opts-common.c
===================================================================
--- opts-common.c	(revision 167855)
+++ opts-common.c	(working copy)
@@ -607,11 +607,15 @@ decode_cmdline_option (const char **argv
     {
       if (i < result)
 	{
+	  size_t len;
 	  if (opt_index == OPT_SPECIAL_unknown)
 	    decoded->canonical_option[i] = argv[i];
 	  else
 	    decoded->canonical_option[i] = NULL;
-	  total_len += strlen (argv[i]) + 1;
+	  len = strlen (argv[i]);
+	  /* If the argument is an empty string, we will print it as "" in
+	     orig_option_with_args_text.  */
+	  total_len += (len != 0 ? len : 2) + 1;
 	}
       else
 	decoded->canonical_option[i] = NULL;
@@ -637,7 +641,14 @@ decode_cmdline_option (const char **argv
     {
       size_t len = strlen (argv[i]);
 
-      memcpy (p, argv[i], len);
+      /* Print the empty string verbally.  */
+      if (len == 0)
+	{
+	  *p++ = '"';
+	  *p++ = '"';
+	}
+      else
+	memcpy (p, argv[i], len);
       p += len;
       if (i == result - 1)
 	*p++ = 0;
Index: gcc.c
===================================================================
--- gcc.c	(revision 167855)
+++ gcc.c	(working copy)
@@ -2521,13 +2521,20 @@ execute (void)
 			}
 		      fputc ('"', stderr);
 		    }
+		  /* If it's empty, print "".  */
+		  else if (!**j)
+		    fprintf (stderr, " \"\"");
 		  else
 		    fprintf (stderr, " %s", *j);
 		}
 	    }
 	  else
 	    for (j = commands[i].argv; *j; j++)
-	      fprintf (stderr, " %s", *j);
+	      /* If it's empty, print "".  */
+	      if (!**j)
+		fprintf (stderr, " \"\"");
+	      else
+		fprintf (stderr, " %s", *j);
 
 	  /* Print a pipe symbol after all but the last command.  */
 	  if (i + 1 != n_commands)
@@ -4398,6 +4405,10 @@ do_spec_1 (const char *spec, int inswitc
   int i;
   int value;
 
+  /* If it's an empty string argument to a switch, keep it as is.  */
+  if (inswitch && !*p)
+    arg_going = 1;
+
   while ((c = *p++))
     /* If substituting a switch, treat all chars like letters.
        Otherwise, NL, SPC, TAB and % are special.  */
@@ -5117,7 +5128,8 @@ do_spec_1 (const char *spec, int inswitc
 	  case '*':
 	    if (soft_matched_part)
 	      {
-		do_spec_1 (soft_matched_part, 1, NULL);
+		if (soft_matched_part[0])
+		  do_spec_1 (soft_matched_part, 1, NULL);
 		do_spec_1 (" ", 0, NULL);
 	      }
 	    else
Index: testsuite/gcc.dg/cpp/include7.c
===================================================================
--- testsuite/gcc.dg/cpp/include7.c	(revision 0)
+++ testsuite/gcc.dg/cpp/include7.c	(revision 0)
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+/* { dg-options "-I \"\"" } */
+

^ permalink raw reply	[flat|nested] 10+ messages in thread

* PING Re: [RFC] Fix -I ""
  2010-12-17  5:57   ` Jie Zhang
@ 2010-12-23  7:10     ` Jie Zhang
  2011-01-04 11:44       ` PING 2 " Jie Zhang
  0 siblings, 1 reply; 10+ messages in thread
From: Jie Zhang @ 2010-12-23  7:10 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, neil

On 12/17/2010 11:53 AM, Jie Zhang wrote:
> On 12/17/2010 04:37 AM, Joseph S. Myers wrote:
>> The gcc.c changes in this patch are OK if there are no objections within
>> 48 hours.
>>
>> The opts-common.c changes aren't correct by themselves; if you increase
>> the amount of text going in orig_option_with_args_text then you also need
>> to update the earlier loop computing how much memory to allocate for that
>> string. (Note also I can't approve changes to opts-common.c.)
>>
> Oops! Thanks! The attached updated patch has this fixed.
>
Can anyone who can approve option handling patches review that part of 
my patch? Neil Booth is listed as the maintainer of "option handling" in 
MAINTAINERS. But I think he has been not active for several years.

Regards,
-- 
Jie Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

* PING 2 Re: [RFC] Fix -I ""
  2010-12-23  7:10     ` PING " Jie Zhang
@ 2011-01-04 11:44       ` Jie Zhang
  2011-01-10  2:55         ` PING^3 " Jie Zhang
  0 siblings, 1 reply; 10+ messages in thread
From: Jie Zhang @ 2011-01-04 11:44 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joseph S. Myers, neil

PING 2

On 12/23/2010 09:52 AM, Jie Zhang wrote:
> On 12/17/2010 11:53 AM, Jie Zhang wrote:
>> On 12/17/2010 04:37 AM, Joseph S. Myers wrote:
>>> The gcc.c changes in this patch are OK if there are no objections within
>>> 48 hours.
>>>
>>> The opts-common.c changes aren't correct by themselves; if you increase
>>> the amount of text going in orig_option_with_args_text then you also
>>> need
>>> to update the earlier loop computing how much memory to allocate for
>>> that
>>> string. (Note also I can't approve changes to opts-common.c.)
>>>
>> Oops! Thanks! The attached updated patch has this fixed.
>>
> Can anyone who can approve option handling patches review that part of
> my patch? Neil Booth is listed as the maintainer of "option handling" in
> MAINTAINERS. But I think he has been not active for several years.
>

-- 
Jie Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

* PING^3 Re: [RFC] Fix -I ""
  2011-01-04 11:44       ` PING 2 " Jie Zhang
@ 2011-01-10  2:55         ` Jie Zhang
  2011-01-17  2:10           ` PING^4 " Jie Zhang
  0 siblings, 1 reply; 10+ messages in thread
From: Jie Zhang @ 2011-01-10  2:55 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joseph S. Myers, neil

PING 3

On 01/04/2011 06:49 PM, Jie Zhang wrote:
> PING 2
>
> On 12/23/2010 09:52 AM, Jie Zhang wrote:
>> On 12/17/2010 11:53 AM, Jie Zhang wrote:
>>> On 12/17/2010 04:37 AM, Joseph S. Myers wrote:
>>>> The gcc.c changes in this patch are OK if there are no objections
>>>> within
>>>> 48 hours.
>>>>
>>>> The opts-common.c changes aren't correct by themselves; if you increase
>>>> the amount of text going in orig_option_with_args_text then you also
>>>> need
>>>> to update the earlier loop computing how much memory to allocate for
>>>> that
>>>> string. (Note also I can't approve changes to opts-common.c.)
>>>>
>>> Oops! Thanks! The attached updated patch has this fixed.
>>>
>> Can anyone who can approve option handling patches review that part of
>> my patch? Neil Booth is listed as the maintainer of "option handling" in
>> MAINTAINERS. But I think he has been not active for several years.
>>
>

-- 
Jie Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

* PING^4 Re: [RFC] Fix -I ""
  2011-01-10  2:55         ` PING^3 " Jie Zhang
@ 2011-01-17  2:10           ` Jie Zhang
  2011-02-21 16:43             ` PING^5 " Jie Zhang
  0 siblings, 1 reply; 10+ messages in thread
From: Jie Zhang @ 2011-01-17  2:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joseph S. Myers, neil

PING 4

On 01/10/2011 10:39 AM, Jie Zhang wrote:
> PING 3
>
> On 01/04/2011 06:49 PM, Jie Zhang wrote:
>> PING 2
>>
>> On 12/23/2010 09:52 AM, Jie Zhang wrote:
>>> On 12/17/2010 11:53 AM, Jie Zhang wrote:
>>>> On 12/17/2010 04:37 AM, Joseph S. Myers wrote:
>>>>> The gcc.c changes in this patch are OK if there are no objections
>>>>> within
>>>>> 48 hours.
>>>>>
>>>>> The opts-common.c changes aren't correct by themselves; if you
>>>>> increase
>>>>> the amount of text going in orig_option_with_args_text then you also
>>>>> need
>>>>> to update the earlier loop computing how much memory to allocate for
>>>>> that
>>>>> string. (Note also I can't approve changes to opts-common.c.)
>>>>>
>>>> Oops! Thanks! The attached updated patch has this fixed.
>>>>
>>> Can anyone who can approve option handling patches review that part of
>>> my patch? Neil Booth is listed as the maintainer of "option handling" in
>>> MAINTAINERS. But I think he has been not active for several years.
>>>
>>
>

-- 
Jie Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

* PING^5 Re: [RFC] Fix -I ""
  2011-01-17  2:10           ` PING^4 " Jie Zhang
@ 2011-02-21 16:43             ` Jie Zhang
  2011-02-22 23:10               ` Joseph S. Myers
  0 siblings, 1 reply; 10+ messages in thread
From: Jie Zhang @ 2011-02-21 16:43 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, neil

Hi Joseph,

Since you are one of the maintainers for "option handling", could you 
please also help review the option handling part of my patch? Thanks!

Jie

On 01/17/2011 10:00 AM, Jie Zhang wrote:
> PING 4
>
> On 01/10/2011 10:39 AM, Jie Zhang wrote:
>> PING 3
>>
>> On 01/04/2011 06:49 PM, Jie Zhang wrote:
>>> PING 2
>>>
>>> On 12/23/2010 09:52 AM, Jie Zhang wrote:
>>>> On 12/17/2010 11:53 AM, Jie Zhang wrote:
>>>>> On 12/17/2010 04:37 AM, Joseph S. Myers wrote:
>>>>>> The gcc.c changes in this patch are OK if there are no objections
>>>>>> within
>>>>>> 48 hours.
>>>>>>
>>>>>> The opts-common.c changes aren't correct by themselves; if you
>>>>>> increase
>>>>>> the amount of text going in orig_option_with_args_text then you also
>>>>>> need
>>>>>> to update the earlier loop computing how much memory to allocate for
>>>>>> that
>>>>>> string. (Note also I can't approve changes to opts-common.c.)
>>>>>>
>>>>> Oops! Thanks! The attached updated patch has this fixed.
>>>>>
>>>> Can anyone who can approve option handling patches review that part of
>>>> my patch? Neil Booth is listed as the maintainer of "option
>>>> handling" in
>>>> MAINTAINERS. But I think he has been not active for several years.
>>>>
>>>
>>
>


-- 
Jie Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PING^5 Re: [RFC] Fix -I ""
  2011-02-21 16:43             ` PING^5 " Jie Zhang
@ 2011-02-22 23:10               ` Joseph S. Myers
  2011-02-23  4:31                 ` Jie Zhang
  0 siblings, 1 reply; 10+ messages in thread
From: Joseph S. Myers @ 2011-02-22 23:10 UTC (permalink / raw)
  To: Jie Zhang; +Cc: gcc-patches, neil

On Tue, 22 Feb 2011, Jie Zhang wrote:

> Hi Joseph,
> 
> Since you are one of the maintainers for "option handling", could you please
> also help review the option handling part of my patch? Thanks!

The option handling changes in the version at 
<http://gcc.gnu.org/ml/gcc-patches/2010-12/msg01348.html> are OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: PING^5 Re: [RFC] Fix -I ""
  2011-02-22 23:10               ` Joseph S. Myers
@ 2011-02-23  4:31                 ` Jie Zhang
  0 siblings, 0 replies; 10+ messages in thread
From: Jie Zhang @ 2011-02-23  4:31 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, neil

On 02/23/2011 06:49 AM, Joseph S. Myers wrote:
> On Tue, 22 Feb 2011, Jie Zhang wrote:
>
>> Hi Joseph,
>>
>> Since you are one of the maintainers for "option handling", could you please
>> also help review the option handling part of my patch? Thanks!
>
> The option handling changes in the version at
> <http://gcc.gnu.org/ml/gcc-patches/2010-12/msg01348.html>  are OK.
>
Committed on trunk. Thanks!

-- 
Jie Zhang

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-02-23  2:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-15 15:17 [RFC] Fix -I "" Jie Zhang
2010-12-16 21:51 ` Joseph S. Myers
2010-12-17  5:57   ` Jie Zhang
2010-12-23  7:10     ` PING " Jie Zhang
2011-01-04 11:44       ` PING 2 " Jie Zhang
2011-01-10  2:55         ` PING^3 " Jie Zhang
2011-01-17  2:10           ` PING^4 " Jie Zhang
2011-02-21 16:43             ` PING^5 " Jie Zhang
2011-02-22 23:10               ` Joseph S. Myers
2011-02-23  4:31                 ` Jie Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).