public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108224] New: Suggest stdlib.h header for rand
@ 2022-12-25 22:04 jg at jguk dot org
  2022-12-25 22:09 ` [Bug c/108224] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jg at jguk dot org @ 2022-12-25 22:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

            Bug ID: 108224
           Summary: Suggest stdlib.h header for rand
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jg at jguk dot org
  Target Milestone: ---

Would be great if the suggestions could suggest <stdlib.h> for rand()
Same in C and C++

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

* [Bug c/108224] Suggest stdlib.h header for rand
  2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
@ 2022-12-25 22:09 ` pinskia at gcc dot gnu.org
  2022-12-25 22:11 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-25 22:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

* [Bug c/108224] Suggest stdlib.h header for rand
  2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
  2022-12-25 22:09 ` [Bug c/108224] " pinskia at gcc dot gnu.org
@ 2022-12-25 22:11 ` pinskia at gcc dot gnu.org
  2022-12-25 22:15 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-25 22:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-12-25
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Simple testcase:
int f(void)
{
  return rand();
}

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

* [Bug c/108224] Suggest stdlib.h header for rand
  2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
  2022-12-25 22:09 ` [Bug c/108224] " pinskia at gcc dot gnu.org
  2022-12-25 22:11 ` pinskia at gcc dot gnu.org
@ 2022-12-25 22:15 ` pinskia at gcc dot gnu.org
  2022-12-25 22:40 ` jg at jguk dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-25 22:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 9c256173b82..dd4c23e5923 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -171,6 +171,8 @@ get_stdlib_header_for_name (const char *name, enum stdlib
lib)
     {"getenv", {"<stdlib.h>", "<cstdlib>"} },
     {"malloc", {"<stdlib.h>", "<cstdlib>"} },
     {"realloc", {"<stdlib.h>", "<cstdlib>"} },
+    {"rand", {"<stdlib.h>", "<cstdlib>"} },
+    {"srand", {"<stdlib.h>", "<cstdlib>"} },

     /* <string.h> and <cstring>.  */
     {"memchr", {"<string.h>", "<cstring>"} },


Should be enough for both C and C++.

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

* [Bug c/108224] Suggest stdlib.h header for rand
  2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
                   ` (2 preceding siblings ...)
  2022-12-25 22:15 ` pinskia at gcc dot gnu.org
@ 2022-12-25 22:40 ` jg at jguk dot org
  2022-12-26  6:54 ` sam at gentoo dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jg at jguk dot org @ 2022-12-25 22:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

--- Comment #3 from Jonny Grant <jg at jguk dot org> ---
Great! I just saw it is the same for random(), srandom(), initstate(),
setstate()

Is there an easy way to add them all based on the C API to save opening
separate tickets?

I added those :

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>"} },
-- 
2.37.2

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

* [Bug c/108224] Suggest stdlib.h header for rand
  2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
                   ` (3 preceding siblings ...)
  2022-12-25 22:40 ` jg at jguk dot org
@ 2022-12-26  6:54 ` sam at gentoo dot org
  2022-12-26  8:59 ` jg at jguk dot org
  2023-12-01  8:44 ` sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: sam at gentoo dot org @ 2022-12-26  6:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

--- Comment #4 from Sam James <sam at gentoo dot org> ---
(In reply to Jonny Grant from comment #3)
> Great! I just saw it is the same for random(), srandom(), initstate(),
> setstate()
> 
> Is there an easy way to add them all based on the C API to save opening
> separate tickets?
> 
> I added those :

Could you send the patch to gcc-patches (the mailing list)? Thanks.

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

* [Bug c/108224] Suggest stdlib.h header for rand
  2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
                   ` (4 preceding siblings ...)
  2022-12-26  6:54 ` sam at gentoo dot org
@ 2022-12-26  8:59 ` jg at jguk dot org
  2023-12-01  8:44 ` sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jg at jguk dot org @ 2022-12-26  8:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

--- Comment #5 from Jonny Grant <jg at jguk dot org> ---
(In reply to Sam James from comment #4)
> (In reply to Jonny Grant from comment #3)
> > Great! I just saw it is the same for random(), srandom(), initstate(),
> > setstate()
> > 
> > Is there an easy way to add them all based on the C API to save opening
> > separate tickets?
> > 
> > I added those :
> 
> Could you send the patch to gcc-patches (the mailing list)? Thanks.

Sure, just sent :-)

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

* [Bug c/108224] Suggest stdlib.h header for rand
  2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
                   ` (5 preceding siblings ...)
  2022-12-26  8:59 ` jg at jguk dot org
@ 2023-12-01  8:44 ` sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-12-01  8:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108224

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmalcolm at gcc dot gnu.org

--- Comment #6 from Sam James <sjames at gcc dot gnu.org> ---
https://inbox.sourceware.org/gcc-patches/881e795d-34c8-0445-74cf-cb68192d2dfe@jguk.org/

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

end of thread, other threads:[~2023-12-01  8:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-25 22:04 [Bug c/108224] New: Suggest stdlib.h header for rand jg at jguk dot org
2022-12-25 22:09 ` [Bug c/108224] " pinskia at gcc dot gnu.org
2022-12-25 22:11 ` pinskia at gcc dot gnu.org
2022-12-25 22:15 ` pinskia at gcc dot gnu.org
2022-12-25 22:40 ` jg at jguk dot org
2022-12-26  6:54 ` sam at gentoo dot org
2022-12-26  8:59 ` jg at jguk dot org
2023-12-01  8:44 ` sjames at gcc dot gnu.org

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