[llvm-bugs] [Bug 27439] New: No warning for integer overflow in array size

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 20 09:03:25 PDT 2016


            Bug ID: 27439
           Summary: No warning for integer overflow in array size
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: cherepan at mccme.ru
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

While compiling this program:

#include <limits.h>

int main()
  char a[INT_MAX * 3];
  (void)(INT_MAX * 3);

clang 3.9.0 (trunk 266734) gives the following warnings:

$ clang example.c
example.c:6:18: warning: overflow in expression; result is 2147483645 with type
'int' [-Winteger-overflow]
  (void)(INT_MAX * 3);
1 warning generated.

There is no warning for the integer overflow in the declaration of the array.
UBSAN doesn't help.

For comparison:

$ gcc example.c
example.c: In function ‘main’:
example.c:5:18: warning: integer overflow in expression [-Woverflow]
   char a[INT_MAX * 3];
example.c:6:18: warning: integer overflow in expression [-Woverflow]
   (void)(INT_MAX * 3);

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160420/114b66a1/attachment.html>

More information about the llvm-bugs mailing list