llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Bruno Cardoso Lopes (bcardosolopes)

<details>
<summary>Changes</summary>

`-fno-clangir` was a no-op whenever `-fclangir` also appeared on the command 
line, in either order: the CIR pipeline ran regardless. Options.td already 
declares clangir as a BoolFOption with a NegFlag, so last-wins semantics were 
intended and the generated marshalling implements them correctly.

---
Full diff: https://github.com/llvm/llvm-project/pull/214904.diff


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+4-1) 
- (modified) clang/test/CIR/Driver/clangir.c (+23) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 85fe99dbf8b69..ec1ad05497751 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5332,7 +5332,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
     }
   }
 
-  if (Args.hasArg(options::OPT_fclangir))
+  if (Args.hasFlag(options::OPT_fclangir, options::OPT_fno_clangir, false))
     CmdArgs.push_back("-fclangir");
 
   if (IsOpenMPDevice) {
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 6562cb3a9b135..4f319f11e7cb6 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3172,7 +3172,10 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
   if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
     Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
                                                            << "-emit-module";
-  if (Args.hasArg(OPT_fclangir) || Args.hasArg(OPT_emit_cir))
+  // -fclangir/-fno-clangir are marshalled into Opts.UseClangIRPipeline above,
+  // which already gives them last-wins semantics; don't clobber that here.
+  // -emit-cir is an action that implies the pipeline regardless.
+  if (Args.hasArg(OPT_emit_cir))
     Opts.UseClangIRPipeline = true;
 
 #if CLANG_ENABLE_CIR
diff --git a/clang/test/CIR/Driver/clangir.c b/clang/test/CIR/Driver/clangir.c
index afbe6c6d2388f..d8419d8812f62 100644
--- a/clang/test/CIR/Driver/clangir.c
+++ b/clang/test/CIR/Driver/clangir.c
@@ -15,4 +15,27 @@
 // LLVMIR: "-cc1"
 // LLVMIR-SAME: "-fclangir"
 
+// -fclangir and -fno-clangir are last-wins, in either order.
+
+// RUN: %clang -### -fclangir -fno-clangir -S %s 2>&1 | FileCheck %s 
--check-prefix=NEG
+// RUN: %clang -### -fno-clangir -S %s 2>&1 | FileCheck %s --check-prefix=NEG
+// NEG: "-cc1"
+// NEG-NOT: "-fclangir"
+
+// RUN: %clang -### -fno-clangir -fclangir -S %s 2>&1 | FileCheck %s 
--check-prefix=POS
+// POS: "-cc1"
+// POS-SAME: "-fclangir"
+
+// The frontend must honor the negation too, not just the driver. -fopenacc
+// warns only when the CIR pipeline is off, which makes UseClangIRPipeline
+// observable at -cc1.
+
+// RUN: %clang_cc1 -fopenacc -fclangir -fno-clangir -emit-llvm-only %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CC1-OFF
+// CC1-OFF: use -fclangir to enable runtime effect
+
+// RUN: %clang_cc1 -fopenacc -fno-clangir -fclangir -emit-llvm-only %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CC1-ON --allow-empty
+// CC1-ON-NOT: use -fclangir to enable runtime effect
+
 void foo() {}

``````````

</details>


https://github.com/llvm/llvm-project/pull/214904
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to