public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95485] New: missing warning writing into function text
@ 2020-06-02 20:14 msebor at gcc dot gnu.org
  2020-06-02 20:15 ` [Bug middle-end/95485] " msebor at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-02 20:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95485
           Summary: missing warning writing into function text
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC doesn't diagnose attempts to write into functions, even though those will
in all likelihood crash with a SIGBUS at runtime.

For example, in the following snippet the destination of the memset call is a
function rather than the memory it was called to obtain.  The memset call
should be diagnosed.

$ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout z.c
typedef void* F (int);

void* f (F *p)
{
  void *q = p (32);              // allocate memory
  __builtin_memset (p, 0, 32);   // zero out -- whoops! -- writing to a
function
  return q;                      // return "clear" memory
}

;; Function f (f, funcdef_no=0, decl_uid=1933, cgraph_uid=1, symbol_order=0)

f (void * (*<T322>) (int) p)
{
  void * q;

  <bb 2> [local count: 1073741824]:
  q_4 = p_2(D) (32);
  __builtin_memset (p_2(D), 0, 32);
  return q_4;

}


Two compilers on Godbolt diagnose the code: Visual C++:

z.c(8): warning C4152: nonstandard extension, function/data pointer conversion
in expression

and the Small Device C Compiler (SDCC):

x.c:8: warning 244: pointer types incompatible 
from type 'void generic* function ( int fixed) code* fixed'
  to type 'void generic* fixed'

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

* [Bug middle-end/95485] missing warning writing into function text
  2020-06-02 20:14 [Bug middle-end/95485] New: missing warning writing into function text msebor at gcc dot gnu.org
@ 2020-06-02 20:15 ` msebor at gcc dot gnu.org
  2020-06-02 20:21 ` msebor at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-02 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

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

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

* [Bug middle-end/95485] missing warning writing into function text
  2020-06-02 20:14 [Bug middle-end/95485] New: missing warning writing into function text msebor at gcc dot gnu.org
  2020-06-02 20:15 ` [Bug middle-end/95485] " msebor at gcc dot gnu.org
@ 2020-06-02 20:21 ` msebor at gcc dot gnu.org
  2020-06-03  5:05 ` egallager at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-02 20:21 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-06-02
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=90404
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
See also pr90404.  I'm working on a solution for that, and I expect it to
handle this as well.

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

* [Bug middle-end/95485] missing warning writing into function text
  2020-06-02 20:14 [Bug middle-end/95485] New: missing warning writing into function text msebor at gcc dot gnu.org
  2020-06-02 20:15 ` [Bug middle-end/95485] " msebor at gcc dot gnu.org
  2020-06-02 20:21 ` msebor at gcc dot gnu.org
@ 2020-06-03  5:05 ` egallager at gcc dot gnu.org
  2020-06-03 16:23 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: egallager at gcc dot gnu.org @ 2020-06-03  5:05 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

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

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
-Wpedantic catches it:

$ /usr/local/bin/gcc -c -O2 -S -Wall -Wextra -pedantic
-fdump-tree-optimized=/dev/stdout 95485.c
95485.c: In function 'f':
95485.c:6:20: warning: ISO C forbids passing argument 1 of '__builtin_memset'
between function pointer and 'void *' [-Wpedantic]
    6 |  __builtin_memset (p, 0, 32);   // zero out -- whoops! -- writing to a
function
      |                    ^
95485.c:6:20: note: expected 'void *' but argument is of type 'void * (*)(int)'

;; Function f (f, funcdef_no=0, decl_uid=1910, cgraph_uid=1, symbol_order=0)

f (void * (*<T318>) (int) p)
{
  void * q;

  <bb 2> [local count: 1073741824]:
  q_4 = p_2(D) (32);
  __builtin_memset (p_2(D), 0, 32);
  return q_4;

}


$

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

* [Bug middle-end/95485] missing warning writing into function text
  2020-06-02 20:14 [Bug middle-end/95485] New: missing warning writing into function text msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-06-03  5:05 ` egallager at gcc dot gnu.org
@ 2020-06-03 16:23 ` msebor at gcc dot gnu.org
  2022-01-04  6:51 ` egallager at gcc dot gnu.org
  2022-01-26 17:55 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-03 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Ah, yes, -Wpedantic does detect the invalid conversion.  But few projects use
-Wpedantic (GCC itself doesn't) and enabling the warning in -Wall or -Wextra
would likely lead to lots of noise for code that converts between object and
function pointers (POSIX requires it to work).

A warning implemented in a front end can also only detect questionable
conversions but not the actual writes, which is what the warning I'm working on
does (i.e., detect stores into read-only storage).

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

* [Bug middle-end/95485] missing warning writing into function text
  2020-06-02 20:14 [Bug middle-end/95485] New: missing warning writing into function text msebor at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-06-03 16:23 ` msebor at gcc dot gnu.org
@ 2022-01-04  6:51 ` egallager at gcc dot gnu.org
  2022-01-26 17:55 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: egallager at gcc dot gnu.org @ 2022-01-04  6:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #3)
> Ah, yes, -Wpedantic does detect the invalid conversion.  But few projects
> use -Wpedantic (GCC itself doesn't) and enabling the warning in -Wall or
> -Wextra would likely lead to lots of noise for code that converts between
> object and function pointers (POSIX requires it to work).
> 
> A warning implemented in a front end can also only detect questionable
> conversions but not the actual writes, which is what the warning I'm working
> on does (i.e., detect stores into read-only storage).

so... you're suggesting a new flag, then?

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

* [Bug middle-end/95485] missing warning writing into function text
  2020-06-02 20:14 [Bug middle-end/95485] New: missing warning writing into function text msebor at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-01-04  6:51 ` egallager at gcc dot gnu.org
@ 2022-01-26 17:55 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-26 17:55 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|msebor at gcc dot gnu.org          |unassigned at gcc dot gnu.org
             Status|ASSIGNED                    |NEW
             Blocks|                            |87403

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm not working on this anymore.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

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

end of thread, other threads:[~2022-01-26 17:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 20:14 [Bug middle-end/95485] New: missing warning writing into function text msebor at gcc dot gnu.org
2020-06-02 20:15 ` [Bug middle-end/95485] " msebor at gcc dot gnu.org
2020-06-02 20:21 ` msebor at gcc dot gnu.org
2020-06-03  5:05 ` egallager at gcc dot gnu.org
2020-06-03 16:23 ` msebor at gcc dot gnu.org
2022-01-04  6:51 ` egallager at gcc dot gnu.org
2022-01-26 17:55 ` msebor 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).