Enable -fwrapv by default with clang to treat signed integer overflows
authorjsg <jsg@openbsd.org>
Tue, 6 Jun 2017 09:40:24 +0000 (09:40 +0000)
committerjsg <jsg@openbsd.org>
Tue, 6 Jun 2017 09:40:24 +0000 (09:40 +0000)
as defined.  This is done to prevent dangerous optimisations which could
remove security critical overflow checks.

Base gcc has -fno-strict-overflow by default, with clang this is
identical to -fwrapv.

Prompted by naddy@ discovering a hang with a clang compiled i386 kernel
that was resolved with -fwrapv.

ok kettenis@ pascal@

gnu/llvm/tools/clang/lib/Driver/Tools.cpp

index bd736c8..5eeb81f 100644 (file)
@@ -5466,7 +5466,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                                       options::OPT_fno_strict_overflow)) {
     if (A->getOption().matches(options::OPT_fno_strict_overflow))
       CmdArgs.push_back("-fwrapv");
-  }
+  } else if (getToolChain().getTriple().isOSOpenBSD())
+      CmdArgs.push_back("-fwrapv");
 
   if (Arg *A = Args.getLastArg(options::OPT_freroll_loops,
                                options::OPT_fno_reroll_loops))