<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - InstCombine: objectsize of alloca optimized to undef returns unknown"
   href="https://llvm.org/bugs/show_bug.cgi?id=23301">23301</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InstCombine: objectsize of alloca optimized to undef returns unknown
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ahmed.bougacha@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Reported by Daniel Micay in PR23280:

  #include <stdio.h>
  #include <stdlib.h>

  static inline __attribute__((always_inline)) size_t object_size(char *p) {
    return __builtin_object_size(p, 0);
  }

  int main(int argc, char **argv) {
    char buf[2];
    printf("%zu\n", object_size(buf));
    return 0;
  }


This returns -1 because buf is optimized to undef by InstCombine.

When InstCombine tries to erase an alloca, the isAllocSiteRemovable logic is
smarter than the RAUW-undef logic: when there's a (objectsize (GEP/bitcast
(alloca))), we should look through the alloca users to properly lower the
objectsize calls.  We currently just do something like alloca->RAUW(undef).

Perhaps the RAUW-undef logic and isAllocSiteRemovable should match?  This would
let the above example print 2 instead of the current -1.</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>