<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_ASSIGNED "
   title="ASSIGNED --- - @llvm.objectsize treats allocsize differently than allocas."
   href="https://llvm.org/bugs/show_bug.cgi?id=28834">28834</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>@llvm.objectsize treats allocsize differently than allocas.
          </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>ASSIGNED
          </td>
        </tr>

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

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

        <tr>
          <th>Component</th>
          <td>Global Analyses
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>george.burgess.iv@gmail.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>george.burgess.iv@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For the purposes of evaluating `@llvm.objectsize(%p)`, we're meant to treat `%p
= call i8* @foo(i32 5)` the same as `%p = alloca i8, i32 5` (assuming @foo has
the allocsize attribute).

This seems not to be the case. Given:
```
void bos(char *a, char *b) {
  g0 = __builtin_object_size(a, 0);
  g1 = __builtin_object_size(b, 1);
}

void bos1() {
  char cs[5], cz[8];
  bos(cs, cz);
}
```

We generate (with clang trunk, -O2):

```
define void @bos1() {
entry:
  store i32 5, i32* @g0, align 4
  store i32 8, i32* @g1, align 4
  ret void
}
```

Which is good. Given its allocsize equivalent:

```
// N.B. alloc_size DNE in clang yet.
void *malloc2(int n) __attribute((alloc_size(1)));

void allocsize(int a, int b) {
  void *p = malloc2(a);
  g0 = __builtin_object_size(p, 0);
  void *v = malloc2(b);
  g1 = __builtin_object_size(v, 1);
}

void allocsize1() {
  allocsize(5, 8);
}
```

We get:

```
define void @allocsize1() {
entry:
  store i32 -1, i32* @g0, align 4
  store i32 -1, i32* @g1, align 4
  ret void
}
```

...Those -1s should be 5 and 8.</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>