[PATCH] D87426: Disallow fbasic-block-sections on non-ELF, non-x86 targets.
Snehasish Kumar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 9 20:52:57 PDT 2020
snehasish updated this revision to Diff 290867.
snehasish added a comment.
Update test based on review comments.
- Use diag::err instead of warn.
- Drop linux-gnu from the triple for the default test.
- Check for the presence of the diagnostic message.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87426/new/
https://reviews.llvm.org/D87426
Files:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/fbasic-block-sections.c
Index: clang/test/Driver/fbasic-block-sections.c
===================================================================
--- clang/test/Driver/fbasic-block-sections.c
+++ clang/test/Driver/fbasic-block-sections.c
@@ -1,9 +1,13 @@
-// RUN: %clang -### -fbasic-block-sections=none %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-NONE %s
-// RUN: %clang -### -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-ALL %s
-// RUN: %clang -### -fbasic-block-sections=list=%s %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LIST %s
-// RUN: %clang -### -fbasic-block-sections=labels %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=none %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-ALL %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=labels %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### -target arm-unknown-linux -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
//
-// CHECK-OPT-NONE: "-fbasic-block-sections=none"
-// CHECK-OPT-ALL: "-fbasic-block-sections=all"
-// CHECK-OPT-LIST: "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
+// CHECK-OPT-NONE: "-fbasic-block-sections=none"
+// CHECK-OPT-ALL: "-fbasic-block-sections=all"
+// CHECK-OPT-LIST: "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
// CHECK-OPT-LABELS: "-fbasic-block-sections=labels"
+// CHECK-TRIPLE-NOT: "-fbasic-block-sections=all"
+// CHECK-TRIPLE: error: unsupported option '-fbasic-block-sections=all' for target
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4880,13 +4880,18 @@
}
if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
- StringRef Val = A->getValue();
- if (Val != "all" && Val != "labels" && Val != "none" &&
- !(Val.startswith("list=") && llvm::sys::fs::exists(Val.substr(5))))
- D.Diag(diag::err_drv_invalid_value)
- << A->getAsString(Args) << A->getValue();
- else
- A->render(Args, CmdArgs);
+ if (Triple.isX86() && Triple.isOSBinFormatELF()) {
+ StringRef Val = A->getValue();
+ if (Val != "all" && Val != "labels" && Val != "none" &&
+ !(Val.startswith("list=") && llvm::sys::fs::exists(Val.substr(5))))
+ D.Diag(diag::err_drv_invalid_value)
+ << A->getAsString(Args) << A->getValue();
+ else
+ A->render(Args, CmdArgs);
+ } else {
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << A->getAsString(Args) << TripleStr;
+ }
}
if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87426.290867.patch
Type: text/x-patch
Size: 3154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200910/ba31c86d/attachment-0001.bin>
More information about the cfe-commits
mailing list