Skip to content

[Flang] Fix -frelaxed-c-loc-checks being ignored when using the driver#200733

Merged
chandraghale merged 5 commits into
llvm:mainfrom
ShashwathiNavada:frelaxed-c-loc-checks
Jun 4, 2026
Merged

[Flang] Fix -frelaxed-c-loc-checks being ignored when using the driver#200733
chandraghale merged 5 commits into
llvm:mainfrom
ShashwathiNavada:frelaxed-c-loc-checks

Conversation

@ShashwathiNavada
Copy link
Copy Markdown
Contributor

@ShashwathiNavada ShashwathiNavada commented Jun 1, 2026

-frelaxed-c-loc-checks worked correctly when passed directly to -fc1, but was silently ignored when using the driver (e.g., flang -c -frelaxed-c-loc-checks), causing the flag to go unused. This patch fixes it by adding OPT_relaxed_c_loc to the addAllArgs call in Flang.cpp
Also extend the existing test with a driver-mode RUN line to cover this path.

@llvmorg-github-actions llvmorg-github-actions Bot added clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' flang Flang issues not falling into any other category flang:semantics labels Jun 1, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

llvmorg-github-actions Bot commented Jun 1, 2026

@llvm/pr-subscribers-flang-driver
@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-flang-semantics

Author: ShashwathiNavada

Changes

-frelaxed-c-loc-checks worked correctly when passed directly to -fc1, but was silently ignored when using the driver (e.g., flang -c -frelaxed-c-loc-checks), causing the flag to go unused. This path fixes it by adding OPT_relaxed_c_loc to the addAllArgs call in Flang.cpp
Also extend the existing test with a driver-mode RUN line to cover this path.


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

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2-1)
  • (modified) flang/test/Semantics/c_loc01-relaxed.f90 (+1)
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 892a455167205..8b6e83528fecf 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -261,7 +261,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
        options::OPT_frepack_arrays_contiguity_EQ,
        options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
        options::OPT_ftime_report, options::OPT_ftime_report_EQ,
-       options::OPT_funroll_loops, options::OPT_fno_unroll_loops});
+       options::OPT_funroll_loops, options::OPT_fno_unroll_loops,
+       options::OPT_relaxed_c_loc});
   if (Args.hasArg(options::OPT_fcoarray))
     CmdArgs.push_back("-fcoarray");
 }
diff --git a/flang/test/Semantics/c_loc01-relaxed.f90 b/flang/test/Semantics/c_loc01-relaxed.f90
index 714d4acd5e06f..bfb036b6c0580 100644
--- a/flang/test/Semantics/c_loc01-relaxed.f90
+++ b/flang/test/Semantics/c_loc01-relaxed.f90
@@ -1,4 +1,5 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1 -frelaxed-c-loc-checks
+! RUN: %python %S/test_errors.py %s %flang -frelaxed-c-loc-checks
 module m
   use iso_c_binding
   type haslen(L)

Copy link
Copy Markdown
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@@ -1,4 +1,5 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -frelaxed-c-loc-checks
! RUN: %python %S/test_errors.py %s %flang -frelaxed-c-loc-checks
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we should not invoke the driver in the semantics tests because there is a lot of work that the driver does that is unnecessary.

If the issue was that the driver was not passing the option along to fc1, it is better to add a test to flang/test/Driver. For instance, something like this:

RUN: %flang -### -frelaxed-c-loc-checks %s 2>&1 | FileCheck %s
CHECK: "-fc1"
CHECK-SAME: "-frelaxed-c-loc-checks"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thank you !!

Copy link
Copy Markdown
Contributor

@akuhlens akuhlens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@akuhlens
Copy link
Copy Markdown
Contributor

akuhlens commented Jun 1, 2026

@tarunprabhu I was honestly a little confused about what the Flang.cpp code was doing... I sort of thought visibility from Options.td what driving the forwarding of arguments. I have corrected that misunderstanding after digging into this code and the call chain between main and fc1_main a little more, but I notice that a lot of this code is just forwarding arguments from flang to fc1. Would you be open to an RFC to add a AutomaticallyForwarded or Forwarded OptionFlag in clang/Options/Options.td and have a generic loop that forwards any options with this flag?

Copy link
Copy Markdown
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the change.

@tarunprabhu
Copy link
Copy Markdown
Contributor

@tarunprabhu I was honestly a little confused about what the Flang.cpp code was doing... I sort of thought visibility from Options.td what driving the forwarding of arguments. I have corrected that misunderstanding after digging into this code and the call chain between main and fc1_main a little more, but I notice that a lot of this code is just forwarding arguments from flang to fc1. Would you be open to an RFC to add a AutomaticallyForwarded or Forwarded OptionFlag in clang/Options/Options.td and have a generic loop that forwards any options with this flag?

I think it may be sufficient to just forward any options that have not been claimed, but let me check what clang does here. I can't remember off the top of my head.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@chandraghale
Copy link
Copy Markdown
Contributor

Thanks, LG for merge !!

@chandraghale chandraghale merged commit 364a883 into llvm:main Jun 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' flang:driver flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants