From d90be54850bcd5d5aff17161fb51887187469a55 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 15 Apr 2021 14:55:36 +0300 Subject: [PATCH] v: add -cstrict for optionally turning on all ccoptions.wargs --- cmd/v/help/build-c.txt | 4 ++++ vlib/v/builder/cc.v | 13 ++++++++----- vlib/v/pref/pref.v | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmd/v/help/build-c.txt b/cmd/v/help/build-c.txt index ce432d6269..a2c0052def 100644 --- a/cmd/v/help/build-c.txt +++ b/cmd/v/help/build-c.txt @@ -16,6 +16,10 @@ see also `v help build`. Pass the provided flag as is to the C compiler. Can be specified multiple times to provide multiple flags. Use quotes to wrap the flag argument if it contains spaces. + + -cstrict + Turn on additional C warnings. This slows down compilation + slightly (~10-10% for gcc), but sometimes provides better diagnosis. -showcc Prints the C command that is used to build the program. diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 9090c64a20..6ff0eead8d 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -378,14 +378,17 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { } v.ccoptions = ccoptions // setup the cache too, so that different compilers/options do not interfere: - v.pref.cache_manager.set_temporary_options(ccoptions.thirdparty_object_args([ + v.pref.cache_manager.set_temporary_options(v.thirdparty_object_args(v.ccoptions, [ ccoptions.guessed_compiler, ])) } -fn (ccoptions CcompilerOptions) all_args() []string { +fn (v &Builder) all_args(ccoptions CcompilerOptions) []string { mut all := []string{} all << ccoptions.env_cflags + if v.pref.is_cstrict { + all << ccoptions.wargs + } all << ccoptions.args all << ccoptions.o_args all << ccoptions.pre_args @@ -396,7 +399,7 @@ fn (ccoptions CcompilerOptions) all_args() []string { return all } -fn (ccoptions CcompilerOptions) thirdparty_object_args(middle []string) []string { +fn (v &Builder) thirdparty_object_args(ccoptions CcompilerOptions, middle []string) []string { mut all := []string{} all << ccoptions.env_cflags all << ccoptions.args @@ -611,7 +614,7 @@ fn (mut v Builder) cc() { } } // - all_args := v.ccoptions.all_args() + all_args := v.all_args(v.ccoptions) v.dump_c_options(all_args) str_args := all_args.join(' ') // write args to response file @@ -953,7 +956,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF all_options << moduleflags.c_options_before_target() all_options << '-o "$opath"' all_options << '-c "$cfile"' - cc_options := v.ccoptions.thirdparty_object_args(all_options).join(' ') + cc_options := v.thirdparty_object_args(v.ccoptions, all_options).join(' ') cmd := '$v.pref.ccompiler $cc_options' $if trace_thirdparty_obj_files ? { println('>>> build_thirdparty_obj_files cmd: $cmd') diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 32505f2192..555931522b 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -166,6 +166,7 @@ pub mut: cache_manager vcache.CacheManager is_help bool // -h, -help or --help was passed gc_mode GarbageCollectionMode = .no_gc // .no_gc, .boehm, .boehm_leak, ... + is_cstrict bool // turn on more C warnings; slightly slower // checker settings: checker_match_exhaustive_cutoff_limit int = 10 } @@ -227,6 +228,9 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences '-silent' { res.output_mode = .silent } + '-cstrict' { + res.is_cstrict = true + } '-gc' { gc_mode := cmdline.option(current_args, '-gc', '') match gc_mode {