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

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