diff options
| author | dimenus <ryan.saunderson88@gmail.com> | 2017-11-10 09:49:45 -0600 |
|---|---|---|
| committer | dimenus <ryan.saunderson88@gmail.com> | 2017-11-10 09:49:45 -0600 |
| commit | e9d7623e1f0300b1b652373f2e0e7b605eaf13d1 (patch) | |
| tree | 65470f2c68466ddc9f1663dc1b91f89324ebb2bd /src | |
| parent | 3a600297ca3f99ee57630c44900eec1fe7c92804 (diff) | |
| parent | 336d81894da2c34a77cffd1bf903ad9e4dcaa7aa (diff) | |
| download | zig-e9d7623e1f0300b1b652373f2e0e7b605eaf13d1.tar.gz zig-e9d7623e1f0300b1b652373f2e0e7b605eaf13d1.zip | |
Merge remote-tracking branch 'origin/master' into llvm6
Diffstat (limited to 'src')
| -rw-r--r-- | src/analyze.cpp | 2 | ||||
| -rw-r--r-- | src/codegen.cpp | 13 | ||||
| -rw-r--r-- | src/ir.cpp | 12 | ||||
| -rw-r--r-- | src/main.cpp | 108 |
4 files changed, 77 insertions, 58 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 0dc221408d..7d46ebc908 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1389,7 +1389,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) { return; } - TypeTableEntry *tag_int_type = get_smallest_unsigned_int_type(g, field_count); + TypeTableEntry *tag_int_type = get_smallest_unsigned_int_type(g, field_count - 1); TypeTableEntry *tag_type_entry = create_enum_tag_type(g, enum_type, tag_int_type); enum_type->data.enumeration.tag_type = tag_type_entry; diff --git a/src/codegen.cpp b/src/codegen.cpp index 976b20405e..38a1a2cbea 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2666,9 +2666,16 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable if (ir_want_debug_safety(g, &instruction->base)) { TypeTableEntry *enum_type = enum_tag_type->data.enum_tag.enum_type; size_t field_count = enum_type->data.enumeration.src_field_count; - LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(enum_tag_value)); - LLVMValueRef end_val = LLVMConstInt(LLVMTypeOf(enum_tag_value), field_count, false); - add_bounds_check(g, enum_tag_value, LLVMIntUGE, zero, LLVMIntULT, end_val); + + // if the field_count can't fit in the bits of the enum_tag_type, then it can't possibly + // be the wrong value + BigInt field_bi; + bigint_init_unsigned(&field_bi, field_count); + TypeTableEntry *tag_int_type = enum_tag_type->data.enum_tag.int_type; + if (bigint_fits_in_bits(&field_bi, tag_int_type->data.integral.bit_count, false)) { + LLVMValueRef end_val = LLVMConstInt(LLVMTypeOf(enum_tag_value), field_count, false); + add_bounds_check(g, enum_tag_value, LLVMIntEQ, nullptr, LLVMIntULT, end_val); + } } LLVMValueRef indices[] = { diff --git a/src/ir.cpp b/src/ir.cpp index ae48c1d369..901ba47b76 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -10311,8 +10311,17 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal { FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; size_t first_arg_1_or_0 = first_arg_ptr ? 1 : 0; - size_t var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0; + + // for extern functions, the var args argument is not counted. + // for zig functions, it is. + size_t var_args_1_or_0; + if (fn_type_id->cc == CallingConventionUnspecified) { + var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0; + } else { + var_args_1_or_0 = 0; + } size_t src_param_count = fn_type_id->param_count - var_args_1_or_0; + size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; AstNode *source_node = call_instruction->base.source_node; @@ -12823,6 +12832,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, case TypeTableEntryIdEnum: { TypeTableEntry *tag_type = target_type->data.enumeration.tag_type; + assert(tag_type != nullptr); if (pointee_val) { ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); bigint_init_unsigned(&out_val->data.x_bigint, pointee_val->data.x_enum.tag); diff --git a/src/main.cpp b/src/main.cpp index db463ac92b..13da71f9e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,70 +20,70 @@ static int usage(const char *arg0) { fprintf(stderr, "Usage: %s [command] [options]\n" "Commands:\n" " build build project from build.zig\n" - " build-exe $source create executable from source or object files\n" - " build-lib $source create library from source or object files\n" - " build-obj $source create object from source or assembly\n" - " parsec $source convert c code to zig code\n" + " build-exe [source] create executable from source or object files\n" + " build-lib [source] create library from source or object files\n" + " build-obj [source] create object from source or assembly\n" + " parsec [source] convert c code to zig code\n" " targets list available compilation targets\n" - " test $source create and run a test build\n" + " test [source] create and run a test build\n" " version print version number and exit\n" " zen print zen of zig and exit\n" "Compile Options:\n" - " --assembly $source add assembly file to build\n" - " --cache-dir $path override the cache directory\n" - " --color $auto|off|on enable or disable colored error messages\n" - " --emit $filetype emit a specific file format as compilation output\n" + " --assembly [source] add assembly file to build\n" + " --cache-dir [path] override the cache directory\n" + " --color [auto|off|on] enable or disable colored error messages\n" + " --emit [filetype] emit a specific file format as compilation output\n" " --enable-timing-info print timing diagnostics\n" - " --libc-include-dir $path directory where libc stdlib.h resides\n" - " --name $name override output name\n" - " --output $file override destination path\n" - " --output-h $file override generated header file path\n" - " --pkg-begin $name $path make package available to import and push current pkg\n" + " --libc-include-dir [path] directory where libc stdlib.h resides\n" + " --name [name] override output name\n" + " --output [file] override destination path\n" + " --output-h [file] override generated header file path\n" + " --pkg-begin [name] [path] make package available to import and push current pkg\n" " --pkg-end pop current pkg\n" " --release-fast build with optimizations on and safety off\n" " --release-safe build with optimizations on and safety on\n" " --static output will be statically linked\n" " --strip exclude debug symbols\n" - " --target-arch $name specify target architecture\n" - " --target-environ $name specify target environment\n" - " --target-os $name specify target operating system\n" + " --target-arch [name] specify target architecture\n" + " --target-environ [name] specify target environment\n" + " --target-os [name] specify target operating system\n" " --verbose-tokenize turn on compiler debug output for tokenization\n" " --verbose-ast turn on compiler debug output for parsing into an AST\n" " --verbose-link turn on compiler debug output for linking\n" " --verbose-ir turn on compiler debug output for Zig IR\n" " --verbose-llvm-ir turn on compiler debug output for LLVM IR\n" " --verbose-cimport turn on compiler debug output for C imports\n" - " --zig-install-prefix $path override directory where zig thinks it is installed\n" - " -dirafter $dir same as -isystem but do it last\n" - " -isystem $dir add additional search path for other .h files\n" - " -mllvm $arg additional arguments to forward to LLVM's option processing\n" + " --zig-install-prefix [path] override directory where zig thinks it is installed\n" + " -dirafter [dir] same as -isystem but do it last\n" + " -isystem [dir] add additional search path for other .h files\n" + " -mllvm [arg] additional arguments to forward to LLVM's option processing\n" "Link Options:\n" - " --ar-path $path set the path to ar\n" - " --dynamic-linker $path set the path to ld.so\n" + " --ar-path [path] set the path to ar\n" + " --dynamic-linker [path] set the path to ld.so\n" " --each-lib-rpath add rpath for each used dynamic library\n" - " --libc-lib-dir $path directory where libc crt1.o resides\n" - " --libc-static-lib-dir $path directory where libc crtbegin.o resides\n" - " --msvc-lib-dir $path (windows) directory where vcruntime.lib resides\n" - " --kernel32-lib-dir $path (windows) directory where kernel32.lib resides\n" - " --library $lib link against lib\n" - " --library-path $dir add a directory to the library search path\n" - " --linker-script $path use a custom linker script\n" - " --object $obj add object file to build\n" - " -L$dir alias for --library-path\n" + " --libc-lib-dir [path] directory where libc crt1.o resides\n" + " --libc-static-lib-dir [path] directory where libc crtbegin.o resides\n" + " --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides\n" + " --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides\n" + " --library [lib] link against lib\n" + " --library-path [dir] add a directory to the library search path\n" + " --linker-script [path] use a custom linker script\n" + " --object [obj] add object file to build\n" + " -L[dir] alias for --library-path\n" " -rdynamic add all symbols to the dynamic symbol table\n" - " -rpath $path add directory to the runtime library search path\n" + " -rpath [path] add directory to the runtime library search path\n" " -mconsole (windows) --subsystem console to the linker\n" " -mwindows (windows) --subsystem windows to the linker\n" - " -framework $name (darwin) link against framework\n" - " -mios-version-min $ver (darwin) set iOS deployment target\n" - " -mmacosx-version-min $ver (darwin) set Mac OS X deployment target\n" - " --ver-major $ver dynamic library semver major version\n" - " --ver-minor $ver dynamic library semver minor version\n" - " --ver-patch $ver dynamic library semver patch version\n" + " -framework [name] (darwin) link against framework\n" + " -mios-version-min [ver] (darwin) set iOS deployment target\n" + " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n" + " --ver-major [ver] dynamic library semver major version\n" + " --ver-minor [ver] dynamic library semver minor version\n" + " --ver-patch [ver] dynamic library semver patch version\n" "Test Options:\n" - " --test-filter $text skip tests that do not match filter\n" - " --test-name-prefix $text add prefix to all tests\n" - " --test-cmd $arg specify test execution command one arg at a time\n" + " --test-filter [text] skip tests that do not match filter\n" + " --test-name-prefix [text] add prefix to all tests\n" + " --test-cmd [arg] specify test execution command one arg at a time\n" " --test-cmd-bin appends test binary path to test cmd args\n" , arg0); return EXIT_FAILURE; @@ -401,8 +401,8 @@ int main(int argc, char **argv) { "\n" "General Options:\n" " --help Print this help and exit\n" - " --build-file $file Override path to build.zig\n" - " --cache-dir $path Override path to cache directory\n" + " --build-file [file] Override path to build.zig\n" + " --cache-dir [path] Override path to cache directory\n" " --verbose Print commands before executing them\n" " --verbose-tokenize Enable compiler debug output for tokenization\n" " --verbose-ast Enable compiler debug output for parsing into an AST\n" @@ -410,14 +410,14 @@ int main(int argc, char **argv) { " --verbose-ir Enable compiler debug output for Zig IR\n" " --verbose-llvm-ir Enable compiler debug output for LLVM IR\n" " --verbose-cimport Enable compiler debug output for C imports\n" - " --prefix $path Override default install prefix\n" + " --prefix [path] Override default install prefix\n" "\n" "Project-specific options become available when the build file is found.\n" "Run this command with no options to generate a build.zig template.\n" "\n" "Advanced Options:\n" - " --build-file $file Override path to build.zig\n" - " --cache-dir $path Override path to cache directory\n" + " --build-file [file] Override path to build.zig\n" + " --cache-dir [path] Override path to cache directory\n" " --verbose-tokenize Enable compiler debug output for tokenization\n" " --verbose-ast Enable compiler debug output for parsing into an AST\n" " --verbose-link Enable compiler debug output for linking\n" @@ -853,20 +853,22 @@ int main(int argc, char **argv) { ZigTarget *non_null_target = target ? target : &native; - Buf *test_exe_name = buf_sprintf("." OS_SEP "test%s", target_exe_file_ext(non_null_target)); + Buf *test_exe_name = buf_sprintf("test%s", target_exe_file_ext(non_null_target)); + Buf *test_exe_path = buf_alloc(); + os_path_join(full_cache_dir, test_exe_name, test_exe_path); for (size_t i = 0; i < test_exec_args.length; i += 1) { if (test_exec_args.items[i] == nullptr) { - test_exec_args.items[i] = buf_ptr(test_exe_name); + test_exec_args.items[i] = buf_ptr(test_exe_path); } } codegen_build(g); - codegen_link(g, buf_ptr(test_exe_name)); + codegen_link(g, buf_ptr(test_exe_path)); if (!target_can_exec(&native, target)) { fprintf(stderr, "Created %s but skipping execution because it is non-native.\n", - buf_ptr(test_exe_name)); + buf_ptr(test_exe_path)); return 0; } @@ -879,12 +881,12 @@ int main(int argc, char **argv) { 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_name), no_args, &term); + os_spawn_process(buf_ptr(test_exe_path), no_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_name)); + fprintf(stderr, "%s\n", buf_ptr(test_exe_path)); } else if (timing_info) { codegen_print_timing_report(g, stdout); } |
