[llvm-dev] Static assert fails when compiler for i386

Rui Ueyama via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 16 21:55:10 PDT 2019


max_align_t is a type whose alignment requirement is as large as any
*scalar* type, but your int4 is not a scalar type but a union containing a
vector _int4, so it looks like your assertion is simply incorrect.

On Thu, Oct 17, 2019 at 12:58 PM kamlesh kumar via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi Devs,
> Consider below testcase.
> $cat test.cpp
> #include <vector>
> #include<type_traits>
> typedef int _int4 __attribute__((vector_size(16)));
> typedef union{
> int data[4];
> struct {int x, y, z, w;};
> _int4 vec;
> } int4;
> typedef int4 int3;
> int main()
> {
> static_assert(std::alignment_of<int4>::value <= alignof(max_align_t), "over
> aligned!");
> }
>
> $clang++ -m32
> error: static_assert failed due to requirement
> 'std::alignment_of<int4>::value <= alignof(max_align_t)' "over aligned
> it goes smooth when compile for x86_64.
> Following changes fixes this.
>
> diff --git a/clang/lib/Headers/__stddef_max_align_t.h
> b/clang/lib/Headers/__stddef_max_align_t.h
> index e3b439285d0..46f705a09c3 100644
> --- a/clang/lib/Headers/__stddef_max_align_t.h
> +++ b/clang/lib/Headers/__stddef_max_align_t.h
> @@ -21,6 +21,10 @@ typedef struct {
>        __attribute__((__aligned__(__alignof__(long long))));
>    long double __clang_max_align_nonce2
>        __attribute__((__aligned__(__alignof__(long double))));
> +  #ifdef __i386__
> +  typedef double xx __attribute__((vector_size(16)));
> +  xx __clang_max_align_nonce3
>  __attribute__((__aligned__(__alignof__(xx))));
> +  #endif
>  } max_align_t;
>  #endif
>
> Like to know community thought on this?
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191017/98303f18/attachment.html>


More information about the llvm-dev mailing list