This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/83537] New: missing integer overflow in offsetof not diagnosed


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

            Bug ID: 83537
           Summary: missing integer overflow in offsetof not diagnosed
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

An offsetof(type, member) expression is supposed to evaluate to an integer
constant with type size_t and a value giving the offset in bytes, to the
structure member.  This is only possible for offsets that fit into size_t. 
Since larger offsets are not representable in size_t such offsetof expressions
cannot satisfy the requirement.  To help detect bugs GCC should diagnose the
overflow (perhaps with -Woverflow).

$ cat z.c && gcc -O -S -Wall -fdump-tree-optimized=/dev/stdout z.c
#include <stddef.h>
#include <stdint.h>

struct S { int i, a[]; };

size_t f (void)
{
  return offsetof (struct S, a[PTRDIFF_MAX]);
}


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

f ()
{
  <bb 2> [local count: 1073741825]:
  return 0;

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]