[Bug,c/108224] add srandom random initstate setstate

Message ID 881e795d-34c8-0445-74cf-cb68192d2dfe@jguk.org
State New
Headers
Series [Bug,c/108224] add srandom random initstate setstate |

Commit Message

Jonny Grant Dec. 26, 2022, 8:55 a.m. UTC
  From 6ff344979af46dbcd739dd9068d6d595547e4c27 Mon Sep 17 00:00:00 2001
From: Jonathan Grant <jg@jguk.org>
Date: Sun, 25 Dec 2022 22:38:44 +0000
Subject: [PATCH] add srandom random initstate setstate

---
 gcc/c-family/known-headers.cc | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Prathamesh Kulkarni Dec. 26, 2022, 9:19 a.m. UTC | #1
On Mon, 26 Dec 2022 at 14:25, Jonny Grant <jg@jguk.org> wrote:
>
>
>
> From 6ff344979af46dbcd739dd9068d6d595547e4c27 Mon Sep 17 00:00:00 2001
> From: Jonathan Grant <jg@jguk.org>
> Date: Sun, 25 Dec 2022 22:38:44 +0000
> Subject: [PATCH] add srandom random initstate setstate
>
> ---
>  gcc/c-family/known-headers.cc | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
> index 9c256173b82..ade9fa2dcc0 100644
> --- a/gcc/c-family/known-headers.cc
> +++ b/gcc/c-family/known-headers.cc
> @@ -171,6 +171,10 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
>      {"getenv", {"<stdlib.h>", "<cstdlib>"} },
>      {"malloc", {"<stdlib.h>", "<cstdlib>"} },
>      {"realloc", {"<stdlib.h>", "<cstdlib>"} },
> +    {"random", {"<stdlib.h>", "<cstdlib>"} },
> +    {"srandom", {"<stdlib.h>", "<cstdlib>"} },
> +    {"initstate", {"<stdlib.h>", "<cstdlib>"} },
> +    {"setstate", {"<stdlib.h>", "<cstdlib>"} },
>
>      /* <string.h> and <cstring>.  */
>      {"memchr", {"<string.h>", "<cstring>"} },
Hi Jonny,
Thanks for the patch. A couple of things:
(a) Could you please add a test-case for the above symbols ? See
testsuite/gcc.dg/missing-header-fixit-4.c
for a similar example for printf.
(b) The patch is missing changelog.
I assume you've tested the patch with bootstrap+regtest ?

Thanks,
Prathamesh

> --
> 2.37.2
  
Jonny Grant Dec. 27, 2022, 10:31 p.m. UTC | #2
On 26/12/2022 09:19, Prathamesh Kulkarni wrote:
> On Mon, 26 Dec 2022 at 14:25, Jonny Grant <jg@jguk.org> wrote:
>>
>>
>>
>> From 6ff344979af46dbcd739dd9068d6d595547e4c27 Mon Sep 17 00:00:00 2001
>> From: Jonathan Grant <jg@jguk.org>
>> Date: Sun, 25 Dec 2022 22:38:44 +0000
>> Subject: [PATCH] add srandom random initstate setstate
>>
>> ---
>>  gcc/c-family/known-headers.cc | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
>> index 9c256173b82..ade9fa2dcc0 100644
>> --- a/gcc/c-family/known-headers.cc
>> +++ b/gcc/c-family/known-headers.cc
>> @@ -171,6 +171,10 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
>>      {"getenv", {"<stdlib.h>", "<cstdlib>"} },
>>      {"malloc", {"<stdlib.h>", "<cstdlib>"} },
>>      {"realloc", {"<stdlib.h>", "<cstdlib>"} },
>> +    {"random", {"<stdlib.h>", "<cstdlib>"} },
>> +    {"srandom", {"<stdlib.h>", "<cstdlib>"} },
>> +    {"initstate", {"<stdlib.h>", "<cstdlib>"} },
>> +    {"setstate", {"<stdlib.h>", "<cstdlib>"} },
>>
>>      /* <string.h> and <cstring>.  */
>>      {"memchr", {"<string.h>", "<cstring>"} },
> Hi Jonny,
> Thanks for the patch. A couple of things:
> (a) Could you please add a test-case for the above symbols ? See
> testsuite/gcc.dg/missing-header-fixit-4.c
> for a similar example for printf.
> (b) The patch is missing changelog.
> I assume you've tested the patch with bootstrap+regtest ?

Hi Prathmesh
Many thanks for your reply.

I built gcc by typing "make", I understand that is the bootstrap. I don't know about regtest, could you direct me to a guide please.

I didn't add a test; I can do that now. Is there an FAQ you can direct me to to run those tests please.

Running ‘make check-c’ now, its taking along time on gcc.c-torture.
Is there a way I can quickly run only the gcc.dg missing header tests?

BTW, do you know if a change could be made to detect dejagnu being installed?

