Skip to content

[flang][driver] deprecate manual usage of -lFortran_main #79016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2024

Conversation

tblah
Copy link
Contributor

@tblah tblah commented Jan 22, 2024

Intended to warn users of the 18.x release not to do this.

A better solution should be found for the 19.x release. See discussion in #78152.

Unfortunately there is no warning on Windows currently. I am rushing to get this landed before 19.x branches.

Intended to warn users of the 19.x release not to do this.

A better solution should be found for the 20.x release. See discussion
in llvm#78152.

Unfortunately there is no warning on Windows currently. I am rushing to
get this landed before 19.x branches.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" flang:driver flang Flang issues not falling into any other category labels Jan 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2024

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

@llvm/pr-subscribers-clang-driver

Author: Tom Eccles (tblah)

Changes

Intended to warn users of the 19.x release not to do this.

A better solution should be found for the 20.x release. See discussion in #78152.

Unfortunately there is no warning on Windows currently. I am rushing to get this landed before 19.x branches.


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

3 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+2)
  • (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+12-2)
  • (modified) flang/test/Driver/linker-flags.f90 (+4)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 090b169a0e72408..094fe1950941270 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -427,6 +427,8 @@ def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
 def warn_drv_deprecated_arg : Warning<
   "argument '%0' is deprecated, use '%1' instead">, InGroup<Deprecated>;
+def warn_drv_deprecated_custom : Warning<
+  "argument '%0' is deprecated, %1">, InGroup<Deprecated>;
 def warn_drv_assuming_mfloat_abi_is : Warning<
   "unknown platform, assuming -mfloat-abi=%0">;
 def warn_drv_unsupported_float_abi_by_lib : Warning<
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 385f66f3782bc1a..938f4941eb5a03f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1193,6 +1193,16 @@ static void addFortranMain(const ToolChain &TC, const ArgList &Args,
     return;
   }
 
+  const Driver &D = TC.getDriver();
+  const char *LinkFlag = "-lFortran_main";
+
+  // warn if -lFortran_main was already specified
+  for (const char *arg : CmdArgs) {
+    if (strncmp(arg, LinkFlag, strlen(LinkFlag)) == 0)
+      D.Diag(diag::warn_drv_deprecated_custom)
+          << LinkFlag << "see the flang driver documentation for correct usage";
+  }
+
   // 2. GNU and similar
   // The --whole-archive option needs to be part of the link line to make
   // sure that the main() function from Fortran_main.a is pulled in by the
@@ -1201,12 +1211,12 @@ static void addFortranMain(const ToolChain &TC, const ArgList &Args,
   if (!isWholeArchivePresent(Args) && !TC.getTriple().isMacOSX() &&
       !TC.getTriple().isOSAIX()) {
     CmdArgs.push_back("--whole-archive");
-    CmdArgs.push_back("-lFortran_main");
+    CmdArgs.push_back(LinkFlag);
     CmdArgs.push_back("--no-whole-archive");
     return;
   }
 
-  CmdArgs.push_back("-lFortran_main");
+  CmdArgs.push_back(LinkFlag);
 }
 
 /// Add Fortran runtime libs
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index ea91946316cfaa6..341f491bd778fbc 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -11,6 +11,7 @@
 ! RUN: %flang -### --target=x86_64-unknown-dragonfly %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
 ! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,HAIKU
 ! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW
+! RUN: %flang -### --target=aarch64-unknown-linux-gnu %S/Inputs/hello.f90 -lFortran_main 2>&1 | FileCheck %s --check-prefixes=DEPRECATED
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'oldnames' on Windows,
 !       but it is not needed when compiling Fortran code and they might bring in
@@ -53,3 +54,6 @@
 ! MSVC-LABEL: link
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Check that we warn when using -lFortran_main
+! DEPRECATED: warning: argument '-lFortran_main' is deprecated, see the flang driver documentation for correct usage [-Wdeprecated]

@mjklemm
Copy link
Contributor

mjklemm commented Jan 22, 2024

I'm OK with landing this for Linux only at this point.

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@kkwli kkwli left a comment

Choose a reason for hiding this comment

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

LG. Thanks

Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

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

Intended to warn users of the 19.x release not to do this.

A better solution should be found for the 20.x release. See discussion in #78152.

Unfortunately there is no warning on Windows currently. I am rushing to get this landed before 19.x branches.

Did you mean:

Intended to warn users of the 18.x release not to do this.

A better solution should be found for the 19.x release. See discussion in #78152.

Unfortunately there is no warning on Windows currently. I am rushing to get this landed before 19.x branches.

LGTM modulo a few comments. I like this direction!

@@ -1193,6 +1193,16 @@ static void addFortranMain(const ToolChain &TC, const ArgList &Args,
return;
}

const Driver &D = TC.getDriver();
const char *LinkFlag = "-lFortran_main";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const char *LinkFlag = "-lFortran_main";
const char *FortranMainLinkFlag = "-lFortran_main";

const Driver &D = TC.getDriver();
const char *LinkFlag = "-lFortran_main";

// warn if -lFortran_main was already specified
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// warn if -lFortran_main was already specified
// Warn if the user added `-lFortran_main` - this library is an implementation detail of Flang and should be handled automatically by the driver.

for (const char *arg : CmdArgs) {
if (strncmp(arg, LinkFlag, strlen(LinkFlag)) == 0)
D.Diag(diag::warn_drv_deprecated_custom)
<< LinkFlag << "see the flang driver documentation for correct usage";
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]

Suggested change
<< LinkFlag << "see the flang driver documentation for correct usage";
<< LinkFlag << "see the Flang driver documentation for correct usage";

@@ -1193,6 +1193,16 @@ static void addFortranMain(const ToolChain &TC, const ArgList &Args,
return;
}

const Driver &D = TC.getDriver();
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this whole block below the // 2. GNU and similar? Otherwise it seems that this is still part of MSVC processing.

@tblah tblah merged commit d37d1c8 into llvm:main Jan 22, 2024
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' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants