tra created this revision.
tra added reviewers: tmsriram, jlebar.
Herald added subscribers: pengfei, bixia.
tra requested review of this revision.
Herald added a project: clang.

We should not error out on non-x86 targets if `-fbasic-block-sections=none` is 
in effect.

Also, filter it out for GPU-side compilations, as we do with other options not
supported on the GPU.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105226

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
@@ -3,11 +3,18 @@
 // 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: not %clang -c -target arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -### -target arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s
 // RUN: not %clang -c -target x86_64-apple-darwin10 -fbasic-block-sections=all 
%s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### -target x86_64 -fbasic-block-sections=alll %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-INVALID-VALUE %s
 // RUN: %clang -### -target x86_64 -fbasic-block-sections=list %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-INVALID-VALUE %s
 // RUN: %clang -### -target x86_64 -fbasic-block-sections=list= %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NULL-LIST %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### -x cuda -nocudainc -nocudalib -target x86_64 
-fbasic-block-sections=all %s -c 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-CUDA %s
+
 //
+// CHECK-NOOPT-NOT:  -fbasic-block-sections=
 // CHECK-OPT-NONE:   "-fbasic-block-sections=none"
 // CHECK-OPT-ALL:    "-fbasic-block-sections=all"
 // CHECK-OPT-LIST:   "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
@@ -15,3 +22,9 @@
 // CHECK-TRIPLE:     error: unsupported option '-fbasic-block-sections=all' 
for target
 // CHECK-INVALID-VALUE: error: invalid value {{[^ ]*}} in 
'-fbasic-block-sections={{.*}}'
 // CHECK-OPT-NULL-LIST: "-fbasic-block-sections=list="
+
+// GPU-side compilations should have no -fbasic-block-sections. It should only
+// be passed to the host compilation
+// CHECK-CUDA-NOT:  -fbasic-block-sections=
+// CHECK-CUDA: "-cc1" "-triple" "x86_64"
+// CHECK-CUDA-SAME: "-fbasic-block-sections=all"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5269,15 +5269,20 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
+    StringRef Val = A->getValue();
     if (Triple.isX86() && Triple.isOSBinFormatELF()) {
-      StringRef Val = A->getValue();
       if (Val != "all" && Val != "labels" && Val != "none" &&
           !Val.startswith("list="))
         D.Diag(diag::err_drv_invalid_value)
             << A->getAsString(Args) << A->getValue();
       else
         A->render(Args, CmdArgs);
-    } else {
+    } else if (Triple.isNVPTX()) {
+      // Do not pass the option to the GPU compilation. We still want it 
enabled
+      // for the host-side compilation, so seeing it here is not an error.
+    } else if (Val != "none") {
+      // =none is allowed everywhere  it's useful for overriding the option
+      // and is the same as not specifying the option.
       D.Diag(diag::err_drv_unsupported_opt_for_target)
           << A->getAsString(Args) << TripleStr;
     }


Index: clang/test/Driver/fbasic-block-sections.c
===================================================================
--- clang/test/Driver/fbasic-block-sections.c
+++ clang/test/Driver/fbasic-block-sections.c
@@ -3,11 +3,18 @@
 // 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: not %clang -c -target arm-unknown-linux -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -### -target arm-unknown-linux -fbasic-block-sections=all -fbasic-block-sections=none %s -S 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s
 // RUN: not %clang -c -target x86_64-apple-darwin10 -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### -target x86_64 -fbasic-block-sections=alll %s -S 2>&1 | FileCheck -check-prefix=CHECK-INVALID-VALUE %s
 // RUN: %clang -### -target x86_64 -fbasic-block-sections=list %s -S 2>&1 | FileCheck -check-prefix=CHECK-INVALID-VALUE %s
 // RUN: %clang -### -target x86_64 -fbasic-block-sections=list= %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-NULL-LIST %s
+// RUN: %clang -### -target x86_64 -fbasic-block-sections=none %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### -x cuda -nocudainc -nocudalib -target x86_64 -fbasic-block-sections=all %s -c 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-CUDA %s
+
 //
+// CHECK-NOOPT-NOT:  -fbasic-block-sections=
 // CHECK-OPT-NONE:   "-fbasic-block-sections=none"
 // CHECK-OPT-ALL:    "-fbasic-block-sections=all"
 // CHECK-OPT-LIST:   "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
@@ -15,3 +22,9 @@
 // CHECK-TRIPLE:     error: unsupported option '-fbasic-block-sections=all' for target
 // CHECK-INVALID-VALUE: error: invalid value {{[^ ]*}} in '-fbasic-block-sections={{.*}}'
 // CHECK-OPT-NULL-LIST: "-fbasic-block-sections=list="
+
+// GPU-side compilations should have no -fbasic-block-sections. It should only
+// be passed to the host compilation
+// CHECK-CUDA-NOT:  -fbasic-block-sections=
+// CHECK-CUDA: "-cc1" "-triple" "x86_64"
+// CHECK-CUDA-SAME: "-fbasic-block-sections=all"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5269,15 +5269,20 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
+    StringRef Val = A->getValue();
     if (Triple.isX86() && Triple.isOSBinFormatELF()) {
-      StringRef Val = A->getValue();
       if (Val != "all" && Val != "labels" && Val != "none" &&
           !Val.startswith("list="))
         D.Diag(diag::err_drv_invalid_value)
             << A->getAsString(Args) << A->getValue();
       else
         A->render(Args, CmdArgs);
-    } else {
+    } else if (Triple.isNVPTX()) {
+      // Do not pass the option to the GPU compilation. We still want it enabled
+      // for the host-side compilation, so seeing it here is not an error.
+    } else if (Val != "none") {
+      // =none is allowed everywhere  it's useful for overriding the option
+      // and is the same as not specifying the option.
       D.Diag(diag::err_drv_unsupported_opt_for_target)
           << A->getAsString(Args) << TripleStr;
     }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to