[llvm-bugs] [Bug 28410] New: Optimized code contains illegal movaps instruction when using aligned attribute in typedef

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 4 06:41:42 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28410

            Bug ID: 28410
           Summary: Optimized code contains illegal movaps instruction
                    when using aligned attribute in typedef
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lukasz.czyz at intel.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

clang generates MOVAPS instruction with wrongly aligned operand (resulting in
SEGFAULT) when compiling following code with optimizations enabled (-O2):


#include <stdint.h>

struct Foo
{
    uint32_t data[ 13 ];
};

typedef  __attribute__((aligned(16))) Foo FooDef;


int counter;

struct Bar
{
        FooDef array[4];
};

__attribute__ ((noinline)) void do_sth(FooDef* foo)
{
        counter += ((char*)foo)[0];
}


int main()
{
        Bar* bar = new Bar();

        FooDef tmp = {{0}};

        for (int i = 0; i < 4; i++)
        {
                FooDef *foo = &bar->array[i];
                *foo = tmp;
                do_sth(foo);
        }

        return 0;
}


Explanation: aligned(16) attribute is ignored when determining sizeof(FooDef)
(so sizeof(FooDef) == 52, not 64). At the other hand optimizer assumes that the
given alignment holds for all elements of bar->array which is not true due to
sizeof(FooDef) not aligned to 16 bytes.

-- 
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/20160704/6bca6143/attachment.html>


More information about the llvm-bugs mailing list