Skip to content

Commit 1c34450

Browse files
authored
[flang] Accept distinct kinds of arguments to IAND/IEOR/IOR (#69782)
As is already supported as a common extension for intrinsic functions like DIM, allow distinct kinds of integer actual arguments to the MIL-STD bit intrinsic functions IAND, IEOR, and IOR, with the kind of the result being the largest of the kinds of the operands. (Though one could make a case that IAND should return the smallest kind of its operands, that's not what other compilers do.)
1 parent 9a847fe commit 1c34450

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

flang/docs/Extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ end
177177
or `EXTENDEDTYPE(PARENTTYPE=PARENTTYPE(1,2,3))`).
178178
* Some intrinsic functions are specified in the standard as requiring the
179179
same type and kind for their arguments (viz., ATAN with two arguments,
180-
ATAN2, DIM, HYPOT, MAX, MIN, MOD, and MODULO);
180+
ATAN2, DIM, HYPOT, IAND, IEOR, IOR, MAX, MIN, MOD, and MODULO);
181181
we allow distinct types to be used, promoting
182182
the arguments as if they were operands to an intrinsic `+` operator,
183183
and defining the result type accordingly.

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ static constexpr TypePattern SameType{AnyType, KindCode::same};
170170
// an intrinsic operation like addition. This is a nonstandard but nearly
171171
// universal extension feature.
172172
static constexpr TypePattern OperandReal{RealType, KindCode::operand};
173+
static constexpr TypePattern OperandInt{IntType, KindCode::operand};
173174
static constexpr TypePattern OperandIntOrReal{IntOrRealType, KindCode::operand};
174175

175176
// For ASSOCIATED, the first argument is a typeless pointer
@@ -517,13 +518,15 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
517518
SameInt, Rank::dimReduced, IntrinsicClass::transformationalFunction},
518519
{"iparity", {{"array", SameInt, Rank::array}, MissingDIM, OptionalMASK},
519520
SameInt, Rank::scalar, IntrinsicClass::transformationalFunction},
520-
{"iand", {{"i", SameInt}, {"j", SameInt, Rank::elementalOrBOZ}}, SameInt},
521+
{"iand", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}},
522+
OperandInt},
521523
{"iand", {{"i", BOZ}, {"j", SameInt}}, SameInt},
522524
{"ibclr", {{"i", SameInt}, {"pos", AnyInt}}, SameInt},
523525
{"ibits", {{"i", SameInt}, {"pos", AnyInt}, {"len", AnyInt}}, SameInt},
524526
{"ibset", {{"i", SameInt}, {"pos", AnyInt}}, SameInt},
525527
{"ichar", {{"c", AnyChar}, DefaultingKIND}, KINDInt},
526-
{"ieor", {{"i", SameInt}, {"j", SameInt, Rank::elementalOrBOZ}}, SameInt},
528+
{"ieor", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}},
529+
OperandInt},
527530
{"ieor", {{"i", BOZ}, {"j", SameInt}}, SameInt},
528531
{"image_status", {{"image", SameInt}, OptionalTEAM}, DefaultInt},
529532
{"index",
@@ -533,7 +536,8 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
533536
KINDInt},
534537
{"int", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}, KINDInt},
535538
{"int_ptr_kind", {}, DefaultInt, Rank::scalar},
536-
{"ior", {{"i", SameInt}, {"j", SameInt, Rank::elementalOrBOZ}}, SameInt},
539+
{"ior", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}},
540+
OperandInt},
537541
{"ior", {{"i", BOZ}, {"j", SameInt}}, SameInt},
538542
{"ishft", {{"i", SameInt}, {"shift", AnyInt}}, SameInt},
539543
{"ishftc",

0 commit comments

Comments
 (0)