From 75d65a005ea190606296e980846c4cad582add41 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 21 Aug 2024 13:18:21 +0300 Subject: [PATCH] ci, checker, pref: extract .github/workflows/run_sanitizers.sh to ease local testing with different options --- .github/workflows/linux_ci.yml | 10 +------- .github/workflows/run_sanitizers.sh | 25 +++++++++++++++++++ .../run_sanitizers_thread.suppressions | 5 ++++ .../run_sanitizers_undefined.suppressions | 4 +++ vlib/v/checker/fn.v | 5 ++-- vlib/v/pref/pref.v | 2 +- 6 files changed, 39 insertions(+), 12 deletions(-) create mode 100755 .github/workflows/run_sanitizers.sh create mode 100644 .github/workflows/run_sanitizers_thread.suppressions create mode 100644 .github/workflows/run_sanitizers_undefined.suppressions diff --git a/.github/workflows/linux_ci.yml b/.github/workflows/linux_ci.yml index c02e945a8..18b476a66 100644 --- a/.github/workflows/linux_ci.yml +++ b/.github/workflows/linux_ci.yml @@ -244,15 +244,7 @@ jobs: - name: Valgrind run: valgrind --error-exitcode=1 v -o v.c cmd/v - name: Run sanitizers - run: | - v -o v2 cmd/v -cflags -fsanitize=memory - v -o v3 cmd/v -cflags -fsanitize=thread - v -o v4 cmd/v -cflags -fsanitize=undefined - v -o v5 cmd/v -cflags -fsanitize=address,pointer-compare,pointer-subtract - UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v - UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v - UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v4 -o v.c cmd/v - ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v5 -o v.c cmd/v + run: .github/workflows/run_sanitizers.sh - name: v self compilation run: v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v - name: v self compilation with -usecache diff --git a/.github/workflows/run_sanitizers.sh b/.github/workflows/run_sanitizers.sh new file mode 100755 index 000000000..eb25a2e45 --- /dev/null +++ b/.github/workflows/run_sanitizers.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +export PS4='\033[0;33m+ >>>>> (${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }\033[0m' + +set -xe + +echo " Setup environment ..." +export DEBUG_OPTS=${DEBUG_OPTS:-"-keepc -cg -cflags -fno-omit-frame-pointer"} +export VFLAGS=${VFLAGS:-"-cc clang"} +v version +v -show-c-output -cflags --version -e ';' || true + +echo " Compile and run sanitizers ..." + +v ${VFLAGS} ${DEBUG_OPTS} -o v2 cmd/v -cflags -fsanitize=memory +UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1" ./v2 -o v.c cmd/v + +v ${VFLAGS} ${DEBUG_OPTS} -o v3 cmd/v -cflags -fsanitize=thread +TSAN_OPTIONS="suppressions=.github/workflows/run_sanitizers_thread.suppressions" UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1" ./v3 -o v.c cmd/v + +v ${VFLAGS} ${DEBUG_OPTS} -o v4 cmd/v -cflags -fsanitize=undefined +UBSAN_OPTIONS="suppressions=.github/workflows/run_sanitizers_undefined.suppressions:print_stacktrace=1:halt_on_error=1" ./v4 -o v.c cmd/v + +v ${VFLAGS} ${DEBUG_OPTS} -o v5 cmd/v -cflags -fsanitize=address,pointer-compare,pointer-subtract +ASAN_OPTIONS="detect_leaks=0" UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1" ./v5 -o v.c cmd/v diff --git a/.github/workflows/run_sanitizers_thread.suppressions b/.github/workflows/run_sanitizers_thread.suppressions new file mode 100644 index 000000000..8fe73636a --- /dev/null +++ b/.github/workflows/run_sanitizers_thread.suppressions @@ -0,0 +1,5 @@ +## See https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions +## and https://clang.llvm.org/docs/ThreadSanitizer.html +## The sync__stdatomic__add_i64 and sync__stdatomic__sub_i64 suppressions below, are needed for clang-10 to clang-12; clang-18 is fine without them +race:sync__stdatomic__add_i64 +race:sync__stdatomic__sub_i64 diff --git a/.github/workflows/run_sanitizers_undefined.suppressions b/.github/workflows/run_sanitizers_undefined.suppressions new file mode 100644 index 000000000..4878ccd91 --- /dev/null +++ b/.github/workflows/run_sanitizers_undefined.suppressions @@ -0,0 +1,4 @@ +## See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html +function:rand__internal_ulid_at_millisecond +function:sync__pool__process_in_thread +function:rand__deinit diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 9d7b5644a..937db9f11 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -2111,8 +2111,9 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { has_method = true mut embed_types := []ast.Type{} method, embed_types = c.table.find_method_from_embeds(final_left_sym, method_name) or { - if err.msg() != '' { - c.error(err.msg(), node.pos) + emsg := err.str() + if emsg != '' { + c.error(emsg, node.pos) } has_method = false ast.Fn{}, []ast.Type{} diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index ffeb2f60f..682f88577 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -285,7 +285,7 @@ fn run_code_in_tmp_vfile_and_exit(args []string, mut res Preferences, option_nam panic('Failed to create temporary file ${tmp_v_file_path}') } run_options := cmdline.options_before(args, [option_name]).join(' ') - command_options := cmdline.options_after(args, [option_name])[1..].join(' ') + command_options := cmdline.options_after(args, [option_name])#[1..].join(' ') vexe := vexe_path() tmp_cmd := '${os.quoted_path(vexe)} ${output_option} ${run_options} run ${os.quoted_path(tmp_v_file_path)} ${command_options}' -- 2.39.5