Skip to content

Commit

Permalink
all: fix remaining c warnings and add -Werror to CI (#7021)
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-weihe authored Nov 29, 2020
1 parent 5eb7660 commit 9367dcd
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
echo $VFLAGS
sudo ln -s $PWD/thirdparty/tcc/tcc.exe /usr/local/bin/tcc ## TODO: remove
make -j4
./v -cg -o v cmd/v
./v -cg -cflags -Werror -o v cmd/v
- name: Test v->c
run: |
thirdparty/tcc/tcc.exe -version
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
## brew install sdl2 sdl2_ttf sdl2_mixer sdl2_image
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/"
- name: Build V
run: make -j4 && ./v -o v cmd/v
run: make -j4 && ./v -cg -cflags -Werror -o v cmd/v
- name: Build V using V
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v
- name: Test symlink
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
sudo apt-get install --quiet -y libglfw3 libglfw3-dev libfreetype6-dev libxi-dev libxcursor-dev libasound2-dev
## sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev
- name: Build V
run: make -j4 && ./v -cc gcc -o v cmd/v
run: make -j4 && ./v -cc gcc -cg -cflags -Werror -o v cmd/v
# - name: Test V
# run: ./v -silent test-compiler
# - name: Test v binaries
Expand Down Expand Up @@ -357,7 +357,7 @@ jobs:
gcc --version
.\make.bat -gcc
- name: Test new v.c
run: .\v.exe -o v.c cmd/v && gcc -municode -w v.c
run: .\v.exe -o v.c cmd/v && gcc -Werror -municode -w v.c
- name: Install dependencies
run: |
.\v.exe setup-freetype
Expand Down Expand Up @@ -392,6 +392,7 @@ jobs:
echo %VFLAGS%
echo $VFLAGS
.\make.bat -msvc
.\v.exe -cflags /WX self
- name: Install dependencies
run: |
.\v.exe setup-freetype
Expand Down Expand Up @@ -433,7 +434,7 @@ jobs:
move "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe.old"
.\make.bat
- name: Test new v.c
run: .\v.exe -o v.c cmd/v && .\thirdparty\tcc\tcc.exe -w -ladvapi32 -bt10 v.c
run: .\v.exe -o v.c cmd/v && .\thirdparty\tcc\tcc.exe -Werror -w -ladvapi32 -bt10 v.c
- name: Install dependencies
run: |
.\v.exe setup-freetype
Expand Down
4 changes: 2 additions & 2 deletions vlib/builtin/builtin_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn print_backtrace_skipping_top_frames(xskipframes int) bool {
// so there is no need to have their twins in builtin_windows.v
fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
$if macos {
buffer := [100]byteptr{}
buffer := [100]voidptr{}
nr_ptrs := C.backtrace(buffer, 100)
if nr_ptrs < 2 {
eprintln('C.backtrace returned less than 2 frames')
Expand All @@ -61,7 +61,7 @@ fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {

fn print_backtrace_skipping_top_frames_freebsd(skipframes int) bool {
$if freebsd {
buffer := [100]byteptr{}
buffer := [100]voidptr{}
nr_ptrs := C.backtrace(buffer, 100)
if nr_ptrs < 2 {
eprintln('C.backtrace returned less than 2 frames')
Expand Down
8 changes: 4 additions & 4 deletions vlib/os/process_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ fn (mut p Process) unix_spawn_process() int {
}
mut cargv := []charptr{}
mut cenvs := []charptr{}
cargv << p.filename.str
cargv << charptr(p.filename.str)
for i in 0 .. p.args.len {
cargv << p.args[i].str
cargv << charptr(p.args[i].str)
}
for i in 0 .. p.env.len {
cenvs << p.env[i].str
cenvs << charptr(p.env[i].str)
}
cargv << charptr(0)
cenvs << charptr(0)
C.execve(p.filename.str, cargv.data, cenvs.data)
C.execve(charptr(p.filename.str), cargv.data, cenvs.data)
// NB: normally execve does not return at all.
// If it returns, then something went wrong...
eprintln(posix_get_error_msg(C.errno))
Expand Down
4 changes: 2 additions & 2 deletions vlib/time/time_darwin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ pub struct C.timeval {
tv_usec u64
}

fn init_time_base() InternalTimeBase {
fn init_time_base() C.mach_timebase_info_data_t {
tb := C.mach_timebase_info_data_t{}
C.mach_timebase_info(&tb)
return InternalTimeBase{numer:tb.numer, denom:tb.denom}
return C.mach_timebase_info_data_t{numer:tb.numer, denom:tb.denom}
}

fn sys_mono_now_darwin() u64 {
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/builder/cc.v
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fn (mut v Builder) cc() {
//
if is_cc_clang {
if debug_mode {
debug_options = '-g3 -O0 -no-pie'
debug_options = '-g3 -O0'
}
optimization_options = '-O3'
mut have_flto := true
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/gen/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -1191,15 +1191,15 @@ fn (mut g Gen) for_in(it ast.ForInStmt) {
g.writeln(' = (*$atmp)[$i];')
}
} else if it.kind == .map {
// `for key, val in map {`
// `for key, val in map {
g.writeln('// FOR IN map')
idx := g.new_tmp_var()
atmp := g.new_tmp_var()
atmp_styp := g.typ(it.cond_type)
g.write('$atmp_styp $atmp = ')
g.expr(it.cond)
g.writeln(';')
g.writeln('for (int $idx = 0; $idx < ${atmp}.key_values.len; ++$idx) {')
g.writeln('for (int $idx = 0; $idx < (int)${atmp}.key_values.len; ++$idx) {')
g.writeln('\tif (${atmp}.key_values.keys[$idx].str == 0) {continue;}')
if it.key_var != '_' {
key_styp := g.typ(it.key_type)
Expand Down
8 changes: 4 additions & 4 deletions vlib/v/parser/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ fn (mut p Parser) hash() ast.HashStmt {
val := p.tok.lit
kind := val.all_before(' ')
p.next()
mut main := ''
mut main_str := ''
mut msg := ''
content := val.all_after('$kind ').all_before('//')
if content.contains(' #') {
main = content.all_before(' #').trim_space()
main_str = content.all_before(' #').trim_space()
msg = content.all_after(' #').trim_space()
} else {
main = content.trim_space()
main_str = content.trim_space()
msg = ''
}
// p.trace('a.v', 'kind: ${kind:-10s} | pos: ${pos:-45s} | hash: $val')
return ast.HashStmt{
mod: p.mod
val: val
kind: kind
main: main
main: main_str
msg: msg
pos: pos
}
Expand Down
1 change: 1 addition & 0 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
field_name: field_name
pos: name_pos
is_mut: is_mut
mut_pos: mut_pos
}
mut node := ast.Expr{}
node = sel_expr
Expand Down

0 comments on commit 9367dcd

Please sign in to comment.