[flang-commits] [flang] 3632e9f - [flang] Accept NULL(mold=x) as constant component value in constant structure constructor

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Feb 14 14:47:03 PST 2022


Author: Peter Klausler
Date: 2022-02-14T14:46:53-08:00
New Revision: 3632e9f85246ac01711f1151ae72dbba3d2a38d5

URL: https://github.com/llvm/llvm-project/commit/3632e9f85246ac01711f1151ae72dbba3d2a38d5
DIFF: https://github.com/llvm/llvm-project/commit/3632e9f85246ac01711f1151ae72dbba3d2a38d5.diff

LOG: [flang] Accept NULL(mold=x) as constant component value in constant structure constructor

The predicate IsInitialDataTarget() was failing to return a correct true
result in the case of a reference to the intrinsic function NULL() with a
MOLD= argument.  Fix, and improve tests for "NULL()" elsewhere in semantics,
checking for an attribute set by intrinsics.cpp rather than the actual name.

Differential Revision: https://reviews.llvm.org/D119452

Added: 
    

Modified: 
    flang/lib/Evaluate/check-expression.cpp
    flang/lib/Semantics/expression.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 64b118a54aa79..06be4da621bcd 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -270,9 +270,6 @@ class IsInitialDataTargetHelper
     return false;
   }
   bool operator()(const StructureConstructor &) const { return false; }
-  template <typename T> bool operator()(const FunctionRef<T> &) {
-    return false;
-  }
   template <typename D, typename R, typename... O>
   bool operator()(const Operation<D, R, O...> &) const {
     return false;
@@ -280,7 +277,11 @@ class IsInitialDataTargetHelper
   template <typename T> bool operator()(const Parentheses<T> &x) const {
     return (*this)(x.left());
   }
-  template <typename T> bool operator()(const FunctionRef<T> &x) const {
+  bool operator()(const ProcedureRef &x) const {
+    if (const SpecificIntrinsic * intrinsic{x.proc().GetSpecificIntrinsic()}) {
+      return intrinsic->characteristics.value().attrs.test(
+          characteristics::Procedure::Attr::NullPointer);
+    }
     return false;
   }
   bool operator()(const Relational<SomeType> &) const { return false; }
@@ -557,7 +558,7 @@ class CheckSpecificationExprHelper
     return std::nullopt;
   }
 
-  template <typename T> Result operator()(const FunctionRef<T> &x) const {
+  Result operator()(const ProcedureRef &x) const {
     if (const auto *symbol{x.proc().GetSymbol()}) {
       const Symbol &ultimate{symbol->GetUltimate()};
       if (!semantics::IsPureProcedure(ultimate)) {
@@ -708,7 +709,7 @@ class IsSimplyContiguousHelper
   Result operator()(const ComplexPart &) const { return false; }
   Result operator()(const Substring &) const { return false; }
 
-  template <typename T> Result operator()(const FunctionRef<T> &x) const {
+  Result operator()(const ProcedureRef &x) const {
     if (auto chars{
             characteristics::Procedure::Characterize(x.proc(), context_)}) {
       if (chars->functionResult) {

diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 7b8da73f404cc..405ca251fa86b 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -3108,7 +3108,9 @@ bool ExpressionAnalyzer::EnforceTypeConstraint(parser::CharBlock at,
 MaybeExpr ExpressionAnalyzer::MakeFunctionRef(parser::CharBlock callSite,
     ProcedureDesignator &&proc, ActualArguments &&arguments) {
   if (const auto *intrinsic{std::get_if<SpecificIntrinsic>(&proc.u)}) {
-    if (intrinsic->name == "null" && arguments.empty()) {
+    if (intrinsic->characteristics.value().attrs.test(
+            characteristics::Procedure::Attr::NullPointer) &&
+        arguments.empty()) {
       return Expr<SomeType>{NullPointer{}};
     }
   }


        


More information about the flang-commits mailing list