From 5adb5a84bfb4f2e5f1ea28fdfc6ee1cd9b622c60 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 27 Mar 2011 00:04:55 +0000 Subject: [PATCH] Add -f[no-]strict-overflow to the Clang driver. Use it to set the default for -fwrapv if that flag isn't specified explicitly. We always prefer an explict setting of -fwrapv when present. Also adds support for -fno-wrapv to allow disabling -fwrapv even when -fno-strict-overflow is passed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128353 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 3 +++ lib/Driver/Tools.cpp | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index f5e92022c3..6cd5645cdf 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -355,12 +355,14 @@ def fno_show_source_location : Flag<"-fno-show-source-location">, Group def fno_spell_checking : Flag<"-fno-spell-checking">, Group; def fno_stack_protector : Flag<"-fno-stack-protector">, Group; def fno_strict_aliasing : Flag<"-fno-strict-aliasing">, Group; +def fno_strict_overflow : Flag<"-fno-strict-overflow">, Group; def fno_threadsafe_statics : Flag<"-fno-threadsafe-statics">, Group; def fno_use_cxa_atexit : Flag<"-fno-use-cxa-atexit">, Group; def fno_unit_at_a_time : Flag<"-fno-unit-at-a-time">, Group; def fno_unwind_tables : Flag<"-fno-unwind-tables">, Group; def fno_verbose_asm : Flag<"-fno-verbose-asm">, Group; def fno_working_directory : Flag<"-fno-working-directory">, Group; +def fno_wrapv : Flag<"-fno-wrapv">, Group; def fno_zero_initialized_in_bss : Flag<"-fno-zero-initialized-in-bss">, Group; def fobjc_atdefs : Flag<"-fobjc-atdefs">, Group; def fobjc_call_cxx_cdtors : Flag<"-fobjc-call-cxx-cdtors">, Group; @@ -408,6 +410,7 @@ def fsigned_char : Flag<"-fsigned-char">, Group; def fstack_protector_all : Flag<"-fstack-protector-all">, Group; def fstack_protector : Flag<"-fstack-protector">, Group; def fstrict_aliasing : Flag<"-fstrict-aliasing">, Group; +def fstrict_overflow : Flag<"-fstrict-overflow">, Group; def fsyntax_only : Flag<"-fsyntax-only">, Flags<[DriverOption]>; def ftabstop_EQ : Joined<"-ftabstop=">, Group; def ferror_limit_EQ : Joined<"-ferror-limit=">, Group; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index beaeade836..81585c8567 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1448,7 +1448,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(A->getValue(Args)); } - Args.AddLastArg(CmdArgs, options::OPT_fwrapv); + // -fno-strict-overflow implies -fwrapv if it isn't disabled, but + // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. + if (Arg *A = Args.getLastArg(options::OPT_fwrapv, + options::OPT_fno_wrapv)) { + if (A->getOption().matches(options::OPT_fwrapv)) + CmdArgs.push_back("-fwrapv"); + } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow, + options::OPT_fno_strict_overflow)) { + if (A->getOption().matches(options::OPT_fno_strict_overflow)) + CmdArgs.push_back("-fwrapv"); + } Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); Args.AddLastArg(CmdArgs, options::OPT_funroll_loops); -- 2.50.1