Skip to content

On Windows clang produce bad binary for global 4-element double array and __builtin_shufflevector #23902

@llvmbot

Description

@llvmbot
Bugzilla Link 23528
Version trunk
OS Windows NT
Attachments Visual Studio 2013 access violation with dissam window screenshot;
Reporter LLVM Bugzilla Contributor

Extended Description

Latest clang 3.7 for Windows (LLVM-3.7.0-r237002-win32) produce bad binary for program:

#include <stdio.h>
#define N 4
typedef double VecTy __attribute__((__vector_size__( sizeof(double) * N)));
double L[] = { 2.5, -0.1, 0.9, 5.1 };

int main(void) {
  VecTy *L_vec = (VecTy*)L;
  VecTy res = __builtin_shufflevector(*L_vec, *L_vec, 1, 2, 3, 0);

  for (int i = 0; i < sizeof(res)/sizeof(res[0]); i++) {
    printf("%f ", res[i]);
  }
}

Build: clang -g VecShuffle.cpp

Actual result, Windows 7 64bit (under Visual Studio):
See attached vs_access_violation.png

Actual result, Windows 7 64bit (under gdb):

>gdb a.exe
(gdb) run
Starting program: C:\workfolder\clang_tests\a.exe
[New Thread 10552.0x323c]
Program received signal SIGSEGV, Segmentation fault.


Expected result: the same on linux(redhat) -
 ./a.out
-0.100000 0.900000 5.100000 2.500000

Note: If you move L[] inside main block, the result on windows will be correct:

C:\workfolder\clang_tests>a.exe
-0.100000 0.900000 5.100000 2.500000

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions