[llvm-bugs] [Bug 30550] LLVM's Global Value Numbering pass bug

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Dec 31 03:26:25 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=30550

Daniel Berlin <dberlin at dberlin.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Daniel Berlin <dberlin at dberlin.org> ---
First, note:
/Users/dannyb/Downloads/test (1).cpp:38:23: warning: when type is in
parentheses, array cannot have dynamic
      size
                p1 = new (20) (char[i]);
                              ~     ^ ~
/Users/dannyb/Downloads/test (1).cpp:39:23: warning: when type is in
parentheses, array cannot have dynamic
      size
                p2 = new (20) (char[i]);
                              ~     ^ ~
2 warnings generated.

Clang's warning is correct here:
"With the parentheses, the type to be newed comes from a type-id, in this case
char[i]. This is a variable length array which is not standard behavior.
Without the parentheses, the type to be newed is a new-type-id, an array of X."

g++ will give you the same warning:
/Users/dannyb/Downloads/test (1).cpp: In function 'int tst()':
/Users/dannyb/Downloads/test (1).cpp:38:25: warning: non-constant array new
length must be specified without parentheses around the type-id [-Wvla]
   p1 = new (20) (char[i]);
                         ^
/Users/dannyb/Downloads/test (1).cpp:39:25: warning: non-constant array new
length must be specified without parentheses around the type-id [-Wvla]
   p2 = new (20) (char[i]);
                         ^

Second, these functions overwrite the heap (and thus, i'm not sure why you
believe they have to return 0).


Both g++ and clang with -fsanitize=address will show you this.

This is because you have:
        int i = 0;
        p1 = new (20) char[i];


Regardless of what your allocation function does, you've told it you've got a
dynamic array of size 0 :)

If you change the code to 
         p1 = new (20) char[20];
         p2 = new (20) char[20];
or
int i = 20
         p1 = new (20) char[i];
         p2 = new (20) char[i];

It will succeed in all cases.

Marking as invalid for now.

-- 
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/20161231/18ee9b33/attachment-0001.html>


More information about the llvm-bugs mailing list