aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/clang_flags_test.go
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-09-21 22:05:43 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-09-21 22:05:43 +0000
commit73fde5d5e2d64f4806fef172dbc064a8e5228694 (patch)
tree3e4cabab5a57ae288c245cff9a1a6ff7926a3207 /compiler_wrapper/clang_flags_test.go
parent40214b48188358a80b7478bfff21d4814dd9177c (diff)
parent0348d10214299073ea59bda4987dd8813a9e7812 (diff)
downloadtoolchain-utils-android14-qpr2-s3-release.tar.gz
Change-Id: Ia39ecafdc4b00a0b2505b638c14b80c02e34d4b6
Diffstat (limited to 'compiler_wrapper/clang_flags_test.go')
-rw-r--r--compiler_wrapper/clang_flags_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/compiler_wrapper/clang_flags_test.go b/compiler_wrapper/clang_flags_test.go
index 08e8a8dc..8b3f5a24 100644
--- a/compiler_wrapper/clang_flags_test.go
+++ b/compiler_wrapper/clang_flags_test.go
@@ -33,6 +33,36 @@ func TestClangBasename(t *testing.T) {
})
}
+func TestAppendCppFlags(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.cfg.cppFlags = append(ctx.cfg.cppFlags, "cppOnlyFlag")
+ // C++ only flags are disabled on clang.
+ clangCmd := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand("./x86_64-cros-linux-gnu-clang", mainCc)))
+ if err := verifyArgCount(clangCmd, 0, "cppOnlyFlag"); err != nil {
+ t.Error(err)
+ }
+ // C++ only flags are enabled on clang++.
+ clangPlusPlusCmd := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand("./x86_64-cros-linux-gnu-clang++", mainCc)))
+ if err := verifyArgCount(clangPlusPlusCmd, 1, "cppOnlyFlag"); err != nil {
+ t.Error(err)
+ }
+ // C++ only flags are disabled with -x.
+ clangPlusPlusWithXCmd := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand("./x86_64-cros-linux-gnu-clang++", "-x", "c", mainCc)))
+ if err := verifyArgCount(clangPlusPlusWithXCmd, 0, "cppOnlyFlag"); err != nil {
+ t.Error(err)
+ }
+ // C++ only flags are disabled with " - " .
+ clangPlusPlusWithStdin := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand("./x86_64-cros-linux-gnu-clang++", "-", mainCc)))
+ if err := verifyArgCount(clangPlusPlusWithStdin, 0, "cppOnlyFlag"); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
func TestClangPathGivenClangEnv(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
ctx.env = []string{"CLANG=/a/b/clang"}
@@ -310,3 +340,18 @@ func TestClangLinkerPathRelativeToRootDir(t *testing.T) {
}
})
}
+
+func TestFilterUnsupportedFlags(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(clangX86_64, "-Xcompiler", mainCc)))
+ if err := verifyArgCount(cmd, 0, "-Xcompiler"); err != nil {
+ t.Error(err)
+ }
+ cmd = ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(clangX86_64, "-avoid-version", mainCc)))
+ if err := verifyArgCount(cmd, 0, "-avoid-version"); err != nil {
+ t.Error(err)
+ }
+ })
+}