aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/check-declarations.cpp
AgeCommit message (Collapse)AuthorFilesLines
2 days[flang][CUDA] Apply intrinsic operator overrides (#151018)Peter Klausler1-2/+2
Fortran's intrinsic numeric and relational operators can be overridden with explicit interfaces so long as one or more of the dummy arguments have the DEVICE attribute. Semantics already allows this without complaint, but fails to replace the operations with the defined specific procedure calls when analyzing expressions.
2025-07-16[flang] Catch bad members of BIND(C) COMMON block (#148971)Peter Klausler1-11/+37
Variables that can't be BIND(C), like pointers, can't be in a BIND(C) common block, either. Fixes https://github.com/llvm/llvm-project/issues/148922.
2025-06-11[flang] silence bogus error with BIND(C) variable in hermetic module (#143737)jeanPerier1-0/+10
The global name semantic check was firing in a bogus way when BIND(C) variables are in hermetic module. Do not raise the error if one of the symbol with the conflicting global name is an "hermetic variant" of the other.
2025-06-04[flang] Extension: allow override of inaccessible DEFERRED binding (#142691)Peter Klausler1-3/+6
Inaccessible procedure bindings can't be overridden, but DEFERRED bindings must be in a non-abstract extension. We presently emit an error for an attempt to override an inaccessible binding in this case. But some compilers accept this usage, and since it seems safe enough, I'll allow it with an optional warning. Codes can avoid this warning and conform to the standard by changing the deferred bindings to be public.
2025-05-13[flang] Fix spurious error on defined assignment in PURE (#139186)Peter Klausler1-2/+2
An assignment to a whole polymorphic object in a PURE subprogram that is implemented by means of a defined assignment procedure shouldn't be subjected to the same definability checks as it would be for an intrinsic assignment (which would also require it to be allocatable). Fixes https://github.com/llvm/llvm-project/issues/139129.
2025-05-12[flang] Stricter checking of v_list DIO arguments (#139329)Peter Klausler1-4/+11
Catch assumed-rank arguments to defined I/O subroutines, and ensure that v_list dummy arguments are vectors. Fixes https://github.com/llvm/llvm-project/issues/138933.
2025-05-12[flang] Emit error when DEFERRED binding overrides non-DEFERRED (#139325)Peter Klausler1-3/+9
Fixes https://github.com/llvm/llvm-project/issues/138915.
2025-05-02[flang] fix scoping of cray pointer declarations and add check for ↵Andre Kuhlenschmidt1-1/+12
initialization (#136776) This PR: - makes Cray pointer declarations shadow previous bindings instead of modifying them, - errors when the pointee of a cray pointee has the SAVE attribute, and - adds a missing newline after dumping the list of cray pointers in a scope. Closes #135579
2025-03-19[flang] Exempt construct entities from SAVE check for PURE (#131383)Peter Klausler1-1/+4
A PURE subprogram can't have a local variable with the SAVE attribute. An ASSOCIATE or SELECT TYPE construct entity whose selector is a variable will return true from IsSave(); exclude them from the local variable check. Fixes https://github.com/llvm/llvm-project/issues/131356.
2025-03-19[flang] Dig deeper to find more EVENT_TYPE/LOCK_TYPE misuse (#130687)Peter Klausler1-0/+14
Only objects may have these types, or have potential subobject components with these types.
2025-03-10[flang] Catch disallowed usage of coarrays in defined I/O (#129907)Peter Klausler1-1/+8
Defined input/output subroutines must conform to documented interfaces that do not allow for coarray dummy arguments.
2025-03-03[flang] Improve two coarray error messages (#129597)Peter Klausler1-2/+3
Two messages that complain about local variables mention that they don't have the SAVE attribute; in both cases, it would be okay if they were ALLOCATABLE instead. Clarify the messages.
2025-03-03[flang] Refine checking of type-bound generics (#129292)Peter Klausler1-6/+13
I merged a patch yesterday (https://github.com/llvm/llvm-project/pull/128980) that strengthened error detection of indistinguishable specific procedures in a type-bound generic procedure, and broke a couple of tests. Refine the check so that it doesn't flag valid cases of overridden bindings, and add a thorough test with all of the boundary cases that I can think of.
2025-02-27[flang] Catch more defined I/O conflicts (#129115)Peter Klausler1-21/+34
The code that checks for conflicts between type-bound defined I/O generic procedures and non-type-bound defined I/O interfaces only works when then procedures are defined in the same module as subroutines. It doesn't catch conflicts when either are external procedures, procedure pointers, dummy procedures, &c. Extend the checking to cover those cases as well. Fixes https://github.com/llvm/llvm-project/issues/128752.
2025-02-27[flang] Fix a warningKazu Hirata1-1/+0
This patch fixes: flang/lib/Semantics/check-declarations.cpp:2009:15: error: unused variable 'kind' [-Werror,-Wunused-variable]
2025-02-27[flang] Catch type-bound generic with inherited indistinguishable spe… ↵Peter Klausler1-5/+38
(#128980) …cific When checking generic procedures for indistinguishable specific procedures, don't neglect to include specific procedures from any accessible instance of the generic procedure inherited from its parent type.. Fixes https://github.com/llvm/llvm-project/issues/128760.
2025-02-27[flang] Enforce C1503 (#128962)Peter Klausler1-0/+8
Enforce an obscure constraint from the standard: an abstract interface is not allowed to have the same name as an intrinsic type keyword. I suspect this is meant to prevent a declaration like "PROCEDURE(REAL), POINTER :: P" from being ambiguous. Fixes https://github.com/llvm/llvm-project/issues/128744.
2025-02-27[flang] Silence spurious error (#128777)Peter Klausler1-3/+4
When checking for conflicts between type-bound generic defined I/O procedures and non-type-bound defined I/O generic interfaces, don't worry about conflicts where the type-bound generic interface is inaccessible in the scope around the non-type-bound interface. Fixes https://github.com/llvm/llvm-project/issues/126797.
2025-02-27[flang] Fix bogus error on defined I/O procedure. (#125898)Peter Klausler1-19/+11
The check that "v_list" be deferred shape is just wrong; there are no deferred shape non-pointer non-allocatable dummy arguments in Fortran. Correct to check for an assumed shape dummy argument. And de-split the error messages that were split across multiple source lines, making them much harder to find with grep. Fixes https://github.com/llvm/llvm-project/issues/125878.
2025-02-27[flang] Catch more semantic errors with coarrays (#125536)Peter Klausler1-18/+80
Detect and report a bunch of uncaught semantic errors with coarray declarations. Add more tests, and clean up bad usage in existing tests.
2025-02-06[flang][cuda] Allow POINTER component to have device attribute (#126116)Valentin Clement (バレンタイン クレメン)1-2/+2
2025-01-27[flang] Catch assumed-length interoperability error (#124179)Peter Klausler1-4/+5
An assumed-length character dummy argument is interoperable only if it is neither a pointer nor allocatable.
2025-01-27[flang] Refine EVENT_TYPE/LOCK_TYPE usage checks (#123244)Peter Klausler1-1/+14
The event variable in an EVENT POST/WAIT statement can be a coarray reference, and need not be an entire coarray. Variables and potential subobject components with EVENT_TYPE/LOCK_TYPE must be coarrays, unless they are potential subobjects nested within coarrays or pointers.
2025-01-14[flang] Fix spurious error message due to inaccessible generic binding (#122810)Peter Klausler1-0/+3
Generic operator/assignment checks for distinguishable specific procedures must ignore inaccessible generic bindings. Fixes https://github.com/llvm/llvm-project/issues/122764.
2024-12-02[flang] Allow a few irrelevant attributes, with warning (#117374)Peter Klausler1-2/+8
INTENT, VALUE, and OPTIONAL attributes apply only to dummy arguments. A couple older compilers accept them, usually with a warning, if they are applied to names that are not dummy arguments, and they show up in some older non-portable source code. Change these cases into stern warnings by default.
2024-11-19[flang] Silence bogus error on local proc pointer initializer (#116663)Peter Klausler1-5/+7
A procedure pointer is allowed to be initialized with the subprogram in which it is local, assuming that other requirements are satisfied. Add a good test for local procedure pointer initialization, as no test existed for the error message in question. Fixes https://github.com/llvm/llvm-project/issues/116566.
2024-11-14[flang] Soften interoperability error when standard allows (#115092)Peter Klausler1-5/+18
The standard doesn't require that an interoperable procedure's dummy arguments have interoperable derived types in some cases. Although nearly all extant Fortran compilers emit errors, some don't, and things should work; so reduce the current fatal error message to an optional portability warning. Fixes https://github.com/llvm/llvm-project/issues/115010.
2024-11-06[flang][cuda] Do not emit warning for SHARED variable in device subprogram ↵Valentin Clement (バレンタイン クレメン)1-1/+3
(#115195) SHARED attribute is explicitly meant to be used in device subprogram (https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#cfpg-var-qual-attr-shared). Do not emit warning.
2024-10-07[flang] Finer error detection in separate module procedure case (#110912)Peter Klausler1-3/+11
When a separate module procedure has a dummy procedure argument that is simply declared EXTERNAL in its interface but is actually called as a subroutine or function in its definition, the compiler is emitting an error message. This is too strong; an error is appropriate only when the dummy procedure in the definition has an interface that is incompatible with the one in the interface definition. However, this is not a safe coding practice, and can lead to trouble during execution if a function is passed as an actual argument but called as a subroutine in the procedure (or the other way around), so add a warning message as well for this case (off by default). Fixes https://github.com/llvm/llvm-project/issues/110797.
2024-10-02[flang] Tag warnings with LanguageFeature or UsageWarning (#110304)Peter Klausler1-204/+155
(This is a big patch, but it's nearly an NFC. No test results have changed and all Fortran tests in the LLVM test suites work as expected.) Allow a parser::Message for a warning to be marked with the common::LanguageFeature or common::UsageWarning that controls it. This will allow a later patch to add hooks whereby a driver will be able to decorate warning messages with the names of its options that enable each particular warning, and to add hooks whereby a driver can map those enumerators by name to command-line options that enable/disable the language feature and enable/disable the messages. The default settings in the constructor for LanguageFeatureControl were moved from its header file into its C++ source file. Hooks for a driver to use to map the name of a feature or warning to its enumerator were also added. To simplify the tagging of warnings with their corresponding language feature or usage warning, to ensure that they are properly controlled by ShouldWarn(), and to ensure that warnings never issue at code sites in module files, two new Warn() member function templates were added to SemanticsContext and other contextual frameworks. Warn() can't be used before source locations can be mapped to scopes, but the bulk of existing code blocks testing ShouldWarn() and FindModuleFile() before calling Say() were convertible into calls to Warn(). The ones that were not convertible were extended with explicit calls to Message::set_languageFeature() and set_usageWarning().
2024-09-18[flang] Fix subtle type naming bug in module file output (#108892)Peter Klausler1-1/+1
A derived type specification in semantics holds both its source name (for location purposes) and its ultimate derived type symbol. But for correct module file generation of a structure constructor using that derived type spec, the original symbol may be needed so that USE association can be exposed. Save both the original symbol and its ultimate symbol in the DerivedTypeSpec, and collect the right one when traversing expressions (specifically for handling initialization in module files). Fixes https://github.com/llvm/llvm-project/issues/108827.
2024-09-12[flang] Downgrade error message to warning (#108115)Peter Klausler1-2/+5
It is a non-mandatory error to reference an external procedure via an implicit interface declaration (EXTERNAL or PROCEDURE()) when the external procedure has an interface that requires the presence of an explicit interface to be called. Until now, the compiler has issued a fatal error message from semantics for this situation. But (1) there are situations, such as passing such an EXTERNAL as an actual argument, or as the target of a procedure pointer assignment, where little or no harm is done, (2) other compilers don't/can't detect this error, even when the procedure's definition is in the same source file, and (3) it shows up in some real applications. So downgrade this error to a stern warning. Perhaps in the future the compiler could resume emission of a hard error in the cases where the EXTERNAL procedure is actually known to be called via its implicit interface.
2024-09-10[flang] Silence spurious error on non-CUDA use of CUDA module (#107444)Peter Klausler1-8/+13
When a module file has been compiled with CUDA enabled, don't emit spurious errors about non-interoperable types when that module is read by a USE statement in a later non-CUDA compilation.
2024-08-26[flang] Silence spurious errors from benign USE errors (#106097)Peter Klausler1-0/+3
When USE association encounters a conflict that can't be resolved, it produces a "UseError" symbol that will trigger an error message if that symbol is ever actually used. UseError symbols that aren't used are benign. Ensure that UseError symbols don't run the gamut of declaration checking. They were getting through, and could lead to spurious error messages. Fixes https://github.com/llvm/llvm-project/issues/106020.
2024-08-08[flang] Fix searches for polymorphic components (#102212)Peter Klausler1-2/+3
FindPolymorphicAllocatableUltimateComponent needs to be FindPolymorphicAllocatablePotentialComponent. The current search is missing cases where a derived type has an allocatable component whose type has a polymorphic allocatable component.
2024-08-08[flang] Warn about automatic data in main program, disallow in BLOCK … ↵Peter Klausler1-4/+25
(#102045) …DATA We allow automatic data objects in the specification part of the main program; add an optional portability warning and documentation. Don't allow them in BLOCK DATA. They're already disallowed as module variables.
2024-07-30[flang] Detect use-before-decl errors on type parameters (#99947)Peter Klausler1-1/+1
Ensure that type parameters are declared as such before being referenced within the derived type definition. (Previously, such references would resolve to symbols in the enclosing scope.) This change causes the symbols for the type parameters to be created when the TYPE statement is processed in name resolution. They are TypeParamDetails symbols with no KIND/LEN attribute set, and they shadow any symbols of the same name in the enclosing scope. When the type parameter declarations are processed, the KIND/LEN attributes are set. Any earlier reference to a type parameter with no KIND/LEN attribute elicits an error. Some members of TypeParamDetails have been retyped &/or renamed.
2024-07-11[flang] Accept IGNORE_TKR in separate module procedure interface (#98374)Peter Klausler1-9/+6
We emit an incorrect error message when !DIR$ IGNORE_TKR appears in a separate module procedure's interface declaration. Fixes https://github.com/llvm/llvm-project/issues/98210.
2024-07-11[flang] Downgrade error message to a portability warning (#98368)Peter Klausler1-1/+1
f18 current emits an error when an assignment is made to an array section with a vector subscript, and the array is finalized with a non-elemental final subroutine. Some other compilers emit this error because (I think) they want variables to only be finalized in place, not by a subroutine call involving copy-in & copy-out of the finalized elements. Since many other Fortran compilers can handle this case, and there's nothing in the standards to preclude it, let's downgrade this error message to a portability warning. This patch got complicated because the API for the WhyNotDefinable() utility routine was such that it would return a message only in error cases, and there was no provision for returning non-fatal messages. It now returns either nothing, a fatal message, or a non-fatal warning message, and all of its call sites have been modified to cope.
2024-07-11[flang] Silence over-eager warning about interoperable character length (#97353)Peter Klausler1-2/+4
Make the results of the two IsInteroperableIntrinsicType() utility routines a tri-state std::optional<bool> so that cases where the character length is simply unknown can be distinguished from those cases where the length is known and not acceptable. Use this distinction to not emit a confusing warning about interoperability with C_LOC() arguments when the length is unknown and might well be acceptable during execution.
2024-06-24[flang] Add/fix some semantic checks for assumed-rank (#96194)Peter Klausler1-7/+11
Catch some cases where assumed rank dummy arguments are not allowed.
2024-06-24[flang] Silence errors on C_LOC/C_FUNLOC in specification expressions (#96108)Peter Klausler1-11/+9
Transformational functions from the intrinsic module ISO_C_BINDING are allowed in specification expressions, so tweak some general checks that would otherwise trigger error messages about inadmissible targets, dummy procedures in specification expressions, and pure procedures with impure dummy procedures.
2024-06-24[flang] harden TypeAndShape for assumed-ranks (#96234)jeanPerier1-0/+7
SIZEOF and C_SIZEOF were broken for assumed-ranks because `TypeAndShape::MeasureSizeInBytes` behaved as a scalar because the `TypeAndShape::shape_` member was the same for scalar and assumed-ranks. The easy fix would have been to add special handling in `MeasureSizeInBytes` for assumed-ranks using the TypeAndShape attributes, but I think this solution would leave `TypeAndShape::shape_` manipulation fragile to future developers. Hence, I went for the solution that turn shape_ into a `std::optional<Shape>`.
2024-06-11[flang] Allow interoperable object to have interoperable derived type… ↵Peter Klausler1-10/+8
(#94768) … that's not BIND(C) An interoperable BIND(C) object with a derived type should have a BIND(C) derived type, but will now work with a derived type that satisfies all of the requirements of a BIND(C) derived type.
2024-06-11[flang] Adjust new warnings for extensions (#94485)Peter Klausler1-4/+3
Prevent messages from module files, respect the language feature flags when enabling the relaxed PURE dummy argument checking, and check that the new warnings are enabled.
2024-06-11[flang] Enforce F'2023 C15121 (#94418)Peter Klausler1-18/+29
No specification expression in the declaration of the result variable of an elemental function may depend on the value of a dummy argument. This ensures that all of the results have the same type when the elemental function is applied to the elements of an array.
2024-06-11[flang] Relax BIND(C) derived type component check (#94392)Peter Klausler1-19/+8
Allow an explicit BIND(C) derived type to have a non-BIND(C) component so long as the component's type is interoperable and it satisfies all other constraints.
2024-06-11[flang] Refine checks for intrinsic operator conflicts with CUDA defi… ↵Peter Klausler1-12/+43
(#94389) …ned operators The checks for conflicts between defined operators/assignments and the intrinsic operators/assignment need to take CUDA procedure and data attributes into account to avoid false positive error messages.
2024-06-03[flang] Relax constraints on PURE/ELEMENTAL dummy arguments (#93748)Peter Klausler1-9/+28
The standard requires that dummy arguments to PURE functions be INTENT(IN) or VALUE, but PURE subroutines are allowed to have modifiable dummy arguments. This makes it impossible to declare atomic operations as PURE functions, which consequently makes such atomic operations ineligible for use in parallel constructs and DO CONCURRENT. This patch downgrades this error to a warning by default, which can be seen with -pedantic & al. and remain an error with -Werror.
2024-05-23[flang] Revert two new interoperability semantic checks (#93112)Peter Klausler1-36/+0
Two checks related to BIND(C) vs non-BIND(C) entry points with the same dummy argument added by https://github.com/llvm/llvm-project/pull/92474 have turned out to be unnecessary. Revert them and adjust the tests.