Commit ec40542c44

Andrew Kelley <superjoe30@gmail.com>
2017-10-02 15:55:18
windows: alignstack=16 on every function
See #302
1 parent 0a4283b
Changed files (3)
ci/travis_linux_script
@@ -21,3 +21,12 @@ wine test.exe
 
 ./zig test ../test/behavior.zig --target-os windows --target-arch i386 --target-environ msvc --release-safe
 wine test.exe
+
+./zig test ../test/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc
+wine64 test.exe
+
+./zig test ../test/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc --release-fast
+wine64 test.exe
+
+./zig test ../test/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc --release-safe
+wine64 test.exe
src/codegen.cpp
@@ -290,6 +290,15 @@ static void addLLVMAttrStr(LLVMValueRef val, LLVMAttributeIndex attr_index,
     LLVMAddAttributeAtIndex(val, attr_index, llvm_attr);
 }
 
+static void addLLVMAttrInt(LLVMValueRef val, LLVMAttributeIndex attr_index,
+        const char *attr_name, uint64_t attr_val)
+{
+    unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, strlen(attr_name));
+    assert(kind_id != 0);
+    LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(LLVMGetGlobalContext(), kind_id, attr_val);
+    LLVMAddAttributeAtIndex(val, attr_index, llvm_attr);
+}
+
 static void addLLVMFnAttr(LLVMValueRef fn_val, const char *attr_name) {
     return addLLVMAttr(fn_val, -1, attr_name);
 }
@@ -298,6 +307,10 @@ static void addLLVMFnAttrStr(LLVMValueRef fn_val, const char *attr_name, const c
     return addLLVMAttrStr(fn_val, -1, attr_name, attr_val);
 }
 
+static void addLLVMFnAttrInt(LLVMValueRef fn_val, const char *attr_name, uint64_t attr_val) {
+    return addLLVMAttrInt(fn_val, -1, attr_name, attr_val);
+}
+
 static void addLLVMArgAttr(LLVMValueRef arg_val, unsigned param_index, const char *attr_name) {
     return addLLVMAttr(arg_val, param_index + 1, attr_name);
 }
@@ -439,6 +452,12 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
         }
     }
 
+    if (g->zig_target.os == ZigLLVM_Win32 && g->zig_target.arch.arch == ZigLLVM_x86_64 &&
+        fn_type->data.fn.fn_type_id.cc != CallingConventionNaked)
+    {
+        addLLVMFnAttrInt(fn_table_entry->llvm_value, "alignstack", 16);
+    }
+
     addLLVMFnAttr(fn_table_entry->llvm_value, "nounwind");
     addLLVMFnAttr(fn_table_entry->llvm_value, "nobuiltin");
     if (g->build_mode == BuildModeDebug && fn_table_entry->fn_inline != FnInlineAlways) {
test/cases/struct.zig
@@ -258,12 +258,7 @@ test "packed struct 24bits" {
         assert(@sizeOf(Foo96Bits) == 12);
     }
 
-    // TODO workaround for LLVM bug on windows
-    // http://lists.llvm.org/pipermail/llvm-dev/2017-September/117864.html
-    const align_bytes = if (builtin.os == builtin.Os.windows and
-        builtin.arch == builtin.Arch.x86_64) 32 else @alignOf(Foo96Bits);
-
-    var value align(align_bytes) = Foo96Bits {
+    var value = Foo96Bits {
         .a = 0,
         .b = 0,
         .c = 0,