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

Caroline Newcombe via flang-commits flang-commits at lists.llvm.org
Wed Sep 23 05:46:08 PDT 2026


================
@@ -1259,22 +1256,54 @@ 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 == "f2028") {
+      res.getFrontendOpts().features.WarnOnAllNonstandard();
+      res.getLangOpts().setFortranStandard(
+          Fortran::common::LangOptions::Fortran2028);
     } else {
       const unsigned diagID =
           diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
-                                "Only -std=f2018 is allowed currently.");
+                                "Only 'f2018', 'f2023', or 'f2028' are "
+                                "accepted to -std= currently.");
       diags.Report(diagID);
     }
   }
+
+  // SystemClockStrict warning check
+  {
+    // 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:
+    //  -W{no-}system-clock-strict
+    //  -std=f20{18,23,28}
+    // Scheme for setting the SystemClockStrict warning:
+    //  - If Fortran 2018 has been set as the Fortran standard to follow, that
+    //    is `-std=f2018` is the last `std` flag, then this warning is
+    //    disabled. Otherwise, the warning is enabled.
----------------
cenewcombe wrote:

I believe `-std=f2018 -pedantic` would now enable this warning, since `WarnOnAllUsage` resets and flips the whole `warnUsage_` set. If you wanted to keep the previous behavior (where `-pedantic` doesn't turn the warning back on), the carve-out could move to `WarnOnAllUsage` rather than being deleted.

I also think it's fine to leave it as is — but then this comment should mention `-pedantic` alongside `-W{no-}system-clock-strict` as later overrides. Either way, could you add a RUN line with `-std=f2018 -pedantic` to pin the behavior?

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


More information about the flang-commits mailing list