From 7f18e67e1b577a50402e8b43508ab2311a5c45b5 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Fri, 17 Sep 2010 18:29:54 +0000 Subject: Add a -ftrapv-handler= option which allows a handler to invoke instead of simply aborting when a signed operation overflows. This mirrors the (GCC-incompatible) behaviour from clang 1.0 and 1.1 when -ftrapv was specified, but allows the handler to be defined for each compilation unit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114192 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CompilerInvocation.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/Frontend/CompilerInvocation.cpp') diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 64ac3bad8c..d793fc01be 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -581,7 +581,12 @@ static void LangOptsToArgs(const LangOptions &Opts, switch (Opts.getSignedOverflowBehavior()) { case LangOptions::SOB_Undefined: break; case LangOptions::SOB_Defined: Res.push_back("-fwrapv"); break; - case LangOptions::SOB_Trapping: Res.push_back("-ftrapv"); break; + case LangOptions::SOB_Trapping: + Res.push_back("-ftrapv"); break; + if (!Opts.OverflowHandler.empty()) { + Res.push_back("-ftrapv-handler"); + Res.push_back(Opts.OverflowHandler); + } } if (Opts.HeinousExtensions) Res.push_back("-fheinous-gnu-extensions"); @@ -1312,8 +1317,12 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, if (Args.hasArg(OPT_fvisibility_inlines_hidden)) Opts.InlineVisibilityHidden = 1; - if (Args.hasArg(OPT_ftrapv)) + if (Args.hasArg(OPT_ftrapv)) { Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping); + // Set the handler, if one is specified. + Opts.OverflowHandler = + Args.getLastArgValue(OPT_ftrapv_handler); + } else if (Args.hasArg(OPT_fwrapv)) Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined); -- cgit v1.2.3-18-g5258