@@ -225,7 +225,8 @@ ENUM_CLASS(Optionality, required,
225
225
)
226
226
227
227
ENUM_CLASS (ArgFlag, none,
228
- canBeNull, // actual argument can be NULL()
228
+ canBeNull, // actual argument can be NULL(with or without MOLD=)
229
+ canBeMoldNull, // actual argument can be NULL(with MOLD=)
229
230
defaultsToSameKind, // for MatchingDefaultKIND
230
231
defaultsToSizeKind, // for SizeDefaultKIND
231
232
defaultsToDefaultForResult, // for DefaultingKIND
@@ -368,7 +369,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
368
369
DefaultLogical},
369
370
{" bit_size" ,
370
371
{{" i" , SameInt, Rank::anyOrAssumedRank, Optionality::required,
371
- common::Intent::In, {ArgFlag::canBeNull }}},
372
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
372
373
SameInt, Rank::scalar, IntrinsicClass::inquiryFunction},
373
374
{" ble" ,
374
375
{{" i" , AnyInt, Rank::elementalOrBOZ},
@@ -403,7 +404,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
403
404
{" dble" , {{" a" , AnyNumeric, Rank::elementalOrBOZ}}, DoublePrecision},
404
405
{" digits" ,
405
406
{{" x" , AnyIntOrReal, Rank::anyOrAssumedRank, Optionality::required,
406
- common::Intent::In, {ArgFlag::canBeNull }}},
407
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
407
408
DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction},
408
409
{" dim" , {{" x" , OperandIntOrReal}, {" y" , OperandIntOrReal}},
409
410
OperandIntOrReal},
@@ -449,7 +450,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
449
450
IntrinsicClass::transformationalFunction},
450
451
{" epsilon" ,
451
452
{{" x" , SameReal, Rank::anyOrAssumedRank, Optionality::required,
452
- common::Intent::In, {ArgFlag::canBeNull }}},
453
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
453
454
SameReal, Rank::scalar, IntrinsicClass::inquiryFunction},
454
455
{" erf" , {{" x" , SameReal}}, SameReal},
455
456
{" erfc" , {{" x" , SameReal}}, SameReal},
@@ -463,8 +464,11 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
463
464
{" exponent" , {{" x" , AnyReal}}, DefaultInt},
464
465
{" exp" , {{" x" , SameFloating}}, SameFloating},
465
466
{" extends_type_of" ,
466
- {{" a" , ExtensibleDerived, Rank::anyOrAssumedRank},
467
- {" mold" , ExtensibleDerived, Rank::anyOrAssumedRank}},
467
+ {{" a" , ExtensibleDerived, Rank::anyOrAssumedRank, Optionality::required,
468
+ common::Intent::In, {ArgFlag::canBeMoldNull}},
469
+ {" mold" , ExtensibleDerived, Rank::anyOrAssumedRank,
470
+ Optionality::required, common::Intent::In,
471
+ {ArgFlag::canBeMoldNull}}},
468
472
DefaultLogical, Rank::scalar, IntrinsicClass::inquiryFunction},
469
473
{" failed_images" , {OptionalTEAM, SizeDefaultKIND}, KINDInt, Rank::vector,
470
474
IntrinsicClass::transformationalFunction},
@@ -512,7 +516,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
512
516
{" getpid" , {}, DefaultInt},
513
517
{" huge" ,
514
518
{{" x" , SameIntOrReal, Rank::anyOrAssumedRank, Optionality::required,
515
- common::Intent::In, {ArgFlag::canBeNull }}},
519
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
516
520
SameIntOrReal, Rank::scalar, IntrinsicClass::inquiryFunction},
517
521
{" hypot" , {{" x" , OperandReal}, {" y" , OperandReal}}, OperandReal},
518
522
{" iachar" , {{" c" , AnyChar}, DefaultingKIND}, KINDInt},
@@ -574,7 +578,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
574
578
{" jzext" , {{" i" , AnyInt}}, DefaultInt},
575
579
{" kind" ,
576
580
{{" x" , AnyIntrinsic, Rank::elemental, Optionality::required,
577
- common::Intent::In, {ArgFlag::canBeNull }}},
581
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
578
582
DefaultInt, Rank::elemental, IntrinsicClass::inquiryFunction},
579
583
{" lbound" ,
580
584
{{" array" , AnyData, Rank::anyOrAssumedRank}, RequiredDIM,
@@ -588,7 +592,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
588
592
{" leadz" , {{" i" , AnyInt}}, DefaultInt},
589
593
{" len" ,
590
594
{{" string" , AnyChar, Rank::anyOrAssumedRank, Optionality::required,
591
- common::Intent::In, {ArgFlag::canBeNull }},
595
+ common::Intent::In, {ArgFlag::canBeMoldNull }},
592
596
DefaultingKIND},
593
597
KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction},
594
598
{" len_trim" , {{" string" , AnyChar}, DefaultingKIND}, KINDInt},
@@ -642,7 +646,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
642
646
SameCharNoLen},
643
647
{" maxexponent" ,
644
648
{{" x" , AnyReal, Rank::anyOrAssumedRank, Optionality::required,
645
- common::Intent::In, {ArgFlag::canBeNull }}},
649
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
646
650
DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction},
647
651
{" maxloc" ,
648
652
{{" array" , AnyRelatable, Rank::array}, RequiredDIM, OptionalMASK,
@@ -681,7 +685,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
681
685
SameCharNoLen},
682
686
{" minexponent" ,
683
687
{{" x" , AnyReal, Rank::anyOrAssumedRank, Optionality::required,
684
- common::Intent::In, {ArgFlag::canBeNull }}},
688
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
685
689
DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction},
686
690
{" minloc" ,
687
691
{{" array" , AnyRelatable, Rank::array}, RequiredDIM, OptionalMASK,
@@ -707,7 +711,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
707
711
{" nearest" , {{" x" , SameReal}, {" s" , AnyReal}}, SameReal},
708
712
{" new_line" ,
709
713
{{" a" , SameCharNoLen, Rank::anyOrAssumedRank, Optionality::required,
710
- common::Intent::In, {ArgFlag::canBeNull }}},
714
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
711
715
SameCharNoLen, Rank::scalar, IntrinsicClass::inquiryFunction},
712
716
{" nint" , {{" a" , AnyReal}, DefaultingKIND}, KINDInt},
713
717
{" norm2" , {{" x" , SameReal, Rank::array}, RequiredDIM}, SameReal,
@@ -747,21 +751,21 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
747
751
SameNumeric, Rank::scalar, IntrinsicClass::transformationalFunction},
748
752
{" precision" ,
749
753
{{" x" , AnyFloating, Rank::anyOrAssumedRank, Optionality::required,
750
- common::Intent::In, {ArgFlag::canBeNull }}},
754
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
751
755
DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction},
752
756
{" present" , {{" a" , Addressable, Rank::anyOrAssumedRank}}, DefaultLogical,
753
757
Rank::scalar, IntrinsicClass::inquiryFunction},
754
758
{" radix" ,
755
759
{{" x" , AnyIntOrReal, Rank::anyOrAssumedRank, Optionality::required,
756
- common::Intent::In, {ArgFlag::canBeNull }}},
760
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
757
761
DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction},
758
762
{" range" ,
759
763
{{" x" , AnyNumeric, Rank::anyOrAssumedRank, Optionality::required,
760
- common::Intent::In, {ArgFlag::canBeNull }}},
764
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
761
765
DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction},
762
766
{" rank" ,
763
767
{{" a" , AnyData, Rank::anyOrAssumedRank, Optionality::required,
764
- common::Intent::In, {ArgFlag::canBeNull }}},
768
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
765
769
DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction},
766
770
{" real" , {{" a" , SameComplex, Rank::elemental}},
767
771
SameReal}, // 16.9.160(4)(ii)
@@ -792,8 +796,11 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
792
796
SameType, Rank::shaped, IntrinsicClass::transformationalFunction},
793
797
{" rrspacing" , {{" x" , SameReal}}, SameReal},
794
798
{" same_type_as" ,
795
- {{" a" , ExtensibleDerived, Rank::anyOrAssumedRank},
796
- {" b" , ExtensibleDerived, Rank::anyOrAssumedRank}},
799
+ {{" a" , ExtensibleDerived, Rank::anyOrAssumedRank, Optionality::required,
800
+ common::Intent::In, {ArgFlag::canBeMoldNull}},
801
+ {" b" , ExtensibleDerived, Rank::anyOrAssumedRank,
802
+ Optionality::required, common::Intent::In,
803
+ {ArgFlag::canBeMoldNull}}},
797
804
DefaultLogical, Rank::scalar, IntrinsicClass::inquiryFunction},
798
805
{" scale" , {{" x" , SameReal}, {" i" , AnyInt}}, SameReal}, // == IEEE_SCALB()
799
806
{" scan" ,
@@ -851,7 +858,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
851
858
IntrinsicClass::transformationalFunction},
852
859
{" storage_size" ,
853
860
{{" a" , AnyData, Rank::anyOrAssumedRank, Optionality::required,
854
- common::Intent::In, {ArgFlag::canBeNull }},
861
+ common::Intent::In, {ArgFlag::canBeMoldNull }},
855
862
SizeDefaultKIND},
856
863
KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction},
857
864
{" sum" , {{" array" , SameNumeric, Rank::array}, RequiredDIM, OptionalMASK},
@@ -873,7 +880,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
873
880
IntrinsicClass::transformationalFunction},
874
881
{" tiny" ,
875
882
{{" x" , SameReal, Rank::anyOrAssumedRank, Optionality::required,
876
- common::Intent::In, {ArgFlag::canBeNull }}},
883
+ common::Intent::In, {ArgFlag::canBeMoldNull }}},
877
884
SameReal, Rank::scalar, IntrinsicClass::inquiryFunction},
878
885
{" trailz" , {{" i" , AnyInt}}, DefaultInt},
879
886
{" transfer" ,
@@ -1744,9 +1751,11 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
1744
1751
return std::nullopt;
1745
1752
}
1746
1753
if (!d.flags .test (ArgFlag::canBeNull)) {
1747
- // NULL() is rarely an acceptable intrinsic argument.
1748
- if (const auto *expr{arg->UnwrapExpr ()}) {
1749
- if (IsNullPointer (*expr)) {
1754
+ if (const auto *expr{arg->UnwrapExpr ()}; expr && IsNullPointer (*expr)) {
1755
+ if (!IsBareNullPointer (expr) && IsNullObjectPointer (*expr) &&
1756
+ d.flags .test (ArgFlag::canBeMoldNull)) {
1757
+ // ok
1758
+ } else {
1750
1759
messages.Say (arg->sourceLocation (),
1751
1760
" A NULL() pointer is not allowed for '%s=' intrinsic argument" _err_en_US,
1752
1761
d.keyword );
@@ -1801,19 +1810,18 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
1801
1810
}
1802
1811
}
1803
1812
} else {
1804
- // NULL(), procedure, or procedure pointer
1813
+ // NULL(no MOLD= ), procedure, or procedure pointer
1805
1814
CHECK (IsProcedurePointerTarget (expr));
1806
1815
if (d.typePattern .kindCode == KindCode::addressable ||
1807
1816
d.rank == Rank::reduceOperation) {
1808
1817
continue ;
1809
1818
} else if (d.typePattern .kindCode == KindCode::nullPointerType) {
1810
1819
continue ;
1811
- } else if (IsNullPointer (expr)) {
1812
- messages.Say (arg->sourceLocation (),
1813
- " Actual argument for '%s=' may not be NULL()" _err_en_US,
1814
- d.keyword );
1820
+ } else if (IsBareNullPointer (&expr)) {
1821
+ // checked elsewhere
1822
+ continue ;
1815
1823
} else {
1816
- CHECK (IsProcedure (expr));
1824
+ CHECK (IsProcedure (expr) || IsProcedurePointer (expr) );
1817
1825
messages.Say (arg->sourceLocation (),
1818
1826
" Actual argument for '%s=' may not be a procedure" _err_en_US,
1819
1827
d.keyword );
0 commit comments