ci: fix sanitizers and add -fsanitize=undefined (#7306)

pull/7285/head
ka-weihe 2020-12-14 06:34:47 +01:00 committed by GitHub
parent 9b139c58ca
commit f57c7032b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View File

@ -156,6 +156,10 @@ jobs:
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/"
- name: Build V
run: make -j4 && ./v -cg -cflags -Werror -o v cmd/v
- name: Run sanitizers
run: |
./v -o v2 cmd/v -cflags -fsanitize=undefined
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v
- name: Build V using V
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v
- name: v self with -usecache
@ -221,6 +225,12 @@ jobs:
run: make -j4 && ./v -cc gcc -cg -cflags -Werror -o v cmd/v
- name: Valgrind
run: valgrind --error-exitcode=1 ./v -o v.c cmd/v
- name: Run sanitizers
run: |
./v -o v2 cmd/v -cflags -fsanitize=thread
./v -o v3 cmd/v -cflags "-fsanitize=undefined -fno-sanitize=alignment"
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
# - name: Test V
# run: ./v -silent test-compiler
# - name: Test v binaries
@ -310,8 +320,12 @@ jobs:
run: valgrind --error-exitcode=1 ./v -o v.c cmd/v
- name: Run sanitizers
run: |
./v -o v2 cmd/v -cflags -fsanitize=memory && ./v2 -o v.c cmd/v
./v -o v2 cmd/v -cflags -fsanitize=thread && ./v2 -o v.c cmd/v
./v -o v2 cmd/v -cflags -fsanitize=memory
./v -o v3 cmd/v -cflags -fsanitize=thread
./v -o v4 cmd/v -cflags -fsanitize=undefined
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
- name: v self compilation
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
- name: v self with -usecache

View File

@ -338,7 +338,9 @@ pub fn (a &array) clone() array {
unsafe {arr.set_unsafe(i, &ar_clone)}
}
} else {
unsafe {C.memcpy(byteptr(arr.data), a.data, a.cap * a.element_size)}
if !isnil(a.data) {
unsafe {C.memcpy(byteptr(arr.data), a.data, a.cap * a.element_size)}
}
}
return arr
}
@ -396,7 +398,7 @@ fn (mut a array) push(val voidptr) {
// `val` is array.data
// TODO make private, right now it's used by strings.Builder
pub fn (mut a3 array) push_many(val voidptr, size int) {
if a3.data == val {
if a3.data == val && !isnil(a3.data) {
// handle `arr << arr`
copy := a3.clone()
a3.ensure_cap(a3.len + size)
@ -406,7 +408,9 @@ pub fn (mut a3 array) push_many(val voidptr, size int) {
}
} else {
a3.ensure_cap(a3.len + size)
unsafe {C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size)}
if !isnil(a3.data) && !isnil(val) {
unsafe {C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size)}
}
}
a3.len += size
}

View File

@ -356,7 +356,7 @@ fn converter(mut pn PrepNumber) u64 {
mut r2 := u32(0) // 96-bit precision integer
mut r1 := u32(0)
mut r0 := u32(0)
mask28 := u32(0xF<<28)
mask28 := u32(u64(0xF)<<28)
mut result := u64(0)
// working on 3 u32 to have 96 bit precision
s0 = u32(pn.mantissa & u64(0x00000000FFFFFFFF))