public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* parameter type of  -frandom-seed
@ 2015-08-25 16:48 Stephan Gatzka
  2015-08-25 23:42 ` Martin Sebor
  0 siblings, 1 reply; 7+ messages in thread
From: Stephan Gatzka @ 2015-08-25 16:48 UTC (permalink / raw)
  To: gcc-help

Hi!

I'm a bit confused about the parameter I have to deliver to -frandom
-seed.

My manual page states it must be a number, others say it's a string.

If I browse through the sources of gcc, it's also not not obvious to me.

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/common.opt;hb=HEAD

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/po/de.po;hb=HEAD

So what's the correct parameter ffor -frandom-seed? A number
(decimal/hex) or a string?

Regards,

Stephan

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

* Re: parameter type of  -frandom-seed
  2015-08-25 16:48 parameter type of -frandom-seed Stephan Gatzka
@ 2015-08-25 23:42 ` Martin Sebor
  2015-08-27  5:36   ` Stephan Gatzka
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Sebor @ 2015-08-25 23:42 UTC (permalink / raw)
  To: Stephan Gatzka, gcc-help

On 08/25/2015 10:48 AM, Stephan Gatzka wrote:
> Hi!
>
> I'm a bit confused about the parameter I have to deliver to -frandom
> -seed.
>
> My manual page states it must be a number, others say it's a string.
>
> If I browse through the sources of gcc, it's also not not obvious to me.
>
> https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/common.opt;hb=HEAD
>
> https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/po/de.po;hb=HEAD
>
> So what's the correct parameter ffor -frandom-seed? A number
> (decimal/hex) or a string?

According to the online manual for the latest GCC it's supposed to
be a non-negative number:

   $ gcc -v --help 2>&1 | grep random-seed
   -frandom-seed               This switch lacks documentation
   -frandom-seed=<number>      Make compile reproducible using <number>

but it looks like there's a bug in the option's specification that
prevents invalid (non-numeric) arguments from being diagnosed, making
GCC accept anything (including negative numbers).

The otherwise untested patch below fixes it for me and makes GCC
accept only non-negative numbers.

A bug should probably be filed for this.

Martin

diff --git a/gcc/common.opt b/gcc/common.opt
index 4dcd518..4776d1f 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1868,7 +1868,7 @@ frandom-seed
  Common Var(common_deferred_options) Defer

  frandom-seed=
-Common Joined RejectNegative Var(common_deferred_options) Defer
+Common Joined RejectNegative UInteger Var(common_deferred_options) Defer
  -frandom-seed=<number> Make compile reproducible using <number>

  ; This switch causes the command line that was used to create an

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

* Re: parameter type of  -frandom-seed
  2015-08-25 23:42 ` Martin Sebor
@ 2015-08-27  5:36   ` Stephan Gatzka
  2015-08-27 15:31     ` Martin Sebor
  0 siblings, 1 reply; 7+ messages in thread
From: Stephan Gatzka @ 2015-08-27  5:36 UTC (permalink / raw)
  To: Martin Sebor, gcc-help

Thanks for the answer.

> but it looks like there's a bug in the option's specification that
> prevents invalid (non-numeric) arguments from being diagnosed, making
> GCC accept anything (including negative numbers).
> 

True, it accept strings and negative decimal numbers and hexadecimal
numbers and even gives me identical binaries...

So you would say that the only valid parameter to -frandom-seed is an
unsigned decimal number?

-frandom-seed=18464 // correct
-frandom-seed=a48cb9 //wrong
-frandom-seed=foobar //wrong

Regards,

Stephan

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

