Skip to content

Commit

Permalink
cgen: generate pragmas for gcc-14, to make it more relaxed by default…
Browse files Browse the repository at this point in the history
…. Support `-no-relaxed-gcc14` for turning them off. (#21680)
  • Loading branch information
spytheman authored Jun 15, 2024
1 parent add1621 commit 63353ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,17 @@ pub fn (mut g Gen) init() {
g.cheaders.writeln(g.pref.custom_prelude)
} else if !g.pref.no_preludes {
g.cheaders.writeln('// Generated by the V compiler')
if g.pref.relaxed_gcc14 {
// See https://gcc.gnu.org/gcc-14/porting_to.html#c-code-generators:
g.cheaders.writeln('
#if defined __GNUC__ && __GNUC__ >= 14
#pragma GCC diagnostic warning "-Wimplicit-function-declaration"
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#pragma GCC diagnostic warning "-Wint-conversion"
#pragma GCC diagnostic warning "-Wreturn-mismatch"
#endif
')
}
if g.pref.os == .wasm32 {
g.cheaders.writeln('#define VWASM 1')
// Include <stdint.h> instead of <inttypes.h> for WASM target
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ pub mut:
warn_about_allocs bool // -warn-about-allocs warngs about every single allocation, e.g. 'hi $name'. Mostly for low level development where manual memory management is used.
// temp
// use_64_int bool
// forwards compatibility settings:
relaxed_gcc14 bool = true // turn on the generated pragmas, that make gcc versions > 14 a lot less pedantic. The default is to have those pragmas in the generated C output, so that gcc-14 can be used on Arch etc.
}

pub struct LineInfo {
Expand Down Expand Up @@ -609,6 +611,9 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.no_preludes = true
res.build_options << arg
}
'-no-relaxed-gcc14' {
res.relaxed_gcc14 = false
}
'-prof', '-profile' {
res.profile_file = cmdline.option(args[i..], arg, '-')
res.is_prof = true
Expand Down

0 comments on commit 63353ba

Please sign in to comment.