2024-05-20 08:00:14 -04:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Daniel Micay <danielmicay@gmail.com>
|
|
|
|
Date: Wed, 23 Aug 2017 20:28:03 -0400
|
|
|
|
Subject: [PATCH] use -fwrapv when signed overflow checking is off
|
|
|
|
|
|
|
|
13: 62bea80ab9189b81a8728b71b284b7afba9d5969
|
|
|
|
---
|
|
|
|
cc/cc.go | 2 ++
|
|
|
|
cc/cc_test.go | 2 +-
|
|
|
|
cc/sanitize.go | 14 ++++++++++++++
|
|
|
|
3 files changed, 17 insertions(+), 1 deletion(-)
|
|
|
|
|
|
|
|
diff --git a/cc/cc.go b/cc/cc.go
|
2024-12-05 13:51:51 -05:00
|
|
|
index b3f0bfadb..ccbc44a56 100644
|
2024-05-20 08:00:14 -04:00
|
|
|
--- a/cc/cc.go
|
|
|
|
+++ b/cc/cc.go
|
2024-12-05 13:51:51 -05:00
|
|
|
@@ -2079,6 +2079,8 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
2024-05-20 08:00:14 -04:00
|
|
|
}
|
|
|
|
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/cc_test.go b/cc/cc_test.go
|
2024-12-05 13:51:51 -05:00
|
|
|
index 6cc500b5f..59f45403a 100644
|
2024-05-20 08:00:14 -04:00
|
|
|
--- a/cc/cc_test.go
|
|
|
|
+++ b/cc/cc_test.go
|
2024-12-05 13:51:51 -05:00
|
|
|
@@ -4439,7 +4439,7 @@ func TestIncludeDirectoryOrdering(t *testing.T) {
|
2024-05-20 08:00:14 -04:00
|
|
|
conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"}
|
|
|
|
cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"}
|
|
|
|
|
|
|
|
- cflags := []string{"-Werror", "-std=candcpp"}
|
|
|
|
+ cflags := []string{"-Werror", "-std=candcpp", "-fwrapv"}
|
|
|
|
cstd := []string{"-std=gnu17", "-std=conly"}
|
|
|
|
cppstd := []string{"-std=gnu++20", "-std=cpp", "-fno-rtti"}
|
|
|
|
|
|
|
|
diff --git a/cc/sanitize.go b/cc/sanitize.go
|
2024-12-05 13:51:51 -05:00
|
|
|
index 52b5be9e6..91e953090 100644
|
2024-05-20 08:00:14 -04:00
|
|
|
--- a/cc/sanitize.go
|
|
|
|
+++ b/cc/sanitize.go
|
|
|
|
@@ -787,8 +787,22 @@ func toDisableUnsignedShiftBaseChange(flags []string) bool {
|
|
|
|
|
|
|
|
func (s *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
if !s.Properties.SanitizerEnabled && !s.Properties.UbsanRuntimeDep {
|
|
|
|
+ flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv")
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ wrapv := true
|
|
|
|
+ for _, san := range s.Properties.Sanitizers {
|
|
|
|
+ if san == "signed-integer-overflow" || san == "integer" || san == "undefined" {
|
|
|
|
+ wrapv = false
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if wrapv {
|
|
|
|
+ flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
sanProps := &s.Properties.SanitizeMutated
|
|
|
|
|
|
|
|
if Bool(sanProps.Address) {
|