From 18dd123c56754edf62c7042dcf23185c3727610f Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Fri, 29 Apr 2022 16:16:41 -0700 Subject: [PATCH] [flang] Operands of SIGN() need not have same kind The standard requires that the operands of the intrinsic function SIGN() must have the same type (INTEGER or REAL), but they are not required to have the same kind. Differential Revision: https://reviews.llvm.org/D125105 --- flang/lib/Evaluate/intrinsics.cpp | 3 ++- flang/test/Evaluate/folding02.f90 | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp index 5c0a2eaaf8a9..83c505353988 100644 --- a/flang/lib/Evaluate/intrinsics.cpp +++ b/flang/lib/Evaluate/intrinsics.cpp @@ -725,7 +725,8 @@ static const IntrinsicInterface genericIntrinsicFunction[]{ {"shifta", {{"i", SameInt}, {"shift", AnyInt}}, SameInt}, {"shiftl", {{"i", SameInt}, {"shift", AnyInt}}, SameInt}, {"shiftr", {{"i", SameInt}, {"shift", AnyInt}}, SameInt}, - {"sign", {{"a", SameIntOrReal}, {"b", SameIntOrReal}}, SameIntOrReal}, + {"sign", {{"a", SameInt}, {"b", AnyInt}}, SameInt}, + {"sign", {{"a", SameReal}, {"b", AnyReal}}, SameReal}, {"sin", {{"x", SameFloating}}, SameFloating}, {"sind", {{"x", SameFloating}}, SameFloating}, {"sinh", {{"x", SameFloating}}, SameFloating}, diff --git a/flang/test/Evaluate/folding02.f90 b/flang/test/Evaluate/folding02.f90 index 32a465051581..6374be35286c 100644 --- a/flang/test/Evaluate/folding02.f90 +++ b/flang/test/Evaluate/folding02.f90 @@ -22,8 +22,8 @@ module m ! Expected values come from libpgmath-precise for Real(4) and Real(8) and ! were computed on X86_64. - logical, parameter :: test_sign_i4 = sign(1_4,2_4) == 1_4 .and. sign(1_4,-3_4) == -1_4 - logical, parameter :: test_sign_i8 = sign(1_8,2_8) == 1_8 .and. sign(1_8,-3_8) == -1_8 + logical, parameter :: test_sign_i4 = sign(1_4,2) == 1_4 .and. sign(1_4,-3_8) == -1_4 + logical, parameter :: test_sign_i8 = sign(1_8,2) == 1_8 .and. sign(1_8,-3_8) == -1_8 ! Real scalar intrinsic function tests #define TEST_FLOATING(name, result, expected, t, k) \ @@ -67,7 +67,7 @@ module m TEST_R4(log_gamma, log_gamma(3.5_4), 1.20097362995147705078125_4) TEST_R4(mod, mod(-8.1_4, 5._4), (-3.1000003814697265625_4)) TEST_R4(real, real(z'3f800000'), 1._4) - logical, parameter :: test_sign_r4 = sign(1._4,2._4) == 1._4 .and. sign(1._4,-2._4) == -1._4 + logical, parameter :: test_sign_r4 = sign(1._4,2._8) == 1._4 .and. sign(1._4,-2._4) == -1._4 TEST_R4(sin, sin(1.6_4), 0.99957358837127685546875_4) TEST_R4(sinh, sinh(0.9_4), 1.0265166759490966796875_4) TEST_R4(sqrt, sqrt(1.1_4), 1.0488088130950927734375_4) @@ -116,7 +116,7 @@ module m TEST_R8(mod, mod(-8.1_8, 5._8), & (-3.0999999999999996447286321199499070644378662109375_8)) TEST_R8(real, real(z'3ff0000000000000',8), 1._8) - logical, parameter :: test_sign_r8 = sign(1._8,2._8) == 1._8 .and. sign(1._8,-2._8) == -1._8 + logical, parameter :: test_sign_r8 = sign(1._8,2._8) == 1._8 .and. sign(1._8,-2._4) == -1._8 TEST_R8(sin, sin(1.6_8), & 0.99957360304150510987852840116829611361026763916015625_8) TEST_R8(sinh, sinh(0.9_8), &