Skip to content

[flang] INT2 & INT8 can't be specific intrinsic functions #115360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Nov 7, 2024

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.

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 llvm#115324.
@klausler klausler requested a review from clementval November 7, 2024 18:44
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/115360.diff

3 Files Affected:

  • (modified) flang/lib/Evaluate/fold-integer.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics.cpp (+4-6)
  • (modified) flang/test/Evaluate/int8.f90 (+4-2)
diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp
index 594a614a5f2e76..0ad09d76a6555d 100644
--- a/flang/lib/Evaluate/fold-integer.cpp
+++ b/flang/lib/Evaluate/fold-integer.cpp
@@ -873,7 +873,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
     } else {
       DIE("first argument must be CHARACTER");
     }
-  } else if (name == "int") {
+  } else if (name == "int" || name == "int2" || name == "int8") {
     if (auto *expr{UnwrapExpr<Expr<SomeType>>(args[0])}) {
       return common::visit(
           [&](auto &&x) -> Expr<T> {
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index aa44967817722e..89d92d7ed3ef6a 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -572,6 +572,10 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
             DefaultingKIND},
         KINDInt},
     {"int", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}, KINDInt},
+    {"int2", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
+        TypePattern{IntType, KindCode::exactKind, 2}},
+    {"int8", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
+        TypePattern{IntType, KindCode::exactKind, 8}},
     {"int_ptr_kind", {}, DefaultInt, Rank::scalar},
     {"ior", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}},
         OperandInt},
@@ -1176,12 +1180,6 @@ static const SpecificIntrinsicInterface specificIntrinsicFunction[]{
     // procedure pointer target.
     {{"index", {{"string", DefaultChar}, {"substring", DefaultChar}},
         DefaultInt}},
-    {{"int2", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
-         TypePattern{IntType, KindCode::exactKind, 2}},
-        "int"},
-    {{"int8", {{"a", AnyNumeric, Rank::elementalOrBOZ}},
-         TypePattern{IntType, KindCode::exactKind, 8}},
-        "int"},
     {{"isign", {{"a", DefaultInt}, {"b", DefaultInt}}, DefaultInt}, "sign"},
     {{"jiabs", {{"a", TypePattern{IntType, KindCode::exactKind, 4}}},
          TypePattern{IntType, KindCode::exactKind, 4}},
diff --git a/flang/test/Evaluate/int8.f90 b/flang/test/Evaluate/int8.f90
index ef8321f4c710b3..677f1b15a076a4 100644
--- a/flang/test/Evaluate/int8.f90
+++ b/flang/test/Evaluate/int8.f90
@@ -1,5 +1,7 @@
-! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+!RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
 !CHECK: warning: REAL(4) to INTEGER(2) conversion overflowed
-!CHECK: PRINT *, 32767_2, 4000000000_8
 print *, int2(4.e9), int8(4.e9)
+!CHECK: error: 'int2' is not an unrestricted specific intrinsic procedure
+!CHECK: error: 'int8' is not an unrestricted specific intrinsic procedure
+call foo(int2,int8)
 end

@klausler klausler requested a review from psteinfeld November 8, 2024 16:57
Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All builds and tests correctly and looks good.

@klausler klausler merged commit ebc0163 into llvm:main Nov 14, 2024
11 checks passed
@klausler klausler deleted the bug115324 branch November 14, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] Fatal internal error
3 participants