Would be good if "make check" quickly failed if the "runtest" command from dejagnu was not found.

I needed to install these two packages. Would be good to get a hint when running ‘make check-c’
autogen dejagnu


For the files like missing-header-fixit-4.c is it sufficient to just add a file to that folder?
Cheers
Jonny
  
Prathamesh Kulkarni Jan. 1, 2023, 7:42 a.m. UTC | #3
On Wed, 28 Dec 2022 at 04:01, Jonny Grant <jg@jguk.org> wrote:
>
>
>
> On 26/12/2022 09:19, Prathamesh Kulkarni wrote:
> > On Mon, 26 Dec 2022 at 14:25, Jonny Grant <jg@jguk.org> wrote:
> >>
> >>
> >>
> >> From 6ff344979af46dbcd739dd9068d6d595547e4c27 Mon Sep 17 00:00:00 2001
> >> From: Jonathan Grant <jg@jguk.org>
> >> Date: Sun, 25 Dec 2022 22:38:44 +0000
> >> Subject: [PATCH] add srandom random initstate setstate
> >>
> >> ---
> >>  gcc/c-family/known-headers.cc | 4 ++++
> >>  1 file changed, 4 insertions(+)
> >>
> >> diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
> >> index 9c256173b82..ade9fa2dcc0 100644
> >> --- a/gcc/c-family/known-headers.cc
> >> +++ b/gcc/c-family/known-headers.cc
> >> @@ -171,6 +171,10 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
> >>      {"getenv", {"<stdlib.h>", "<cstdlib>"} },
> >>      {"malloc", {"<stdlib.h>", "<cstdlib>"} },
> >>      {"realloc", {"<stdlib.h>", "<cstdlib>"} },
> >> +    {"random", {"<stdlib.h>", "<cstdlib>"} },
> >> +    {"srandom", {"<stdlib.h>", "<cstdlib>"} },
> >> +    {"initstate", {"<stdlib.h>", "<cstdlib>"} },
> >> +    {"setstate", {"<stdlib.h>", "<cstdlib>"} },
> >>
> >>      /* <string.h> and <cstring>.  */
> >>      {"memchr", {"<string.h>", "<cstring>"} },
> > Hi Jonny,
> > Thanks for the patch. A couple of things:
> > (a) Could you please add a test-case for the above symbols ? See
> > testsuite/gcc.dg/missing-header-fixit-4.c
> > for a similar example for printf.
> > (b) The patch is missing changelog.
> > I assume you've tested the patch with bootstrap+regtest ?
>
> Hi Prathmesh
> Many thanks for your reply.
>
> I built gcc by typing "make", I understand that is the bootstrap. I don't know about regtest, could you direct me to a guide please.
Hi,
Sorry for slow response. It depends on how you configured gcc. If
bootstrap is enabled (which is by default), then make would bootstrap
gcc.
Typically for development, we disable bootstrap by passing
--disable-bootstrap to configure for faster builds,
and then validate the patch with final bootstrap+test.
For regression testing, you'd have to
(1) Bootstrap the trunk without the patch,
(2) Bootstrap the trunk with patch,
(3) Compare the two build dirs with $gcc-src/contrib/compare_tests.
and address issues for the FAIL'd tests.
>
> I didn't add a test; I can do that now. Is there an FAQ you can direct me to to run those tests please.
>
> Running ‘make check-c’ now, its taking along time on gcc.c-torture.
> Is there a way I can quickly run only the gcc.dg missing header tests?
>
> BTW, do you know if a change could be made to detect dejagnu being installed?
>
> Would be good if "make check" quickly failed if the "runtest" command from dejagnu was not found.
>
> I needed to install these two packages. Would be good to get a hint when running ‘make check-c’
> autogen dejagnu
>
>
> For the files like missing-header-fixit-4.c is it sufficient to just add a file to that folder?
Yes, adding the file in $gcc-src/gcc/testsuite/gcc.dg/ should be sufficient.
For eg, to only run missing-header-fixit-4.c this should work:
make check-gcc RUNTESTFLAGS="dg.exp=missing-header-fixit-4.c"

Thanks,
Prathamesh
> Cheers
> Jonny
  

Patch

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 9c256173b82..ade9fa2dcc0 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -171,6 +171,10 @@  get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"getenv", {"<stdlib.h>", "<cstdlib>"} },
     {"malloc", {"<stdlib.h>", "<cstdlib>"} },
     {"realloc", {"<stdlib.h>", "<cstdlib>"} },
+    {"random", {"<stdlib.h>", "<cstdlib>"} },
+    {"srandom", {"<stdlib.h>", "<cstdlib>"} },
+    {"initstate", {"<stdlib.h>", "<cstdlib>"} },
+    {"setstate", {"<stdlib.h>", "<cstdlib>"} },
 
     /* <string.h> and <cstring>.  */
     {"memchr", {"<string.h>", "<cstring>"} },