bp2build conversion for Sanitize.Integer_overflow
and Sanitize.Misc_undefined.
This is a redo of aosp/2277186 with changes to account for issues
in mixed builds. Specifically, for now we're disabling mixed builds
for modules that use ubsan. This bug tracks enabling it:
b/261058727.
Bug: 253428057
Test: Unit tests
Change-Id: Ia1277a7fa9a82f40998d7f3d2c40ea90f38201e7
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 8aa2c3e..fe156df 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -789,3 +789,82 @@
},
})
}
+
+func TestCcBinaryWithIntegerOverflowProperty(t *testing.T) {
+ runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
+ description: "cc_binary with integer overflow property specified",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ sanitize: {
+ integer_overflow: true,
+ },
+}`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "features": `["ubsan_integer_overflow"]`,
+ }},
+ },
+ })
+}
+
+func TestCcBinaryWithMiscUndefinedProperty(t *testing.T) {
+ runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
+ description: "cc_binary with miscellaneous properties specified",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+}`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ]`,
+ }},
+ },
+ })
+}
+
+func TestCcBinaryWithUBSanPropertiesArchSpecific(t *testing.T) {
+ runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
+ description: "cc_binary has correct feature select when UBSan props are specified in arch specific blocks",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+ target: {
+ android: {
+ sanitize: {
+ misc_undefined: ["alignment"],
+ },
+ },
+ linux_glibc: {
+ sanitize: {
+ integer_overflow: true,
+ },
+ },
+ },
+}`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "local_includes": `["."]`,
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ] + select({
+ "//build/bazel/platforms/os:android": ["ubsan_alignment"],
+ "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
+ "//conditions:default": [],
+ })`,
+ }},
+ },
+ })
+}
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 595ee63..f924d00 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -3908,3 +3908,113 @@
},
)
}
+
+func TestCcLibraryWithIntegerOverflowProperty(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library has correct features when integer_overflow property is provided",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `
+cc_library {
+ name: "foo",
+ sanitize: {
+ integer_overflow: true,
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "features": `["ubsan_integer_overflow"]`,
+ "local_includes": `["."]`,
+ }),
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "features": `["ubsan_integer_overflow"]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
+
+func TestCcLibraryWithMiscUndefinedProperty(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library has correct features when misc_undefined property is provided",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `
+cc_library {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ]`,
+ "local_includes": `["."]`,
+ }),
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
+
+func TestCcLibraryWithUBSanPropertiesArchSpecific(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library has correct feature select when UBSan props are specified in arch specific blocks",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `
+cc_library {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+ target: {
+ android: {
+ sanitize: {
+ misc_undefined: ["alignment"],
+ },
+ },
+ linux_glibc: {
+ sanitize: {
+ integer_overflow: true,
+ },
+ },
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ] + select({
+ "//build/bazel/platforms/os:android": ["ubsan_alignment"],
+ "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ }),
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ] + select({
+ "//build/bazel/platforms/os:android": ["ubsan_alignment"],
+ "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go
index 14b6f0d..017df6f 100644
--- a/bp2build/cc_library_shared_conversion_test.go
+++ b/bp2build/cc_library_shared_conversion_test.go
@@ -885,3 +885,85 @@
},
})
}
+
+func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_shared has correct features when integer_overflow property is provided",
+ Blueprint: `
+cc_library_shared {
+ name: "foo",
+ sanitize: {
+ integer_overflow: true,
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "features": `["ubsan_integer_overflow"]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
+
+func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_shared has correct features when misc_undefined property is provided",
+ Blueprint: `
+cc_library_shared {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
+
+func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
+ runCcLibrarySharedTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
+ Blueprint: `
+cc_library_shared {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+ target: {
+ android: {
+ sanitize: {
+ misc_undefined: ["alignment"],
+ },
+ },
+ linux_glibc: {
+ sanitize: {
+ integer_overflow: true,
+ },
+ },
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ] + select({
+ "//build/bazel/platforms/os:android": ["ubsan_alignment"],
+ "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index b47d1f1..5a1260f 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1723,3 +1723,85 @@
},
})
}
+
+func TestCcLibraryStaticWithIntegerOverflowProperty(t *testing.T) {
+ runCcLibraryStaticTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_static has correct features when integer_overflow property is provided",
+ Blueprint: `
+cc_library_static {
+ name: "foo",
+ sanitize: {
+ integer_overflow: true,
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
+ "features": `["ubsan_integer_overflow"]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
+
+func TestCcLibraryStaticWithMiscUndefinedProperty(t *testing.T) {
+ runCcLibraryStaticTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_static has correct features when misc_undefined property is provided",
+ Blueprint: `
+cc_library_static {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ]`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}
+
+func TestCcLibraryStaticWithUBSanPropertiesArchSpecific(t *testing.T) {
+ runCcLibraryStaticTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_static has correct feature select when UBSan props are specified in arch specific blocks",
+ Blueprint: `
+cc_library_static {
+ name: "foo",
+ sanitize: {
+ misc_undefined: ["undefined", "nullability"],
+ },
+ target: {
+ android: {
+ sanitize: {
+ misc_undefined: ["alignment"],
+ },
+ },
+ linux_glibc: {
+ sanitize: {
+ integer_overflow: true,
+ },
+ },
+ },
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
+ "features": `[
+ "ubsan_undefined",
+ "ubsan_nullability",
+ ] + select({
+ "//build/bazel/platforms/os:android": ["ubsan_alignment"],
+ "//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ }),
+ },
+ })
+}