Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zig-lang/zig into MemChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
BraedonWooding committed Apr 24, 2018
2 parents 96d1e51 + 15bf0c1 commit 5183b39
Show file tree
Hide file tree
Showing 26 changed files with 1,317 additions and 83 deletions.
22 changes: 13 additions & 9 deletions .travis.yml
@@ -1,18 +1,22 @@
sudo: required
services:
- docker
- docker
os:
- linux
- osx
- linux
- osx
dist: trusty
osx_image: xcode8.3
language: cpp
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ci/travis_linux_before_install; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ci/travis_osx_before_install; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ci/travis_linux_before_install; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ci/travis_osx_before_install; fi
install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ci/travis_linux_install; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ci/travis_osx_install; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ci/travis_linux_install; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ci/travis_osx_install; fi
script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ci/travis_linux_script; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ci/travis_osx_script; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ci/travis_linux_script; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ci/travis_osx_script; fi
env:
global:
- secure: QmJ+eLOxj3Irl5SHxt6lQvrj7++1AIz8bYri6RScAQGHQPIztkmbpBjAkpFgYaWPkZ04ROtamFXdS7oHtJHSECesgPoqM/CHIychQkgpDq30+TsFyYbBpDGHY+N6r2WnQTvg+9EuAp6P365us6qFS0D5zQ3P40c56uMbazFu3J4W1HZP+pLWlLjEXaN88ePhHWqNZyvwGMkLpYl3ghc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YkJVlNW1/TTyJJOOvjMQCjF8SJmPHuh+QpqKbSaT9XM/vBhxbIZEufH8kawJKCBBcCNspGMNjhXfNjM0=
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -508,8 +508,11 @@ set(ZIG_STD_FILES
"os/index.zig"
"os/linux/errno.zig"
"os/linux/index.zig"
"os/linux/vdso.zig"
"os/linux/x86_64.zig"
"os/path.zig"
"os/time.zig"
"os/epoch.zig"
"os/windows/error.zig"
"os/windows/index.zig"
"os/windows/util.zig"
Expand Down
15 changes: 10 additions & 5 deletions src/analyze.cpp
Expand Up @@ -4306,7 +4306,8 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
static ZigWindowsSDK *get_windows_sdk(CodeGen *g) {
if (g->win_sdk == nullptr) {
if (os_find_windows_sdk(&g->win_sdk)) {
zig_panic("Unable to determine Windows SDK path.");
fprintf(stderr, "unable to determine windows sdk path\n");
exit(1);
}
}
assert(g->win_sdk != nullptr);
Expand Down Expand Up @@ -4408,7 +4409,8 @@ void find_libc_include_path(CodeGen *g) {
ZigWindowsSDK *sdk = get_windows_sdk(g);
g->libc_include_dir = buf_alloc();
if (os_get_win32_ucrt_include_path(sdk, g->libc_include_dir)) {
zig_panic("Unable to determine libc include path.");
fprintf(stderr, "Unable to determine libc include path. --libc-include-dir");
exit(1);
}
} else if (g->zig_target.os == OsLinux) {
g->libc_include_dir = get_linux_libc_include_path();
Expand All @@ -4433,23 +4435,26 @@ void find_libc_lib_path(CodeGen *g) {
if (g->msvc_lib_dir == nullptr) {
Buf* vc_lib_dir = buf_alloc();
if (os_get_win32_vcruntime_path(vc_lib_dir, g->zig_target.arch.arch)) {
zig_panic("Unable to determine vcruntime path.");
fprintf(stderr, "Unable to determine vcruntime path. --msvc-lib-dir");
exit(1);
}
g->msvc_lib_dir = vc_lib_dir;
}

if (g->libc_lib_dir == nullptr) {
Buf* ucrt_lib_path = buf_alloc();
if (os_get_win32_ucrt_lib_path(sdk, ucrt_lib_path, g->zig_target.arch.arch)) {
zig_panic("Unable to determine ucrt path.");
fprintf(stderr, "Unable to determine ucrt path. --libc-lib-dir");
exit(1);
}
g->libc_lib_dir = ucrt_lib_path;
}

if (g->kernel32_lib_dir == nullptr) {
Buf* kern_lib_path = buf_alloc();
if (os_get_win32_kern32_path(sdk, kern_lib_path, g->zig_target.arch.arch)) {
zig_panic("Unable to determine kernel32 path.");
fprintf(stderr, "Unable to determine kernel32 path. --kernel32-lib-dir");
exit(1);
}
g->kernel32_lib_dir = kern_lib_path;
}
Expand Down
5 changes: 5 additions & 0 deletions src/bigint.cpp
Expand Up @@ -86,6 +86,11 @@ static void to_twos_complement(BigInt *dest, const BigInt *op, size_t bit_count)
size_t digits_to_copy = bit_count / 64;
size_t leftover_bits = bit_count % 64;
dest->digit_count = digits_to_copy + ((leftover_bits == 0) ? 0 : 1);
if (dest->digit_count == 1 && leftover_bits == 0) {
dest->data.digit = op_digits[0];
if (dest->data.digit == 0) dest->digit_count = 0;
return;
}
dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
for (size_t i = 0; i < digits_to_copy; i += 1) {
uint64_t digit = (i < op->digit_count) ? op_digits[i] : 0;
Expand Down
16 changes: 14 additions & 2 deletions src/codegen.cpp
Expand Up @@ -3561,6 +3561,16 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,
success_order, failure_order, instruction->is_weak);

TypeTableEntry *maybe_type = instruction->base.value.type;
assert(maybe_type->id == TypeTableEntryIdMaybe);
TypeTableEntry *child_type = maybe_type->data.maybe.child_type;

if (type_is_codegen_pointer(child_type)) {
LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
LLVMValueRef success_bit = LLVMBuildExtractValue(g->builder, result_val, 1, "");
return LLVMBuildSelect(g->builder, success_bit, LLVMConstNull(child_type->type_ref), payload_val, "");
}

assert(instruction->tmp_ptr != nullptr);
assert(type_has_bits(instruction->type));

Expand Down Expand Up @@ -6628,12 +6638,14 @@ static void gen_root_source(CodeGen *g) {
Buf *abs_full_path = buf_alloc();
int err;
if ((err = os_path_real(rel_full_path, abs_full_path))) {
zig_panic("unable to open '%s': %s", buf_ptr(rel_full_path), err_str(err));
fprintf(stderr, "unable to open '%s': %s", buf_ptr(rel_full_path), err_str(err));
exit(1);
}

Buf *source_code = buf_alloc();
if ((err = os_fetch_file_path(rel_full_path, source_code, true))) {
zig_panic("unable to open '%s': %s", buf_ptr(rel_full_path), err_str(err));
fprintf(stderr, "unable to open '%s': %s", buf_ptr(rel_full_path), err_str(err));
exit(1);
}

g->root_import = add_source_file(g, g->root_package, abs_full_path, source_code);
Expand Down
8 changes: 7 additions & 1 deletion src/ir.cpp
Expand Up @@ -3147,6 +3147,9 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
if (block_node->data.block.name == nullptr || incoming_blocks.length == 0) {
return noreturn_return_value;
}

ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
return ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
} else {
incoming_blocks.append(irb->current_basic_block);
incoming_values.append(ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node)));
Expand Down Expand Up @@ -14782,7 +14785,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
return out_val->type;
}

assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) {
ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));
return ira->codegen->builtin_types.entry_invalid;
}

TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
ConstExprValue *pointee_val = nullptr;
Expand Down
18 changes: 18 additions & 0 deletions std/c/darwin.zig
Expand Up @@ -3,10 +3,28 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int;

pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;

pub extern "c" fn mach_absolute_time() u64;
pub extern "c" fn mach_timebase_info(tinfo: ?&mach_timebase_info_data) void;

pub use @import("../os/darwin_errno.zig");

pub const _errno = __error;

pub const timeval = extern struct {
tv_sec: isize,
tv_usec: isize,
};

pub const timezone = extern struct {
tz_minuteswest: i32,
tz_dsttime: i32,
};

pub const mach_timebase_info_data = struct {
numer: u32,
denom: u32,
};

/// Renamed to Stat to not conflict with the stat function.
pub const Stat = extern struct {
dev: i32,
Expand Down
1 change: 1 addition & 0 deletions std/c/index.zig
Expand Up @@ -41,6 +41,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
pub extern "c" fn gettimeofday(tv: ?&timeval, tz: ?&timezone) c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int;
pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
Expand Down

0 comments on commit 5183b39

Please sign in to comment.