<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:dberlin@dberlin.org" title="Daniel Berlin <dberlin@dberlin.org>"> <span class="fn">Daniel Berlin</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - LLVM's Global Value Numbering pass bug"
   href="https://llvm.org/bugs/show_bug.cgi?id=30550">bug 30550</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - LLVM's Global Value Numbering pass bug"
   href="https://llvm.org/bugs/show_bug.cgi?id=30550#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - LLVM's Global Value Numbering pass bug"
   href="https://llvm.org/bugs/show_bug.cgi?id=30550">bug 30550</a>
              from <span class="vcard"><a class="email" href="mailto:dberlin@dberlin.org" title="Daniel Berlin <dberlin@dberlin.org>"> <span class="fn">Daniel Berlin</span></a>
</span></b>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>