aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Evaluate/intrinsics.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-06-18[flang] Fold IEEE_SUPPORT_xxx() intrinsic functions (#95866)Peter Klausler1-0/+25
All of the IEEE_SUPPORT_xxx() intrinsic functions must fold to constant logical values when they have constant arguments; and since they fold to .TRUE. for currently support architectures, always fold them. But also put in the infrastructure whereby a driver can initialize Evaluate's target information to set some of them to .FALSE. if that becomes necessary.
2024-06-17[Flang] Switch to common::visit more call sites (#90018)Alexander Shaposhnikov1-1/+1
Switch to common::visit more call sites. Test plan: ninja check-all
2024-06-13[flang] Catch NULL(MOLD=assumed-rank) (#95270)Peter Klausler1-0/+4
An assumed-rank dummy argument is not an acceptable MOLD argument to NULL(), whose result must have a known rank at compilation time.
2024-06-06[flang] Add GETCWD runtime and lowering intrinsics implementation (#92746)jiajie zhang1-1/+11
This patch add support of intrinsics GNU extension GETCWD https://github.com/llvm/llvm-project/issues/84203. Some usage info and example has been added to `flang/docs/Intrinsics.md`. The patch contains both the lowering and the runtime code and works on both Windows and Linux. | System | Implmentation | |-----------|--------------------| | Windows | _getcwd | | Linux |getcwd |
2024-06-04[flang] relax ASSOCIATED checks for assumed-ranks (#94277)jeanPerier1-2/+3
Nothing in the standard actually prevents TARGET from being an assumed-rank if the POINTER is. The only rank related constraints says: "POINTER is not assumed-rank, TARGET shall have the same rank as POINTER.".
2024-06-03[flang] Improve handling of NULL() arguments to intrinsics (#93866)Peter Klausler1-29/+37
Some intrinsics (extends_type_of, same_type_as) can accept a NULL actual argument so long as it has a MOLD=. Some intrinsics that are marked in the intrinsics table as accepting a NULL actual argument already should only do so if it has a MOLD=. Distinguish table entries that accept a NULL() only with a MOLD= from the few others that allow a bare NULL() and update tests. Fixes https://github.com/llvm/llvm-project/issues/93845.
2024-06-03[flang] Better error message for RANK(NULL()) (#93577)Peter Klausler1-0/+5
We currently complain that the argument may not be a procedure, which is confusing. Distinguish the NULL() case from other error cases (which are indeed procedures). And clean up the utility predicates used for these tests -- the current IsProcedure() is really just a test for a procedure designator.
2024-05-18[reland][flang] Add ETIME runtime and lowering intrinsics implementation ↵jiajie zhang1-2/+24
(#92571) This is same as https://github.com/llvm/llvm-project/pull/90578 with an added fix. This PR updated tests of etime intrinsic due to Lowering changes for assigning dummy_scope to hlfir.declare. Referring to https://github.com/llvm/llvm-project/pull/92472 and https://github.com/llvm/llvm-project/pull/90989
2024-05-15Revert "[flang] Add ETIME runtime and lowering intrinsics implementation" ↵Mehdi Amini1-24/+2
(#92354) Reverts llvm/llvm-project#90578 This broke the premerge linux buildbot.
2024-05-16[flang] Add ETIME runtime and lowering intrinsics implementation (#90578)jiajie zhang1-2/+24
This patch add support of intrinsics GNU extension ETIME https://github.com/llvm/llvm-project/issues/84205. Some usage info and example has been added to `flang/docs/Intrinsics.md`. The patch contains both the lowering and the runtime code and works on both Windows and Linux. | System | Implmentation | |-----------|--------------------| | Windows| GetProcessTimes | | Linux |times |
2024-05-01[flang] Ensure all warning/portability messages are guarded by Should… ↵Peter Klausler1-10/+17
(#90518) …Warn() Many warning messages were being emitted unconditionally. Ensure that all warnings are conditional on a true result from a call to common::LanguageFeatureControl::ShouldWarn() so that it is easy for a driver to disable them all, or, in the future, to provide per-warning control over them.
2024-04-24[flang] Catch error on REPEAT(x,NCOPIES=array) (#89993)Peter Klausler1-1/+3
The NCOPIES= argument to the intrinsic function REPEAT must be a scalar integer. Fixes https://github.com/llvm/llvm-project/issues/89851.
2024-04-22[flang] C_LOC is PURE (#89437)Peter Klausler1-1/+2
The standard defines C_LOC as being PURE (actually SIMPLE now in F'2023); characterize it appropriately. Fixes https://github.com/llvm/llvm-project/issues/88747.
2024-04-08[flang] Clean up ISO_FORTRAN_ENV, fix NUMERIC_STORAGE_SIZE (#87566)Peter Klausler1-2/+3
Address TODOs in the intrinsic module ISO_FORTRAN_ENV, and extend the implementation of NUMERIC_STORAGE_SIZE so that the calculation of its value is deferred until it is needed so that the effects of -fdefault-integer-8 or -fdefault-real-8 are reflected. Emit a warning when NUMERIC_STORAGE_SIZE is used from the module file and the default integer and real sizes do not match. Fixes https://github.com/llvm/llvm-project/issues/87476.
2024-03-05[flang] NULL(NULL(NULL(...(NULL()...))) means NULL() (#83738)Peter Klausler1-10/+23
When the actual MOLD= argument of a reference to the intrinsic function NULL is itself just NULL() (possibly nested), treat the MOLD= as if it had not been present. Fixes https://github.com/llvm/llvm-project/issues/83572.
2024-03-01[flang] Support INDEX as a procedure interface (#83073)Peter Klausler1-0/+12
The specific intrinsic function INDEX should work as a PROCEDURE interface in the declaration of a procedure pointer or dummy procedure, and it should be compatible with a user-defined interface. Fixes https://github.com/llvm/llvm-project/issues/82397.
2024-02-05[flang] Fix for atand(Y,X), and implment atan2d(Y,X), atanpi(X), ↵Yi Wu1-1/+4
atanpi(Y,X), atan2pi(Y,X) (#79002) Fix: https://github.com/llvm/llvm-project/issues/78568 --------- Co-authored-by: jeanPerier <jean.perier.polytechnique@gmail.com>
2024-01-30[flang] Add image_index to list of intrinsics and add tests (#79519)Katherine Rasmussen1-1/+12
Add image_index to the list of intrinsic functions and add additional check on its args in check-call.cpp. Add two semantics tests for image_index.
2024-01-29[flang] add SYSTEM runtime and lowering intrinsics support (#74309)Yi Wu1-0/+5
Calls std::system() function and pass the command, cmd on Windows or shell on Linux. Command parameter is required, exitstatus is optional. call system(command) call system(command, exitstatus) It calls `execute_command_line` runtime function with `wait` set to true. --------- Co-authored-by: Yi Wu <yiwu02@wdev-yiwu02.arm.com>
2024-01-29Apply kind code check on exitstat and cmdstat (#78286)Yi Wu1-7/+14
When testing on gcc, both exitstat and cmdstat must be a kind=4 integer, e.g. DefaultInt. This patch changes the input arg requirement from `AnyInt` to `TypePattern{IntType, KindCode::greaterOrEqualToKind, n}`. The standard stated in 16.9.73 - EXITSTAT (optional) shall be a scalar of type integer with a decimal exponent range of at least nine. - CMDSTAT (optional) shall be a scalar of type integer with a decimal exponent range of at least four. ```fortran program bug implicit none integer(kind = 2) :: exitstatvar integer(kind = 4) :: cmdstatvar character(len=256) :: msg character(len=:), allocatable :: command command='echo hello' call execute_command_line(command, exitstat=exitstatvar, cmdstat=cmdstatvar) end program ``` When testing the above program with exitstatvar kind<4, an error would occur: ``` $ ../build-release/bin/flang-new test.f90 error: Semantic errors in test.f90 ./test.f90:8:47: error: Actual argument for 'exitstat=' has bad type or kind 'INTEGER(2)' call execute_command_line(command, exitstat=exitstatvar) ``` When testing the above program with exitstatvar kind<2, an error would occur: ``` $ ../build-release/bin/flang-new test.f90 error: Semantic errors in test.f90 ./test.f90:8:47: error: Actual argument for 'cmdstat=' has bad type or kind 'INTEGER(1)' call execute_command_line(command, cmdstat=cmdstatvar) ``` Test file for this semantics has been added to `flang/test/Semantic` Fixes: https://github.com/llvm/llvm-project/issues/77990
2024-01-26[flang][Runtime] Add SIGNAL intrinisic (#79337)Tom Eccles1-0/+12
The intrinsic is defined as a GNU extension here: https://gcc.gnu.org/onlinedocs/gfortran/SIGNAL.html And as an IBM extension here: https://www.ibm.com/docs/en/xffbg/121.141?topic=procedures-signali-proc-extension The IBM version provides a compatible subset of the functionality offered by the GNU version. This patch supports most of the GNU features, but not calling SIGNAL as a function. We don't currently support intrinsics being both subroutines AND functions and this changed seemed too large to be justified by a non-standard intrinsic. I cannot point to open source code Fortran using this intrinsic. This is needed for a proprietary code base.
2024-01-26[flang][runtime] Implement SLEEP intrinsic (#79074)Tom Eccles1-0/+4
This intrinsic is a gnu extension. See https://gcc.gnu.org/onlinedocs/gfortran/SLEEP.html This intrinsic is used in minighost: https://github.com/Mantevo/miniGhost/blob/c2102b521568a74862fa5abb074b1fc8041fc222/ref/MG_UTILS.F#L606
2024-01-25[flang] Support KNINT and KIDNNT legacy intrinsic functions (#79190)Peter Klausler1-0/+6
These specific intrinsic functions are legacy names that map to the standard generic NINT(..., KIND=8).
2024-01-25[flang] Don't create impossible conversions in intrinsic extension (#79042)Peter Klausler1-15/+23
We support specific intrinsic calls like `AMAX0(1.0,2)` that have heterogeneous argument types as an optional extension in cases where the specific intrinsic has a related generic intrinsic function capable of handling the argument types. This feature can't be allowed to apply to calls where the result of the related generic intrinsic function is not convertible to the type of the specific intrinsic, as in `AMAX0('a', 'b')`. Fixes https://github.com/llvm/llvm-project/issues/78932.
2024-01-25[flang] Correct checking of PRESENT() (#78364)Peter Klausler1-16/+0
The argument to the PRESENT() intrinsic function must be the name of a a whole OPTIONAL dummy argument. Fixes llvm-test-suite/Fortran/gfortran/regression/present_1.f90.
2024-01-25[flang] Add warnings for non-standard C_F_POINTER() usage (#78332)Peter Klausler1-4/+19
There's a few restrictions in the standard on the Fortran pointer argument (FPTR=) to the intrinsic subroutine C_F_POINTER() that almost no compilers enforce. Enforce them here with warnings.
2024-01-15[flang] Fix semantic checks for MOVE_ALLOC (#77362)Peter Klausler1-48/+14
The checking of calls to the intrinsic subroutine MOVE_ALLOC is not insisting that its first two arguments be whole allocatable variables or components. Fix, move the code into check-calls.cpp (a better home for such things), and clean up the tests. Fixes https://github.com/llvm/llvm-project/issues/77230.
2023-11-30[flang] Move and extend REDUCE() compile-time checking (#72570)Peter Klausler1-87/+30
Move the code to check the arguments of references to the intrinsic function REDUCE() into Semantics/check-calls.cpp, and add checks for several requirements from the standard that weren't yet caught.
2023-11-13[flang] Ensure that portability warnings are conditional (#71857)Peter Klausler1-28/+40
Before emitting a warning message, code should check that the usage in question should be diagnosed by calling ShouldWarn(). A fair number of sites in the code do not, and can emit portability warnings unconditionally, which can confuse a user that hasn't asked for them (-pedantic) and isn't terribly concerned about portability *to* other compilers. Add calls to ShouldWarn() or IsEnabled() around messages that need them, and add -pedantic to tests that now require it to test their portability messages, and add more expected message lines to those tests when -pedantic causes other diagnostics to fire.
2023-11-13[flang] Allow polymorphic actual to implicit interface (#70873)Peter Klausler1-2/+2
Semantics is emitting an error when an actual argument to a procedure that has an implicit interface has a polymorphic type. This is too general; while TYPE(*) and CLASS(*) unlimited polymorphic items require the presence of an explicit procedure interface, CLASS(T) data can be passed over an implicit interface to a procedure expecting a corresponding dummy argument with TYPE(T), so long as T is not parameterized. (Only XLF handles this usage correctly among other Fortran compilers.) (Making this work in the case of an actual CLASS(T) array may well require additional changes in lowering to copy data to/from a temporary buffer to ensure contiguity when the actual type of the array is an extension of T.)
2023-11-13[flang] GETPID runtime and lower intrinsic implementation (#70442)Yi Wu1-0/+1
Runtime function GetPID calls the function getpid from unistd.h or process.h base on the OS.
2023-10-31[flang] Accept distinct kinds of arguments to IAND/IEOR/IOR (#69782)Peter Klausler1-3/+7
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.)
2023-10-23[flang] Place MIN/MAX A1/A2 first in semantic analysis (#69722)jeanPerier1-72/+62
Intrinsic analysis in semantics reorder the actual arguments so that they match the dummy order. This was not done for MIN/MAX because they are special: these are the only intrinsics with a variadic number of arguments. This caused bugs in lowering that only check the optionality of actual arguments from the third position (since A1 and A2 are mandatory). Update semantics to place A1/A2 first. This also allow removing some checks that were specific to MIN/MAX. There is no point in sorting/placing the rest of the arguments which would be tedious and tricky because of the variadic aspect.
2023-09-18[flang] Accept pointer-valued function results as ASSOCIATED() arguments ↵Peter Klausler1-3/+3
(#66238) The POINTER= and TARGET= arguments to the intrinsic function ASSOCIATED() can be the results of references to functions that return object pointers or procedure pointers. NULL() was working well but not program-defined pointer-valued functions. Correct the validation of ASSOCIATED() and extend the infrastructure used to detect and characterize procedures and pointers.
2023-09-13[flang] Accept ALLOCATED(ARRAY=assumedRank) (#66233)Peter Klausler1-2/+2
The definitions of the ALLOCATED intrinsic in the intrinsics table did not allow for an assumed-rank array.
2023-09-11[flang] Improve length information in character transformational (#65771)jeanPerier1-1/+9
Intrinsic resolution currently does not resolve constant length information for character transformational (with "sameChar") where the argument has constant length but is not a variable or a constant expression. It is not required to fold those expressions (only inquiry on constant expression or variable with constant length is required to be a constant expression). But constant length information for character is valuable for lowering, so I think this is a nice and easy to have.
2023-08-29[flang] Check procedure pointer initializations; clean up ELEMENTALPeter Klausler1-1/+1
Implements compatibility checking for initializers in procedure pointer declarations. This work exposed some inconsistency in how ELEMENTAL interfaces were handled and checked, from both unrestricted intrinsic functions and others, and some refinements needed for function result compatbility checking; these have also been ironed out. Some new warnings are now emitted, and this affected a dozen or so tests. Differential Revision: https://reviews.llvm.org/D159026
2023-08-29[flang] Support SELECT RANK on allocatables & pointersPeter Klausler1-1/+1
Unlike other executable constructs with associating selectors, the selector of a SELECT RANK construct can have the ALLOCATABLE or POINTER attribute, and will work as an allocatable or object pointer within each rank case, so long as there is no RANK(*) case. Getting this right exposed a correctness risk with the popular predicate IsAllocatableOrPointer() -- it will be true for procedure pointers as well as object pointers, and in many contexts, a procedure pointer should not be acceptable. So this patch adds the new predicate IsAllocatableOrObjectPointer(), and updates some call sites of the original function to use the new one. Differential Revision: https://reviews.llvm.org/D159043
2023-08-29[flang] Support SELECTED_LOGICAL_KIND() up to loweringPeter Klausler1-0/+2
Process and fold the new F'2023 intrinsic function SELECTED_LOGICAL_KIND. Differential Revision: https://reviews.llvm.org/D159039
2023-08-29[flang] Better error recovery when using erroneous procedures and pointers ↵Peter Klausler1-9/+9
as intrinsic actual arguments Instead of crashing with an internal error when a procedure or procedure pointer with a badly declared interface is presented to an intrinsic procedure like ASSOCIATED, emit an error message and continue with compilation. Differential Revision: https://reviews.llvm.org/D159028
2023-07-21[flang] Accept an assumed-rank array as operand of ASSOCIATED()Peter Klausler1-3/+10
The ASSOCIATED() intrinsic was mistakenly defined in the intrinsic function table as requiring operands of known rank, which unintentionally prevented assumed-rank dummy arguments from being tested. Fixes llvm-test-suite/Fortran/gfortran/regression/pr88932.f90. Differential Revision: https://reviews.llvm.org/D155498
2023-07-17[flang] Catch impure specifics called in DO CONCURRENTPeter Klausler1-0/+4
Rework the code used to check for calls to impure procedures in DO CONCURRENT constructs. The current code wasn't checking the representation of the procedure references in the strongly typed expressions, so it was missing calls to impure subprograms made via generic interfaces. While here, improve error messages, and fix some minor issues exposed by testing the improved checks. Differential Revision: https://reviews.llvm.org/D155489
2023-06-06[Flang] Map `ieee_fma` intrinsic to `llvm.fma`Shao-Ce SUN1-0/+2
Map `ieee_fma` intrinsic to LLVM IR as `llvm.fma`. Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D151872
2023-06-01Flang implementation for COMPILER_VERSION and COMPILER_OPTIONS intrinsicsHussain Kadhem1-1/+8
This revision implements the Fortran intrinsic procedures COMPILER_VERSION and COMPILER_OPTIONS from the iso_fortran_env module. To be able to set the COMPILER_OPTIONS string according to the original compiler driver invocation, a string is passed to the frontend driver using the environment variable FLANG_COMPILER_OPTIONS_STRING, for lack of a better mechanism. Fixes #59233 Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D140524
2023-05-08[flang] Semantics for ISO_C_BINDING's C_LOC()Peter Klausler1-18/+81
Make __builtin_c_loc() into an intrinsic function and verify the special semantic requirements on its actual arguments. Differential Revision: https://reviews.llvm.org/D149988
2023-04-16[flang] Apply fixes from readability-string-compare (NFC)Kazu Hirata1-2/+2
2023-04-03[flang] Don't allow CALL RANDOM_NUMBER(assumed-size-array)Peter Klausler1-6/+16
The extents, if any, of the HARVEST= actual argument must be known at execution time for the call to be implemented. Differential Revision: https://reviews.llvm.org/D147391
2023-04-03[flang] NORM2(DIM=) argument can't be dynamically optionalPeter Klausler1-1/+3
The intrinsic function table entry for NORM2 treats its DIM= argument as if it can be dynamically optional; this is wrong, and it should be treated in the same way as DIM= is for other transformational intrinsic functions like SUM. Differential Revision: https://reviews.llvm.org/D147390
2023-03-28[flang] Disallow scalar argument to SIZE/LBOUND/UBOUNDPeter Klausler1-8/+17
The compiler accepts arguments of any rank, or assumed rank, to a host of intrinsic inquiry functions. For scalars, this is correct for most of them, but the standard (and other compilers) prohibit scalar arguments to SIZE, LBOUND, and UBOUND (without DIM=). There are meaningful interpretations for these intrinsic inquiries on scalars, but since there's no portability concern here, continuing to support them would be an unjustifiable extension. Differential Revision: https://reviews.llvm.org/D146587
2023-03-27[flang] Emit error when a positional actual argument follows an argument ↵Peter Klausler1-11/+25
with a keyword A positional (non-keyword) actual argument or alternate return label is not allowed to follow an actual argument with a keyword. Differential Revision: https://reviews.llvm.org/D146575