Skip to content

Commit ebc0163

Browse files
authored
[flang] INT2 & INT8 can't be specific intrinsic functions (#115360)
I recently added support for the extension intrinsic functions INT2 and INT8, and took the shortcut of defining them as specific intrinsic functions that map to the standard INT() with hard-wired KIND= values for the result. This works fine for references to these functions, but leads to a compiler crash for an attempt to use their names in contexts other than calling them, since their argument types aren't restricted to single types and no concrete interface can be characterized for them. So move them out of the table of specific intrinsic functions and into the general table of intrinsics, and then handle them afterwards as if they had been INT(). Fixes #115324.
1 parent 2bc30f3 commit ebc0163

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

flang/lib/Evaluate/fold-integer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
873873
} else {
874874
DIE("first argument must be CHARACTER");
875875
}
876-
} else if (name == "int") {
876+
} else if (name == "int" || name == "int2" || name == "int8") {
877877
if (auto *expr{UnwrapExpr<Expr<SomeType>>(args[0])}) {
878878
return common::visit(
879879
[&](auto &&x) -> Expr<T> {

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
572572
DefaultingKIND},
573573
KINDInt},
574574
{"int", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}, KINDInt},
575+
{"int2", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
576+
TypePattern{IntType, KindCode::exactKind, 2}},
577+
{"int8", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
578+
TypePattern{IntType, KindCode::exactKind, 8}},
575579
{"int_ptr_kind", {}, DefaultInt, Rank::scalar},
576580
{"ior", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}},
577581
OperandInt},
@@ -1176,12 +1180,6 @@ static const SpecificIntrinsicInterface specificIntrinsicFunction[]{
11761180
// procedure pointer target.
11771181
{{"index", {{"string", DefaultChar}, {"substring", DefaultChar}},
11781182
DefaultInt}},
1179-
{{"int2", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
1180-
TypePattern{IntType, KindCode::exactKind, 2}},
1181-
"int"},
1182-
{{"int8", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
1183-
TypePattern{IntType, KindCode::exactKind, 8}},
1184-
"int"},
11851183
{{"isign", {{"a", DefaultInt}, {"b", DefaultInt}}, DefaultInt}, "sign"},
11861184
{{"jiabs", {{"a", TypePattern{IntType, KindCode::exactKind, 4}}},
11871185
TypePattern{IntType, KindCode::exactKind, 4}},

flang/test/Evaluate/int8.f90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
1+
!RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
22
!CHECK: warning: REAL(4) to INTEGER(2) conversion overflowed
3-
!CHECK: PRINT *, 32767_2, 4000000000_8
43
print *, int2(4.e9), int8(4.e9)
4+
!CHECK: error: 'int2' is not an unrestricted specific intrinsic procedure
5+
!CHECK: error: 'int8' is not an unrestricted specific intrinsic procedure
6+
call foo(int2,int8)
57
end

0 commit comments

Comments
 (0)