aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-08-23 11:43:37 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-08-23 11:43:37 -0400
commit3865b6ad8f8ba71dca06c81828ec2e29f3019879 (patch)
treecfadbebe532708c931bddcc8e5b262d63946c78d /src
parent79a4b7a2365dc50d01eb6bc29bbb77244a1620cf (diff)
parentec2f9ef4e8be5995ab652dde59b12ee340a9e28d (diff)
downloadzig-3865b6ad8f8ba71dca06c81828ec2e29f3019879.tar.gz
zig-3865b6ad8f8ba71dca06c81828ec2e29f3019879.zip
Merge remote-tracking branch 'origin/master' into fix-field-alignment-kludge
Diffstat (limited to 'src')
-rw-r--r--src/all_types.hpp2
-rw-r--r--src/analyze.cpp28
-rw-r--r--src/bigint.cpp23
-rw-r--r--src/bigint.hpp5
-rw-r--r--src/codegen.cpp2
-rw-r--r--src/ir.cpp48
-rw-r--r--src/os.cpp30
-rw-r--r--src/os.hpp8
-rw-r--r--src/parser.cpp8
-rw-r--r--src/target.cpp15
10 files changed, 112 insertions, 57 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp
index de82159d27..3e811311b0 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -895,6 +895,8 @@ struct AstNodeStructField {
Buf *name;
AstNode *type;
AstNode *value;
+ // populated if the "align(A)" is present
+ AstNode *align_expr;
};
struct AstNodeStringLiteral {
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 414ce09b2c..84299a5c8b 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -1147,7 +1147,7 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
if (type_is_invalid(align_result->type))
return false;
- uint32_t align_bytes = bigint_as_unsigned(&align_result->data.x_bigint);
+ uint32_t align_bytes = bigint_as_u32(&align_result->data.x_bigint);
if (align_bytes == 0) {
add_node_error(g, node, buf_sprintf("alignment must be >= 1"));
return false;
@@ -1179,7 +1179,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
return true;
}
expand_undef_array(g, array_val);
- size_t len = bigint_as_unsigned(&len_field->data.x_bigint);
+ size_t len = bigint_as_usize(&len_field->data.x_bigint);
Buf *result = buf_alloc();
buf_resize(result, len);
for (size_t i = 0; i < len; i += 1) {
@@ -1189,7 +1189,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
add_node_error(g, node, buf_sprintf("use of undefined value"));
return false;
}
- uint64_t big_c = bigint_as_unsigned(&char_val->data.x_bigint);
+ uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
assert(big_c <= UINT8_MAX);
uint8_t c = (uint8_t)big_c;
buf_ptr(result)[i] = c;
@@ -2384,19 +2384,25 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
if (field->gen_index == SIZE_MAX)
continue;
- // TODO: https://github.com/ziglang/zig/issues/1512
- size_t this_field_align;
- if (packed) {
- this_field_align = 1;
+ AstNode *align_expr = field->decl_node->data.struct_field.align_expr;
+ if (align_expr != nullptr) {
+ if (!analyze_const_align(g, &struct_type->data.structure.decls_scope->base, align_expr,
+ &field->align))
+ {
+ struct_type->data.structure.resolve_status = ResolveStatusInvalid;
+ return err;
+ }
+ } else if (packed) {
+ field->align = 1;
} else {
- if ((err = type_val_resolve_abi_align(g, field->type_val, &this_field_align))) {
+ if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) {
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
return err;
}
}
- if (this_field_align > struct_type->abi_align) {
- struct_type->abi_align = this_field_align;
+ if (field->align > struct_type->abi_align) {
+ struct_type->abi_align = field->align;
}
}
@@ -6008,7 +6014,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
{
if (is_slice(type_entry)) {
ConstExprValue *len_val = &const_val->data.x_struct.fields[slice_len_index];
- size_t len = bigint_as_unsigned(&len_val->data.x_bigint);
+ size_t len = bigint_as_usize(&len_val->data.x_bigint);
ConstExprValue *ptr_val = &const_val->data.x_struct.fields[slice_ptr_index];
if (ptr_val->special == ConstValSpecialUndef) {
diff --git a/src/bigint.cpp b/src/bigint.cpp
index da53a2b129..b227b3b4f7 100644
--- a/src/bigint.cpp
+++ b/src/bigint.cpp
@@ -15,6 +15,8 @@
#include <limits>
#include <algorithm>
+static uint64_t bigint_as_unsigned(const BigInt *bigint);
+
static void bigint_normalize(BigInt *dest) {
const uint64_t *digits = bigint_ptr(dest);
@@ -1660,7 +1662,7 @@ size_t bigint_clz(const BigInt *bi, size_t bit_count) {
return count;
}
-uint64_t bigint_as_unsigned(const BigInt *bigint) {
+static uint64_t bigint_as_unsigned(const BigInt *bigint) {
assert(!bigint->is_negative);
if (bigint->digit_count == 0) {
return 0;
@@ -1671,6 +1673,25 @@ uint64_t bigint_as_unsigned(const BigInt *bigint) {
}
}
+uint64_t bigint_as_u64(const BigInt *bigint)
+{
+ return bigint_as_unsigned(bigint);
+}
+
+uint32_t bigint_as_u32(const BigInt *bigint) {
+ uint64_t value64 = bigint_as_unsigned(bigint);
+ uint32_t value32 = (uint32_t)value64;
+ assert (value64 == value32);
+ return value32;
+}
+
+size_t bigint_as_usize(const BigInt *bigint) {
+ uint64_t value64 = bigint_as_unsigned(bigint);
+ size_t valueUsize = (size_t)value64;
+ assert (value64 == valueUsize);
+ return valueUsize;
+}
+
int64_t bigint_as_signed(const BigInt *bigint) {
if (bigint->digit_count == 0) {
return 0;
diff --git a/src/bigint.hpp b/src/bigint.hpp
index 48b222a227..276ccd64f9 100644
--- a/src/bigint.hpp
+++ b/src/bigint.hpp
@@ -36,7 +36,10 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op);
void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative);
// panics if number won't fit
-uint64_t bigint_as_unsigned(const BigInt *bigint);
+uint64_t bigint_as_u64(const BigInt *bigint);
+uint32_t bigint_as_u32(const BigInt *bigint);
+size_t bigint_as_usize(const BigInt *bigint);
+
int64_t bigint_as_signed(const BigInt *bigint);
static inline const uint64_t *bigint_ptr(const BigInt *bigint) {
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 2be4ebbbc9..cfeb0187eb 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -2872,7 +2872,7 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
eval_min_max_value_int(g, int_type, &biggest_possible_err_val, true);
if (bigint_fits_in_bits(&biggest_possible_err_val, 64, false) &&
- bigint_as_unsigned(&biggest_possible_err_val) < g->errors_by_index.length)
+ bigint_as_usize(&biggest_possible_err_val) < g->errors_by_index.length)
{
ok_bit = neq_zero_bit;
} else {
diff --git a/src/ir.cpp b/src/ir.cpp
index c545109d24..789126cf67 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -5768,7 +5768,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
return irb->codegen->invalid_instruction;
}
- bit_offset_start = bigint_as_unsigned(node->data.pointer_type.bit_offset_start);
+ bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);
}
uint32_t host_int_bytes = 0;
@@ -5780,7 +5780,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));
return irb->codegen->invalid_instruction;
}
- host_int_bytes = bigint_as_unsigned(node->data.pointer_type.host_int_bytes);
+ host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);
}
if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {
@@ -11589,7 +11589,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
return ira->codegen->invalid_instruction;
}
- size_t index = bigint_as_unsigned(&val->data.x_bigint);
+ size_t index = bigint_as_usize(&val->data.x_bigint);
result->value.data.x_err_set = ira->codegen->errors_by_index.at(index);
return result;
} else {
@@ -12554,7 +12554,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
if ((err = ir_resolve_const_val(codegen, exec, source_node, const_val, UndefBad)))
return false;
- uint32_t align_bytes = bigint_as_unsigned(&const_val->data.x_bigint);
+ uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);
if (align_bytes == 0) {
exec_add_error_node(codegen, exec, source_node, buf_sprintf("alignment must be >= 1"));
return false;
@@ -12594,7 +12594,7 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
if (!const_val)
return false;
- *out = bigint_as_unsigned(&const_val->data.x_bigint);
+ *out = bigint_as_u64(&const_val->data.x_bigint);
return true;
}
@@ -12642,7 +12642,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
if (!const_val)
return false;
- *out = (AtomicOrder)bigint_as_unsigned(&const_val->data.x_enum_tag);
+ *out = (AtomicOrder)bigint_as_u32(&const_val->data.x_enum_tag);
return true;
}
@@ -12662,7 +12662,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
if (!const_val)
return false;
- *out = (AtomicRmwOp)bigint_as_unsigned(&const_val->data.x_enum_tag);
+ *out = (AtomicRmwOp)bigint_as_u32(&const_val->data.x_enum_tag);
return true;
}
@@ -12682,7 +12682,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
if (!const_val)
return false;
- *out = (GlobalLinkageId)bigint_as_unsigned(&const_val->data.x_enum_tag);
+ *out = (GlobalLinkageId)bigint_as_u32(&const_val->data.x_enum_tag);
return true;
}
@@ -12702,7 +12702,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
if (!const_val)
return false;
- *out = (FloatMode)bigint_as_unsigned(&const_val->data.x_enum_tag);
+ *out = (FloatMode)bigint_as_u32(&const_val->data.x_enum_tag);
return true;
}
@@ -12731,7 +12731,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
return array_val->data.x_array.data.s_buf;
}
expand_undef_array(ira->codegen, array_val);
- size_t len = bigint_as_unsigned(&len_field->data.x_bigint);
+ size_t len = bigint_as_usize(&len_field->data.x_bigint);
Buf *result = buf_alloc();
buf_resize(result, len);
for (size_t i = 0; i < len; i += 1) {
@@ -12741,7 +12741,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
return nullptr;
}
- uint64_t big_c = bigint_as_unsigned(&char_val->data.x_bigint);
+ uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
assert(big_c <= UINT8_MAX);
uint8_t c = (uint8_t)big_c;
buf_ptr(result)[i] = c;
@@ -13891,7 +13891,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
ConstExprValue *len_val = &op1_val->data.x_struct.fields[slice_len_index];
- op1_array_end = op1_array_index + bigint_as_unsigned(&len_val->data.x_bigint);
+ op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
} else {
ir_add_error(ira, op1,
buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name)));
@@ -13924,7 +13924,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
ConstExprValue *len_val = &op2_val->data.x_struct.fields[slice_len_index];
- op2_array_end = op2_array_index + bigint_as_unsigned(&len_val->data.x_bigint);
+ op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
} else {
ir_add_error(ira, op2,
buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));
@@ -16803,7 +16803,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
uint64_t ptr_align = get_ptr_align(ira->codegen, return_type);
if (instr_is_comptime(casted_elem_index)) {
- uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint);
+ uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint);
if (array_type->id == ZigTypeIdArray) {
uint64_t array_len = array_type->data.array.len;
if (index >= array_len) {
@@ -16965,7 +16965,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
ConstExprValue *out_val = &result->value;
- uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);
+ uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
if (index >= slice_len) {
ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
@@ -21250,7 +21250,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
ConstExprValue *len_val = &val->data.x_struct.fields[slice_len_index];
if (value_is_comptime(len_val)) {
- known_len = bigint_as_unsigned(&len_val->data.x_bigint);
+ known_len = bigint_as_u64(&len_val->data.x_bigint);
have_known_len = true;
}
}
@@ -21607,7 +21607,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
zig_panic("TODO memset on null ptr");
}
- size_t count = bigint_as_unsigned(&count_val->data.x_bigint);
+ size_t count = bigint_as_usize(&count_val->data.x_bigint);
size_t end = start + count;
if (end > bound_end) {
ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));
@@ -21704,7 +21704,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
return ira->codegen->invalid_instruction;
if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
- size_t count = bigint_as_unsigned(&count_val->data.x_bigint);
+ size_t count = bigint_as_usize(&count_val->data.x_bigint);
ConstExprValue *dest_elements;
size_t dest_start;
@@ -21988,7 +21988,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
case ConstPtrSpecialBaseArray:
array_val = parent_ptr->data.x_ptr.data.base_array.array_val;
abs_offset = parent_ptr->data.x_ptr.data.base_array.elem_index;
- rel_end = bigint_as_unsigned(&len_val->data.x_bigint);
+ rel_end = bigint_as_usize(&len_val->data.x_bigint);
break;
case ConstPtrSpecialBaseStruct:
zig_panic("TODO slice const inner struct");
@@ -22001,7 +22001,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
case ConstPtrSpecialHardCodedAddr:
array_val = nullptr;
abs_offset = 0;
- rel_end = bigint_as_unsigned(&len_val->data.x_bigint);
+ rel_end = bigint_as_usize(&len_val->data.x_bigint);
break;
case ConstPtrSpecialFunction:
zig_panic("TODO slice of slice cast from function");
@@ -22012,7 +22012,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
zig_unreachable();
}
- uint64_t start_scalar = bigint_as_unsigned(&casted_start->value.data.x_bigint);
+ uint64_t start_scalar = bigint_as_u64(&casted_start->value.data.x_bigint);
if (!ptr_is_undef && start_scalar > rel_end) {
ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));
return ira->codegen->invalid_instruction;
@@ -22020,7 +22020,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
uint64_t end_scalar;
if (end) {
- end_scalar = bigint_as_unsigned(&end->value.data.x_bigint);
+ end_scalar = bigint_as_u64(&end->value.data.x_bigint);
} else {
end_scalar = rel_end;
}
@@ -23622,7 +23622,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
BigInt bn;
bigint_read_twos_complement(&bn, buf, codegen->builtin_types.entry_usize->data.integral.bit_count,
codegen->is_big_endian, false);
- val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);
+ val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_usize(&bn);
return ErrorNone;
}
case ZigTypeIdArray:
@@ -23815,7 +23815,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
if (!val)
return ira->codegen->invalid_instruction;
- uint64_t addr = bigint_as_unsigned(&val->data.x_bigint);
+ uint64_t addr = bigint_as_u64(&val->data.x_bigint);
if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
ir_add_error(ira, source_instr,
buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));
diff --git a/src/os.cpp b/src/os.cpp
index 5fa70bd260..6c1a2581df 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -1125,29 +1125,27 @@ Error os_get_cwd(Buf *out_cwd) {
#endif
}
-#if defined(ZIG_OS_WINDOWS)
#define is_wprefix(s, prefix) \
(wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0)
-static bool is_stderr_cyg_pty(void) {
- HANDLE stderr_handle = GetStdHandle(STD_ERROR_HANDLE);
- if (stderr_handle == INVALID_HANDLE_VALUE)
+bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {
+#if defined(ZIG_OS_WINDOWS)
+ HANDLE handle = (HANDLE)_get_osfhandle(fd);
+
+ // Cygwin/msys's pty is a pipe.
+ if (handle == INVALID_HANDLE_VALUE || GetFileType(handle) != FILE_TYPE_PIPE) {
return false;
+ }
int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
- FILE_NAME_INFO *nameinfo;
WCHAR *p = NULL;
- // Cygwin/msys's pty is a pipe.
- if (GetFileType(stderr_handle) != FILE_TYPE_PIPE) {
- return 0;
- }
- nameinfo = (FILE_NAME_INFO *)allocate<char>(size);
+ FILE_NAME_INFO *nameinfo = (FILE_NAME_INFO *)allocate<char>(size);
if (nameinfo == NULL) {
- return 0;
+ return false;
}
// Check the name of the pipe:
// '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master'
- if (GetFileInformationByHandleEx(stderr_handle, FileNameInfo, nameinfo, size)) {
+ if (GetFileInformationByHandleEx(handle, FileNameInfo, nameinfo, size)) {
nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0';
p = nameinfo->FileName;
if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */
@@ -1180,12 +1178,14 @@ static bool is_stderr_cyg_pty(void) {
}
free(nameinfo);
return (p != NULL);
-}
+#else
+ return false;
#endif
+}
bool os_stderr_tty(void) {
#if defined(ZIG_OS_WINDOWS)
- return _isatty(_fileno(stderr)) != 0 || is_stderr_cyg_pty();
+ return _isatty(fileno(stderr)) != 0 || os_is_cygwin_pty(fileno(stderr));
#elif defined(ZIG_OS_POSIX)
return isatty(STDERR_FILENO) != 0;
#else
@@ -1486,7 +1486,7 @@ WORD original_console_attributes = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BL
void os_stderr_set_color(TermColor color) {
#if defined(ZIG_OS_WINDOWS)
- if (is_stderr_cyg_pty()) {
+ if (os_stderr_tty()) {
set_color_posix(color);
return;
}
diff --git a/src/os.hpp b/src/os.hpp
index c8135e9844..7354528c34 100644
--- a/src/os.hpp
+++ b/src/os.hpp
@@ -11,6 +11,7 @@
#include "list.hpp"
#include "buffer.hpp"
#include "error.hpp"
+#include "target.hpp"
#include "zig_llvm.h"
#include "windows_sdk.h"
@@ -88,6 +89,11 @@ struct Termination {
#define OsFile int
#endif
+#if defined(ZIG_OS_WINDOWS)
+#undef fileno
+#define fileno _fileno
+#endif
+
struct OsTimeStamp {
uint64_t sec;
uint64_t nsec;
@@ -152,6 +158,8 @@ Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_include_path(ZigWindowsSDK *sdk, Buf
Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_lib_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);
Error ATTRIBUTE_MUST_USE os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);
+bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd);
+
Error ATTRIBUTE_MUST_USE os_self_exe_shared_libs(ZigList<Buf *> &paths);
#endif
diff --git a/src/parser.cpp b/src/parser.cpp
index 1e7e36d0bd..6cd6c2f045 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -782,24 +782,26 @@ static AstNode *ast_parse_var_decl(ParseContext *pc) {
return res;
}
-// ContainerField <- IDENTIFIER (COLON TypeExpr)? (EQUAL Expr)?
+// ContainerField <- IDENTIFIER (COLON TypeExpr ByteAlign?)? (EQUAL Expr)?
static AstNode *ast_parse_container_field(ParseContext *pc) {
Token *identifier = eat_token_if(pc, TokenIdSymbol);
if (identifier == nullptr)
return nullptr;
AstNode *type_expr = nullptr;
- if (eat_token_if(pc, TokenIdColon) != nullptr)
+ if (eat_token_if(pc, TokenIdColon) != nullptr) {
type_expr = ast_expect(pc, ast_parse_type_expr);
+ }
+ AstNode *align_expr = ast_parse_byte_align(pc);
AstNode *expr = nullptr;
if (eat_token_if(pc, TokenIdEq) != nullptr)
expr = ast_expect(pc, ast_parse_expr);
-
AstNode *res = ast_create_node(pc, NodeTypeStructField, identifier);
res->data.struct_field.name = token_buf(identifier);
res->data.struct_field.type = type_expr;
res->data.struct_field.value = expr;
+ res->data.struct_field.align_expr = align_expr;
return res;
}
diff --git a/src/target.cpp b/src/target.cpp
index 8d73af6a01..65d72bf5f2 100644
--- a/src/target.cpp
+++ b/src/target.cpp
@@ -491,6 +491,16 @@ Error target_parse_glibc_version(ZigGLibCVersion *glibc_ver, const char *text) {
return ErrorNone;
}
+static ZigLLVM_EnvironmentType target_get_win32_abi() {
+ FILE* files[] = { stdin, stdout, stderr, nullptr };
+ for (int i = 0; files[i] != nullptr; i++) {
+ if (os_is_cygwin_pty(fileno(files[i]))) {
+ return ZigLLVM_GNU;
+ }
+ }
+ return ZigLLVM_MSVC;
+}
+
void get_native_target(ZigTarget *target) {
// first zero initialize
*target = {};
@@ -505,6 +515,9 @@ void get_native_target(ZigTarget *target) {
&target->abi,
&oformat);
target->os = get_zig_os_type(os_type);
+ if (target->os == OsWindows) {
+ target->abi = target_get_win32_abi();
+ }
target->is_native = true;
if (target->abi == ZigLLVM_UnknownEnvironment) {
target->abi = target_default_abi(target->arch, target->os);
@@ -1601,7 +1614,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
return ZigLLVM_GNU;
case OsUefi:
case OsWindows:
- return ZigLLVM_MSVC;
+ return ZigLLVM_MSVC;
case OsLinux:
case OsWASI:
return ZigLLVM_Musl;