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'

Reply via email to