MaskRay created this revision.
MaskRay added a reviewer: xur.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds some tests missing in D54176 <https://reviews.llvm.org/D54176> and 
disallows `-fcs-profile-generate` without `-fprofile-use`.

If conflicting `-fprofile-generate -fcs-profile-generate` are used together,
there is currently an assertion failure. Fix the failure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94463

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fcs-profile-generate.c


Index: clang/test/Driver/fcs-profile-generate.c
===================================================================
--- /dev/null
+++ clang/test/Driver/fcs-profile-generate.c
@@ -0,0 +1,12 @@
+// RUN: %clang -### -c -fprofile-use=a.profdata -fcs-profile-generate %s 2>&1 
| FileCheck %s
+// CHECK:  "-fprofile-instrument=csllvm" 
"-fprofile-instrument-use-path=a.profdata"
+
+// RUN: %clang -### -c -fprofile-use=a.profdata -fcs-profile-generate=dir %s 
2>&1 | FileCheck %s --check-prefix=CHECK1
+// CHECK1: "-fprofile-instrument=csllvm" 
"-fprofile-instrument-path=dir/default_%m.profraw" 
"-fprofile-instrument-use-path=a.profdata"
+
+// RUN: %clang -### -c -fcs-profile-generate %s 2>&1 | FileCheck %s 
--check-prefix=NOUSE
+// NOUSE: error: invalid argument '-fcs-profile-generate' only allowed with 
'-fprofile-use'
+
+// RUN: %clang -### -c -fprofile-generate -fcs-profile-generate %s 2>&1 | 
FileCheck %s --check-prefix=CONFLICT
+// CONFLICT: error: invalid argument '-fcs-profile-generate' not allowed with 
'-fprofile-generate'
+// CONFLICT: error: invalid argument '-fcs-profile-generate' only allowed with 
'-fprofile-use'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -766,9 +766,14 @@
     D.Diag(diag::err_drv_argument_not_allowed_with)
         << ProfileGenerateArg->getSpelling() << ProfileUseArg->getSpelling();
 
-  if (CSPGOGenerateArg && PGOGenerateArg)
+  if (CSPGOGenerateArg && PGOGenerateArg) {
     D.Diag(diag::err_drv_argument_not_allowed_with)
         << CSPGOGenerateArg->getSpelling() << PGOGenerateArg->getSpelling();
+    PGOGenerateArg = nullptr;
+  }
+  if (CSPGOGenerateArg && !ProfileUseArg)
+    D.Diag(diag::err_drv_argument_only_allowed_with)
+        << CSPGOGenerateArg->getSpelling() << "-fprofile-use";
 
   if (ProfileGenerateArg) {
     if (ProfileGenerateArg->getOption().matches(


Index: clang/test/Driver/fcs-profile-generate.c
===================================================================
--- /dev/null
+++ clang/test/Driver/fcs-profile-generate.c
@@ -0,0 +1,12 @@
+// RUN: %clang -### -c -fprofile-use=a.profdata -fcs-profile-generate %s 2>&1 | FileCheck %s
+// CHECK:  "-fprofile-instrument=csllvm" "-fprofile-instrument-use-path=a.profdata"
+
+// RUN: %clang -### -c -fprofile-use=a.profdata -fcs-profile-generate=dir %s 2>&1 | FileCheck %s --check-prefix=CHECK1
+// CHECK1: "-fprofile-instrument=csllvm" "-fprofile-instrument-path=dir/default_%m.profraw" "-fprofile-instrument-use-path=a.profdata"
+
+// RUN: %clang -### -c -fcs-profile-generate %s 2>&1 | FileCheck %s --check-prefix=NOUSE
+// NOUSE: error: invalid argument '-fcs-profile-generate' only allowed with '-fprofile-use'
+
+// RUN: %clang -### -c -fprofile-generate -fcs-profile-generate %s 2>&1 | FileCheck %s --check-prefix=CONFLICT
+// CONFLICT: error: invalid argument '-fcs-profile-generate' not allowed with '-fprofile-generate'
+// CONFLICT: error: invalid argument '-fcs-profile-generate' only allowed with '-fprofile-use'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -766,9 +766,14 @@
     D.Diag(diag::err_drv_argument_not_allowed_with)
         << ProfileGenerateArg->getSpelling() << ProfileUseArg->getSpelling();
 
-  if (CSPGOGenerateArg && PGOGenerateArg)
+  if (CSPGOGenerateArg && PGOGenerateArg) {
     D.Diag(diag::err_drv_argument_not_allowed_with)
         << CSPGOGenerateArg->getSpelling() << PGOGenerateArg->getSpelling();
+    PGOGenerateArg = nullptr;
+  }
+  if (CSPGOGenerateArg && !ProfileUseArg)
+    D.Diag(diag::err_drv_argument_only_allowed_with)
+        << CSPGOGenerateArg->getSpelling() << "-fprofile-use";
 
   if (ProfileGenerateArg) {
     if (ProfileGenerateArg->getOption().matches(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to