From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 23 Aug 2017 20:28:03 -0400 Subject: [PATCH] use -fwrapv when signed overflow checking is off Signed-off-by: anupritaisno1 --- cc/cc.go | 2 ++ cc/sanitize.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/cc/cc.go b/cc/cc.go index 619acf96b..02ec906a0 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1710,6 +1710,8 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { } if c.sanitize != nil { flags = c.sanitize.flags(ctx, flags) + } else { + flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv") } if c.coverage != nil { flags, deps = c.coverage.flags(ctx, flags, deps) diff --git a/cc/sanitize.go b/cc/sanitize.go index 941a955e5..694a3659f 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -556,9 +556,21 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { } if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep { + flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv") return flags } + wrapv := true + for _, element := range sanitize.Properties.Sanitizers { + if (element == "signed-integer-overflow" || element == "integer" || element == "undefined") { + wrapv = false + break + } + } + if wrapv { + flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv") + } + if Bool(sanitize.Properties.Sanitize.Address) { if ctx.Arch().ArchType == android.Arm { // Frame pointer based unwinder in ASan requires ARM frame setup.