[llvm-branch-commits] [clang] cf45731 - [Driver] Fix assertion failure when -fprofile-generate -fcs-profile-generate are used together

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 12 14:24:47 PST 2021


Author: Fangrui Song
Date: 2021-01-12T14:19:55-08:00
New Revision: cf45731f0eaead79e1ac501b397e330df41ec152

URL: https://github.com/llvm/llvm-project/commit/cf45731f0eaead79e1ac501b397e330df41ec152
DIFF: https://github.com/llvm/llvm-project/commit/cf45731f0eaead79e1ac501b397e330df41ec152.diff

LOG: [Driver] Fix assertion failure when -fprofile-generate -fcs-profile-generate are used together

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

Also add some driver tests.

Reviewed By: xur

Differential Revision: https://reviews.llvm.org/D94463

Added: 
    clang/test/Driver/fcs-profile-generate.c

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 4a20936ddda1..c03b513150b3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -766,9 +766,11 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
     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 (ProfileGenerateArg) {
     if (ProfileGenerateArg->getOption().matches(

diff  --git a/clang/test/Driver/fcs-profile-generate.c b/clang/test/Driver/fcs-profile-generate.c
new file mode 100644
index 000000000000..6be7f758c3e6
--- /dev/null
+++ b/clang/test/Driver/fcs-profile-generate.c
@@ -0,0 +1,15 @@
+// RUN: %clang -### -c -fprofile-use=a.profdata -fcs-profile-generate %s 2>&1 | FileCheck %s
+// CHECK:      "-fprofile-instrument=csllvm"
+// CHECK-NOT:  "-fprofile-instrument-path=
+// CHECK-SAME: "-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"
+
+/// Degradation case. This usage does not make much sense.
+// RUN: %clang -### -c -fcs-profile-generate %s 2>&1 | FileCheck %s --check-prefix=NOUSE
+// NOUSE:     "-fprofile-instrument=csllvm"
+// NOUSE-NOT: "-fprofile-instrument-path=
+
+// 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'


        


More information about the llvm-branch-commits mailing list