[flang-commits] [flang] [flang] Add semantics support for Fortran 2023 conditional arguments (F2023 R1526-R1528) (PR #195345)

via flang-commits flang-commits at lists.llvm.org
Thu Jun 4 03:24:31 PDT 2026


================
@@ -4819,9 +4822,121 @@ void ArgumentAnalyzer::Analyze(
               actual->set_isPercentVal();
             }
           },
-          [&](const parser::ConditionalArg &) {
-            context_.Say(
-                "Fortran 2023 conditional arguments are not yet supported"_todo_en_US);
+          [&](const parser::ConditionalArg &condArg) {
+            // F2023 R1526 conditional-arg analysis (recursive)
+            using EvalConsequent = ActualArgument::ConditionalArg::Consequent;
+            using EvalConditionalArg = ActualArgument::ConditionalArg;
+            using EvalTail =
+                ActualArgument::ConditionalArg::ConditionalArgPartOrConsequent;
+
+            // Analyze a single parser::Consequent into an evaluate Consequent
+            auto analyzeConsequent{[&](const parser::ConditionalArg::Consequent
+                                           &consequent) -> EvalConsequent {
+              EvalConsequent result;
+              common::visit(
+                  common::visitors{
+                      [&](const common::Indirection<parser::Expr> &expr) {
+                        // F2023 15.5.2.3-2: consequent-args are actual
+                        // arguments, so TYPE(*) dummies are permitted here
+                        // (F2018 C710 (F2023 C715) waived).
+                        auto restorer{context_.AllowAssumedTypeDummy()};
----------------
jeanPerier wrote:

Won't this allow assumed-type for the whole sub-expression tree visit and lead to miss illegal usage of assumed-type in sub-expression as in: `call foo((cdt ? assumed_type + 1 : other))`?

It seems that only that only `expr` should be  allowed to be an assumed-type here and that it would be better to add some optional argument to Analyze to only target `expr` instead of adding a state that will impact the whole sub-expression tree.

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


More information about the flang-commits mailing list