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: unassignedclangb...@nondot.org
          Reporter: alexandre.ga...@ubisoft.com
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@metafoo.co.uk, r...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to