[flang-commits] [clang] [flang] [flang] Add checks for Fortran 2023 system clock and add f2023/f202Y to valid arguments of -std= (PR #205938)

via flang-commits flang-commits at lists.llvm.org
Tue Aug 11 15:01:54 PDT 2026


================
@@ -1197,22 +1194,66 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
         Fortran::common::LanguageFeature::OpenACC);
   }
 
-  // -std=f2018
-  // TODO: Set proper options when more fortran standards
-  // are supported.
+  // -std=f20**
   if (args.hasArg(clang::options::OPT_std_EQ)) {
     auto standard = args.getLastArgValue(clang::options::OPT_std_EQ);
-    // We only allow f2018 as the given standard
     if (standard == "f2018") {
-      res.setEnableConformanceChecks();
       res.getFrontendOpts().features.WarnOnAllNonstandard();
+      res.getLangOpts().setFortranStandard(
+          Fortran::common::LangOptions::Fortran2018);
+    } else if (standard == "f2023") {
+      res.getFrontendOpts().features.WarnOnAllNonstandard();
+      res.getLangOpts().setFortranStandard(
+          Fortran::common::LangOptions::Fortran2023);
+    } else if (standard == "f202Y") {
+      res.getFrontendOpts().features.WarnOnAllNonstandard();
+      res.getLangOpts().setFortranStandard(
+          Fortran::common::LangOptions::Fortran202Y);
     } else {
       const unsigned diagID =
           diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
-                                "Only -std=f2018 is allowed currently.");
+                                "Only 'f2018', 'f2023', or 'f202Y' are "
+                                "accepted to -std= currently.");
       diags.Report(diagID);
     }
   }
+
+  // -f{no-}system-clock-strict
+  {
+    // Fortran 2023 introduced restrictions to the arguements of SYSTEM_CLOCK.
+    // Since violations of these restrictions can cause unexpected or incorrect
+    // runtime results, violations should be reported to users at compile time
+    // by default. However, since these restrictions are not in Fortran 2018,
+    // these reports should be warnings and not errors. There are two ways to
+    // enable/disable these warnings:
+    //  -f{no-}system-clock-strict
+    //  -std=f20{18,23}
+    // Rules for enabling/disabling these warnings:
+    //  - If one or more of `-f{no-}system-clock-strict` appear, then the last
+    //    dictates whether or not the warnings are enabled.
+    //  - If no `-f{no-}system-clock-strict` flags appear and Fortran 2018 has
+    //    been set as the Fortran standard to follow, that is `-std=f2018` is
+    //    the last `std` flag, then the warnings are disabled.
+    //  - Otherwise, the warnings are enabled.
+    auto last = args.getLastArg(clang::options::OPT_fsystem_clock_strict,
+                                clang::options::OPT_fno_system_clock_strict);
----------------
chris-earl wrote:

While the suggested logic is clearer, it does not capture the intended behavior. If both `-fsystem-clock-strict` and `-fno-system-clock-strict` appear on the same call in that order, the first `else if` will be skipped because the `if` condition evaluated to true.

Incidentally, this is the test on line 6 of `flang/test/Semantics/system_clock.f90`.

I have rewritten the logic here to hopefully be more clear. Let me know if the latest version is more confusing, and we can revert to what I originally had (or something else).

https://github.com/llvm/llvm-project/pull/205938


More information about the flang-commits mailing list