<html>
    <head>
      <base href="http://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 --- - __attribute__((aligned(4))) must be placed in a typedef for it to work."
   href="http://llvm.org/bugs/show_bug.cgi?id=19881">19881</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__attribute__((aligned(4))) must be placed in a typedef for it to work.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jujjyl@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following code:

#include <cstdint>
#include <stdio.h>

char data[256];

__attribute__((noinline)) double *getd()
{
        char *ptr = (char*)(((uintptr_t)data + 7) & ~7); // Make 8-byte aligned
        ptr += 4; // Now 4-byte aligned
        double *d = (double*)ptr;
        return d;
}

typedef double __attribute__((aligned(4))) double4;

int main()
{
        double4 *d = getd();    // (*)
//      double __attribute__((aligned(4))) *d = getd();
        *d = 1.0;
        printf("addr: %p, value: %f\n", d, *d);
}

in the resulting bitcode, the data pointed to by the variable d is properly
tracked as being aligned to 4 bytes (instead of being aligned to default 8
bytes). 

If you instead replace the starred line (*) with the commented out line, i.e.
expand the typedef manually, then the attribute no longer works and it gets
ignored in the generated bitcode, and the alignment says 8 bytes.

It looks odd that the attribute must be used in a typedef in order to make it
work, is that a bug?</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>