[llvm-bugs] [Bug 44641] New: GPF when passing a non-aligned struct to a __declspec(align) typedef

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 23 13:18:55 PST 2020


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

            Bug ID: 44641
           Summary: GPF when passing a non-aligned struct to a
                    __declspec(align) typedef
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: alexandre.ganea at ubisoft.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk, rnk at google.com

Clang does not complain when a non-aligned instance is assigned to aligned
typedef'd type (repro below).
I think at least a warning would be nice (if not, an error).

MSVC and GCC handle this by doing a unaligned load.

https://godbolt.org/z/62HzmJ

--------------------------------
// a.h
struct Vector4 { float v[4]; };
typedef __declspec(align(16)) Vector4  AlignVector4;

struct A {
  AlignVector4 vec;
  void SetVec(const AlignVector4& v) { vec = v; }
};
struct B {
  bool b;
  Vector4 vec;
};
--------------------------------
// a.cpp
#include "a.h"
int f(A& a, const B& b) {
  a.SetVec(b.vec);
  return (int)a.vec.v[0];
}
--------------------------------
// main.cpp
#include "a.h"
int f(A& a, const B& b);
int main() {
  A a; B b;
  return f(a, b);
}

--------------------------------
// Build:
// clang-cl a.cpp /O2 /c /MT
// clang-cl main.cpp /c /MT
// lld-link a.obj main.obj /entry:main /subsystem:console

-- 
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/20200123/7964d75e/attachment.html>


More information about the llvm-bugs mailing list