* Re: parameter type of  -frandom-seed
  2015-08-27  5:36   ` Stephan Gatzka
@ 2015-08-27 15:31     ` Martin Sebor
  2015-08-27 18:16       ` Stephan Gatzka
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Sebor @ 2015-08-27 15:31 UTC (permalink / raw)
  To: Stephan Gatzka, gcc-help

On 08/26/2015 11:35 PM, Stephan Gatzka wrote:
> Thanks for the answer.
>
>> but it looks like there's a bug in the option's specification that
>> prevents invalid (non-numeric) arguments from being diagnosed, making
>> GCC accept anything (including negative numbers).
>>
>
> True, it accept strings and negative decimal numbers and hexadecimal
> numbers and even gives me identical binaries...
>
> So you would say that the only valid parameter to -frandom-seed is an
> unsigned decimal number?
>
> -frandom-seed=18464 // correct
> -frandom-seed=a48cb9 //wrong
> -frandom-seed=foobar //wrong

That is what I said, yes.

GCC 5 documents a numeric argument. Earlier versions of gcc document
a string argument. This was changed in commit cf3579 without adjusting
the option specification to reject non-numeric or negative arguments.

The option argument is processed in the set_random_seed function in
toplev.c. The function takes a string argument and calls strtoul on
it to obtain the numeric random seed (strtoul is called with the base
argument of zero letting it detect it from the prefix). When strtoul
fails, set_random_seed calls crc32_string with the string argument.
So the function is capable of processing both numeric and string
arguments. I suppose the question is whether GCC should should be
changed back to accept string arguments as originally implemented,
or whether it should stay as is and the option specification changed
to match the documentation. Either way, there are problems here that
should be fixed.

Martin

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

* Re: parameter type of  -frandom-seed
  2015-08-27 15:31     ` Martin Sebor
@ 2015-08-27 18:16       ` Stephan Gatzka
  2015-09-01 17:33         ` Martin Sebor
  0 siblings, 1 reply; 7+ messages in thread
From: Stephan Gatzka @ 2015-08-27 18:16 UTC (permalink / raw)
  To: Martin Sebor, gcc-help


> The option argument is processed in the set_random_seed function in
> toplev.c. The function takes a string argument and calls strtoul on
> it to obtain the numeric random seed (strtoul is called with the base
> argument of zero letting it detect it from the prefix). When strtoul
> fails, set_random_seed calls crc32_string with the string argument.
> So the function is capable of processing both numeric and string
> arguments.

Thanks for diving into the sources.

> I suppose the question is whether GCC should should be
> changed back to accept string arguments as originally implemented,
> or whether it should stay as is and the option specification changed
> to match the documentation.

Well, I would stay with the implementation and allow strings. So
reverting the docs back to string would be fine.

Regards,

Stephan

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

* Re: parameter type of  -frandom-seed
  2015-08-27 18:16       ` Stephan Gatzka
@ 2015-09-01 17:33         ` Martin Sebor
  2015-09-01 18:31           ` Stephan Gatzka
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Sebor @ 2015-09-01 17:33 UTC (permalink / raw)
  To: Stephan Gatzka, gcc-help

On 08/27/2015 12:16 PM, Stephan Gatzka wrote:
>
>> The option argument is processed in the set_random_seed function in
>> toplev.c. The function takes a string argument and calls strtoul on
>> it to obtain the numeric random seed (strtoul is called with the base
>> argument of zero letting it detect it from the prefix). When strtoul
>> fails, set_random_seed calls crc32_string with the string argument.
>> So the function is capable of processing both numeric and string
>> arguments.
>
> Thanks for diving into the sources.
>
>> I suppose the question is whether GCC should should be
>> changed back to accept string arguments as originally implemented,
>> or whether it should stay as is and the option specification changed
>> to match the documentation.
>
> Well, I would stay with the implementation and allow strings. So
> reverting the docs back to string would be fine.

I opened driver/67425 for this and outlined the two solutions we've
discussed.

Martin

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

* Re: parameter type of  -frandom-seed
  2015-09-01 17:33         ` Martin Sebor
@ 2015-09-01 18:31           ` Stephan Gatzka
  0 siblings, 0 replies; 7+ messages in thread
From: Stephan Gatzka @ 2015-09-01 18:31 UTC (permalink / raw)
  To: Martin Sebor, gcc-help


> I opened driver/67425 for this and outlined the two solutions we've
> discussed.

Thanks,

Stephan

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

end of thread, other threads:[~2015-09-01 18:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-25 16:48 parameter type of -frandom-seed Stephan Gatzka
2015-08-25 23:42 ` Martin Sebor
2015-08-27  5:36   ` Stephan Gatzka
2015-08-27 15:31     ` Martin Sebor
2015-08-27 18:16       ` Stephan Gatzka
2015-09-01 17:33         ` Martin Sebor
2015-09-01 18:31           ` Stephan Gatzka

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).