From c6412597abe24cdf099c9031ebdc47a3a263d141 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 29 Aug 2023 23:39:26 +0300 Subject: [PATCH] builder: add -fwrapv to fix UB overflow --- vlib/v/builder/cc.v | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index a820890c5d9975..ba7c6245465b09 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -206,6 +206,13 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { || ccoptions.guessed_compiler == 'msvc' ccoptions.is_cc_clang = ccompiler_file_name.contains('clang') || ccoptions.guessed_compiler == 'clang' + + // Add -fwrapv to handle UB overflows + if (ccoptions.is_cc_gcc || ccoptions.is_cc_clang || ccoptions.is_cc_tcc) + && v.pref.os in [.macos, .linux, .windows] { + ccoptions.args << '-fwrapv' + } + // For C++ we must be very tolerant if ccoptions.guessed_compiler.contains('++') { ccoptions.args << '-fpermissive'