[LLVMbugs] [Bug 19881] New: __attribute__((aligned(4))) must be placed in a typedef for it to work.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed May 28 13:59:54 PDT 2014


            Bug ID: 19881
           Summary: __attribute__((aligned(4))) must be placed in a
                    typedef for it to work.
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jujjyl at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

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?

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/20140528/7cb7fd7a/attachment.html>

More information about the llvm-bugs mailing list