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: I9dbec1d99353f8cbe6751d5241283ab19592dc27
This commit is contained in:
Trevor Radcliffe
2022-10-28 16:48:18 +00:00
parent c03724c442
commit f82482db31
6 changed files with 377 additions and 3 deletions

View File

@@ -1723,3 +1723,85 @@ cc_library_static {
},
})
}
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": ["ubsan_integer_overflow"],
"//conditions:default": [],
})`,
"local_includes": `["."]`,
}),
},
})
}