diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-06-19 19:01:28 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-06-19 19:01:28 -0400 |
| commit | 04c25efe112e374facaf1bc8b58bbdb6999a39e3 (patch) | |
| tree | 66a70b185ad8e44a69c8be27dd7dbc23425b040c /src | |
| parent | 4ffab5b85f03f63a7e724698482f8497cacc7212 (diff) | |
| parent | 381c6a38b145665a22440f7aa816f0ddd9b70ee5 (diff) | |
| download | zig-04c25efe112e374facaf1bc8b58bbdb6999a39e3.tar.gz zig-04c25efe112e374facaf1bc8b58bbdb6999a39e3.zip | |
Merge remote-tracking branch 'origin/master' into copy-elision-3
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.hpp | 2 | ||||
| -rw-r--r-- | src/codegen.cpp | 3 | ||||
| -rw-r--r-- | src/ir.cpp | 9 | ||||
| -rw-r--r-- | src/libc_installation.cpp | 6 | ||||
| -rw-r--r-- | src/link.cpp | 3 | ||||
| -rw-r--r-- | src/main.cpp | 28 | ||||
| -rw-r--r-- | src/os.cpp | 56 | ||||
| -rw-r--r-- | src/os.hpp | 4 |
8 files changed, 57 insertions, 54 deletions
diff --git a/src/buffer.hpp b/src/buffer.hpp index 082d584e2c..d4a911fc21 100644 --- a/src/buffer.hpp +++ b/src/buffer.hpp @@ -27,11 +27,13 @@ Buf *buf_sprintf(const char *format, ...) Buf *buf_vprintf(const char *format, va_list ap); static inline size_t buf_len(Buf *buf) { + assert(buf); assert(buf->list.length); return buf->list.length - 1; } static inline char *buf_ptr(Buf *buf) { + assert(buf); assert(buf->list.length); return buf->list.items; } diff --git a/src/codegen.cpp b/src/codegen.cpp index b55b8a1094..6830007f32 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8732,6 +8732,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { Termination term; ZigList<const char *> args = {}; + args.append(buf_ptr(self_exe_path)); args.append("cc"); Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path)); @@ -8750,7 +8751,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { if (g->verbose_cc) { print_zig_cc_cmd("zig", &args); } - os_spawn_process(buf_ptr(self_exe_path), args, &term); + os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nThe following command failed:\n"); print_zig_cc_cmd(buf_ptr(self_exe_path), &args); diff --git a/src/ir.cpp b/src/ir.cpp index 0a920c0974..b2ff8f5896 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -18046,7 +18046,9 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, case ZigTypeIdPromise: case ZigTypeIdVector: { - if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) + ResolveStatus needed_status = (align_bytes == 0) ? + ResolveStatusZeroBitsKnown : ResolveStatusAlignmentKnown; + if ((err = type_resolve(ira->codegen, child_type, needed_status))) return ira->codegen->invalid_instruction; ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero); @@ -19901,10 +19903,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr true, false, PtrLenUnknown, 0, 0, 0, false); fn_decl_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); - if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { + if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) { fn_decl_fields[6].data.x_optional = create_const_vals(1); ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name); - init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0, buf_len(fn_node->lib_name), true); + init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0, + buf_len(fn_node->lib_name), true); } else { fn_decl_fields[6].data.x_optional = nullptr; } diff --git a/src/libc_installation.cpp b/src/libc_installation.cpp index d1773b89e7..135941dc40 100644 --- a/src/libc_installation.cpp +++ b/src/libc_installation.cpp @@ -153,6 +153,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b const char *cc_exe = getenv("CC"); cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; ZigList<const char *> args = {}; + args.append(cc_exe); args.append("-E"); args.append("-Wp,-v"); args.append("-xc"); @@ -166,7 +167,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b Buf *out_stderr = buf_alloc(); Buf *out_stdout = buf_alloc(); Error err; - if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { + if ((err = os_exec_process(args, &term, out_stderr, out_stdout))) { if (verbose) { fprintf(stderr, "unable to determine libc include path: executing '%s': %s\n", cc_exe, err_str(err)); } @@ -277,12 +278,13 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam const char *cc_exe = getenv("CC"); cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; ZigList<const char *> args = {}; + args.append(cc_exe); args.append(buf_ptr(buf_sprintf("-print-file-name=%s", o_file))); Termination term; Buf *out_stderr = buf_alloc(); Buf *out_stdout = buf_alloc(); Error err; - if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { + if ((err = os_exec_process(args, &term, out_stderr, out_stdout))) { if (err == ErrorFileNotFound) return ErrorNoCCompilerInstalled; if (verbose) { diff --git a/src/link.cpp b/src/link.cpp index 3a437e4eda..277dcbc5c6 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1721,10 +1721,11 @@ void codegen_link(CodeGen *g) { if (g->system_linker_hack && g->zig_target->os == OsMacOSX) { Termination term; ZigList<const char *> args = {}; + args.append("ld"); for (size_t i = 1; i < lj.args.length; i += 1) { args.append(lj.args.at(i)); } - os_spawn_process("ld", args, &term); + os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { exit(1); } diff --git a/src/main.cpp b/src/main.cpp index 9c14ba3250..9b1892061b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -467,6 +467,7 @@ int main(int argc, char **argv) { init_all_targets(); ZigList<const char *> args = {0}; + args.append(NULL); // placeholder args.append(zig_exe_path); args.append(NULL); // placeholder args.append(NULL); // placeholder @@ -525,8 +526,8 @@ int main(int argc, char **argv) { g->enable_time_report = timing_info; codegen_set_out_name(g, buf_create_from_str("build")); - args.items[1] = buf_ptr(&build_file_dirname); - args.items[2] = buf_ptr(&full_cache_dir); + args.items[2] = buf_ptr(&build_file_dirname); + args.items[3] = buf_ptr(&full_cache_dir); bool build_file_exists; if ((err = os_file_exists(&build_file_abs, &build_file_exists))) { @@ -580,12 +581,14 @@ int main(int argc, char **argv) { codegen_build_and_link(g); Termination term; - os_spawn_process(buf_ptr(&g->output_file_path), args, &term); + args.items[0] = buf_ptr(&g->output_file_path); + os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nBuild failed. The following command failed:\n"); - fprintf(stderr, "%s", buf_ptr(&g->output_file_path)); + const char *prefix = ""; for (size_t i = 0; i < args.length; i += 1) { - fprintf(stderr, " %s", args.at(i)); + fprintf(stderr, "%s%s", prefix, args.at(i)); + prefix = " "; } fprintf(stderr, "\n"); } @@ -1161,7 +1164,7 @@ int main(int argc, char **argv) { args.pop(); Termination term; - os_spawn_process(exec_path, args, &term); + os_spawn_process(args, &term); return term.code; } else if (cmd == CmdBuild) { if (g->enable_cache) { @@ -1213,17 +1216,10 @@ int main(int argc, char **argv) { } Termination term; - if (test_exec_args.length > 0) { - ZigList<const char *> rest_args = {0}; - for (size_t i = 1; i < test_exec_args.length; i += 1) { - rest_args.append(test_exec_args.at(i)); - } - os_spawn_process(test_exec_args.items[0], rest_args, &term); - } else { - ZigList<const char *> no_args = {0}; - os_spawn_process(buf_ptr(test_exe_path), no_args, &term); + if (test_exec_args.length == 0) { + test_exec_args.append(buf_ptr(test_exe_path)); } - + os_spawn_process(test_exec_args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nTests failed. Use the following command to reproduce the failure:\n"); fprintf(stderr, "%s\n", buf_ptr(test_exe_path)); diff --git a/src/os.cpp b/src/os.cpp index e3d223325f..bc28b1e7a6 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -105,16 +105,15 @@ static void populate_termination(Termination *term, int status) { } } -static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, Termination *term) { - const char **argv = allocate<const char *>(args.length + 2); - argv[0] = exe; - argv[args.length + 1] = nullptr; +static void os_spawn_process_posix(ZigList<const char *> &args, Termination *term) { + const char **argv = allocate<const char *>(args.length + 1); for (size_t i = 0; i < args.length; i += 1) { - argv[i + 1] = args.at(i); + argv[i] = args.at(i); } + argv[args.length] = nullptr; pid_t pid; - int rc = posix_spawnp(&pid, exe, nullptr, nullptr, const_cast<char *const*>(argv), environ); + int rc = posix_spawnp(&pid, args.at(0), nullptr, nullptr, const_cast<char *const*>(argv), environ); if (rc != 0) { zig_panic("posix_spawn failed: %s", strerror(rc)); } @@ -126,16 +125,14 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, #endif #if defined(ZIG_OS_WINDOWS) -static void os_windows_create_command_line(Buf *command_line, const char *exe, ZigList<const char *> &args) { - buf_resize(command_line, 0); - - buf_append_char(command_line, '\"'); - buf_append_str(command_line, exe); - buf_append_char(command_line, '\"'); +static void os_windows_create_command_line(Buf *command_line, ZigList<const char *> &args) { + buf_resize(command_line, 0); + char *prefix = "\""; for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) { - buf_append_str(command_line, " \""); const char *arg = args.at(arg_i); + buf_append_str(command_line, prefix); + prefix = " \""; size_t arg_len = strlen(arg); for (size_t c_i = 0; c_i < arg_len; c_i += 1) { if (arg[c_i] == '\"') { @@ -147,14 +144,15 @@ static void os_windows_create_command_line(Buf *command_line, const char *exe, Z } } -static void os_spawn_process_windows(const char *exe, ZigList<const char *> &args, Termination *term) { +static void os_spawn_process_windows(ZigList<const char *> &args, Termination *term) { Buf command_line = BUF_INIT; - os_windows_create_command_line(&command_line, exe, args); + os_windows_create_command_line(&command_line, args); PROCESS_INFORMATION piProcInfo = {0}; STARTUPINFO siStartInfo = {0}; siStartInfo.cb = sizeof(STARTUPINFO); + const char *exe = args.at(0); BOOL success = CreateProcessA(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &siStartInfo, &piProcInfo); @@ -173,11 +171,11 @@ static void os_spawn_process_windows(const char *exe, ZigList<const char *> &arg } #endif -void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term) { +void os_spawn_process(ZigList<const char *> &args, Termination *term) { #if defined(ZIG_OS_WINDOWS) - os_spawn_process_windows(exe, args, term); + os_spawn_process_windows(args, term); #elif defined(ZIG_OS_POSIX) - os_spawn_process_posix(exe, args, term); + os_spawn_process_posix(args, term); #else #error "missing os_spawn_process implementation" #endif @@ -785,7 +783,7 @@ Error os_file_exists(Buf *full_path, bool *result) { } #if defined(ZIG_OS_POSIX) -static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, +static Error os_exec_process_posix(ZigList<const char *> &args, Termination *term, Buf *out_stderr, Buf *out_stdout) { int stdin_pipe[2]; @@ -817,13 +815,12 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, if (dup2(stderr_pipe[1], STDERR_FILENO) == -1) zig_panic("dup2 failed"); - const char **argv = allocate<const char *>(args.length + 2); - argv[0] = exe; - argv[args.length + 1] = nullptr; + const char **argv = allocate<const char *>(args.length + 1); + argv[args.length] = nullptr; for (size_t i = 0; i < args.length; i += 1) { - argv[i + 1] = args.at(i); + argv[i] = args.at(i); } - execvp(exe, const_cast<char * const *>(argv)); + execvp(argv[0], const_cast<char * const *>(argv)); Error report_err = ErrorUnexpected; if (errno == ENOENT) { report_err = ErrorFileNotFound; @@ -874,11 +871,11 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, // LocalFree(messageBuffer); //} -static Error os_exec_process_windows(const char *exe, ZigList<const char *> &args, +static Error os_exec_process_windows(ZigList<const char *> &args, Termination *term, Buf *out_stderr, Buf *out_stdout) { Buf command_line = BUF_INIT; - os_windows_create_command_line(&command_line, exe, args); + os_windows_create_command_line(&command_line, args); HANDLE g_hChildStd_IN_Rd = NULL; HANDLE g_hChildStd_IN_Wr = NULL; @@ -925,6 +922,7 @@ static Error os_exec_process_windows(const char *exe, ZigList<const char *> &arg siStartInfo.hStdInput = g_hChildStd_IN_Rd; siStartInfo.dwFlags |= STARTF_USESTDHANDLES; + const char *exe = args.at(0); BOOL success = CreateProcess(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &siStartInfo, &piProcInfo); @@ -1005,13 +1003,13 @@ Error os_execv(const char *exe, const char **argv) { #endif } -Error os_exec_process(const char *exe, ZigList<const char *> &args, +Error os_exec_process(ZigList<const char *> &args, Termination *term, Buf *out_stderr, Buf *out_stdout) { #if defined(ZIG_OS_WINDOWS) - return os_exec_process_windows(exe, args, term, out_stderr, out_stdout); + return os_exec_process_windows(args, term, out_stderr, out_stdout); #elif defined(ZIG_OS_POSIX) - return os_exec_process_posix(exe, args, term, out_stderr, out_stdout); + return os_exec_process_posix(args, term, out_stderr, out_stdout); #else #error "missing os_exec_process implementation" #endif diff --git a/src/os.hpp b/src/os.hpp index 058bb2020c..c8135e9844 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -100,8 +100,8 @@ struct OsFileAttr { int os_init(void); -void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term); -Error os_exec_process(const char *exe, ZigList<const char *> &args, +void os_spawn_process(ZigList<const char *> &args, Termination *term); +Error os_exec_process(ZigList<const char *> &args, Termination *term, Buf *out_stderr, Buf *out_stdout); Error os_execv(const char *exe, const char **argv); |
