Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Sources/SWBUniversalPlatform/Specs/Clang.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,44 @@
};
// Hidden.
},
{
Name = "CLANG_BOUNDS_SAFETY_BRINGUP_MISSING_CHECKS";
Type = Enumeration;
FileTypes = (
"sourcecode.c.c",
);
Values = (
"none",
"default",
);
DefaultValue = "default";
CommandLineArgs = {
"none" = ( "-fno-bounds-safety-bringup-missing-checks" );
// Use the compiler default
"default" = ();
// E.g. `batch_0` or `all` or comma separated lists of checks to enable
"<<otherwise>>" = ( "-fbounds-safety-bringup-missing-checks=$(value)" );
};

Condition = "$(CLANG_ENABLE_BOUNDS_ATTRIBUTES) || $(CLANG_ENABLE_BOUNDS_SAFETY)";
// Hidden
},
{
Name = "CLANG_BOUNDS_SAFETY_BRINGUP_MISSING_CHECKS_OPT_OUTS";
Type = String;
FileTypes = (
"sourcecode.c.c",
);
DefaultValue = "";
CommandLineArgs = {
"" = ();
// Comma separated list of checks to disable
"<<otherwise>>" = ( "-fno-bounds-safety-bringup-missing-checks=$(value)" );
};
Condition = "$(CLANG_ENABLE_BOUNDS_ATTRIBUTES) || $(CLANG_ENABLE_BOUNDS_SAFETY)";
AppearsAfter = "CLANG_BOUNDS_SAFETY_BRINGUP_MISSING_CHECKS";
// Hidden
},
{
Name = "CLANG_ENABLE_APP_EXTENSION";
Type = Boolean;
Expand Down
66 changes: 66 additions & 0 deletions Tests/SWBTaskConstructionTests/TaskConstructionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9185,6 +9185,72 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
}
}
}

// Test missing check build settings
let boundsSafetyMissingChecksSetting = "CLANG_BOUNDS_SAFETY_BRINGUP_MISSING_CHECKS"
let enableBoundsAttributesSetting = "CLANG_ENABLE_BOUNDS_ATTRIBUTES"
let boundsSafetyMissingChecksOptOutsSetting = "CLANG_BOUNDS_SAFETY_BRINGUP_MISSING_CHECKS_OPT_OUTS"

for (enableBoundsSafetyBuildSetting, enableBoundsSafetyFlag) in [
(enableBoundsSafetySetting,"-fbounds-safety"),
(enableBoundsAttributesSetting, "-fbounds-attributes")] {

// Maps an array of build overrides to a closure that tests properties of the build overrides
let missingChecksOverrides = [
[ enableBoundsSafetyBuildSetting: "YES", boundsSafetyMissingChecksSetting: "none"]: { (task: any PlannedTask) in
task.checkCommandLineContains(["-fno-bounds-safety-bringup-missing-checks"])
},

// Default behavior is not pass the compiler flag and thus use the compiler default
[ enableBoundsSafetyBuildSetting: "YES", boundsSafetyMissingChecksSetting: "default"]: { (task: any PlannedTask) in
task.checkCommandLineDoesNotContain("-fno-bounds-safety-bringup-missing-checks")
task.checkCommandLineDoesNotContain("-fbounds-safety-bringup-missing-checks")
},
[ enableBoundsSafetyBuildSetting: "YES"]: { (task: any PlannedTask) in
task.checkCommandLineDoesNotContain("-fno-bounds-safety-bringup-missing-checks")
task.checkCommandLineDoesNotContain("-fbounds-safety-bringup-missing-checks")
},


[ enableBoundsSafetyBuildSetting: "YES", boundsSafetyMissingChecksSetting: "batch_0"]: { (task: any PlannedTask) in
task.checkCommandLineContains(["-fbounds-safety-bringup-missing-checks=batch_0"])
task.checkCommandLineDoesNotContain("-fno-bounds-safety-bringup-missing-checks")
},
[ enableBoundsSafetyBuildSetting: "YES", boundsSafetyMissingChecksSetting: "access_size,return_size"]: { (task: any PlannedTask) in
task.checkCommandLineContains(["-fbounds-safety-bringup-missing-checks=access_size,return_size"])
task.checkCommandLineDoesNotContain("-fno-bounds-safety-bringup-missing-checks")
},

// Opt-outs
[ enableBoundsSafetyBuildSetting: "YES",
boundsSafetyMissingChecksSetting: "batch_0",
boundsSafetyMissingChecksOptOutsSetting: "access_size"]: { (task: any PlannedTask) in
task.checkCommandLineContains([
"-fbounds-safety-bringup-missing-checks=batch_0",
"-fno-bounds-safety-bringup-missing-checks=access_size"])
},
[ enableBoundsSafetyBuildSetting: "YES",
boundsSafetyMissingChecksSetting: "batch_0",
boundsSafetyMissingChecksOptOutsSetting: "access_size,return_size"]: { (task: any PlannedTask) in
task.checkCommandLineContains([
"-fbounds-safety-bringup-missing-checks=batch_0",
"-fno-bounds-safety-bringup-missing-checks=access_size,return_size"])
},
]

for (overrides, checkOverrideProperties) in missingChecksOverrides {
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: overrides), runDestination: .macOS, fs: fs) { results -> Void in
results.checkTarget("AppTarget") { target -> Void in
results.checkTask(.matchTarget(target), .matchRuleType("CompileC"), body: {task in
// Check the overrides contains -fbounds-safety or -fbounds-attributes
task.checkCommandLineContains([enableBoundsSafetyFlag])
// Check properties specific to this array of overrides
checkOverrideProperties(task)
})
}
}
}
}
}
}

Expand Down
Loading