458 Commits

Author SHA1 Message Date
Valentin Clement (バレンタイン クレメン)
38b2755983
Revert "[flang][cuda] Implicitly load cudadevice module in device/global subprogram" (#91827)
Reverts llvm/llvm-project#91668
2024-05-10 17:51:30 -07:00
Valentin Clement (バレンタイン クレメン)
f32f6d199a
[flang][cuda] Implicitly load cudadevice module in device/global subprogram (#91668)
Some functions and subroutines are available in device context
(device/global). These functions have interfaces declared in the
`cudadevice` module.

This patch adds interfaces as `__cuda_device_builtins_<fctname>` in a
builtin module and they are USE'd rename in the `cudadevice` module. The
module is implicitly used in device/global subprograms.

The builtin module only contains procedures from section 3.6.4 for now.
2024-05-10 13:41:53 -07:00
Peter Klausler
19b41f40a4
[flang] Complete RESULT() name constraint checking (#91476)
There are two constraints in the language that prohibit the use of an
ENTRY name being used as the RESULT() variable of the function or
another ENTRY name in the same function's scope; neither can the name of
the function be used as the RESULT() of an ENTRY.
    
Move most of the existing partial enforcement of these constraints from
name resolution into declaration checking, complete it, and add more
cases to the tests.
2024-05-09 11:31:13 -07:00
Peter Klausler
22c59e01cd
[flang] Don't crash on bad inherited implied DO type (#91073)
Fortran has an ambiguously defined rule about the typing of index
variables of implied DO loops in DATA statements and array constructors
that omit an explicit type specification. Such indices have the type
that they would have "if they were variables" in the innermost enclosing
scope. Although this could, and perhaps should, be read to mean that
implicit typing rules active in that innermost enclosing scope should be
applied, every other Fortran compiler interprets that language to mean
that if there is a type declaration for that name that is visible from
the enclosing scope, it is applied, and it is an error if that type is
not integer.

Fixes https://github.com/llvm/llvm-project/issues/91053.
2024-05-09 10:17:15 -07:00
Peter Klausler
8ed7ea0896
[flang] Defer conversion of PDT default initializers (#91026)
As the kinds of the integer types of type parameters may well depend on
the values of other type parameters, defer the attempt to convert their
values to the point of type instantiation instead of doing it during
declaration processing.
2024-05-09 09:56:01 -07:00
Peter Klausler
505f6da196
[flang] Ensure all warning/portability messages are guarded by Should… (#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-05-01 14:33:14 -07:00
Peter Klausler
68a27989d0
[flang] Accept and ignore compiler directives between internal subpro… (#89810)
…grams

The parser only recognizes compiler directives that appear within
internal / module subprograms, not those that might appear between them.
Extend to allow them between subprograms as well.
2024-04-24 15:25:19 -07:00
Peter Klausler
c3def59d0f
[flang] Fix bogus error about duplicate binding names (#89786)
Don't call SetBindNameOn() from DeclareUnknownEntity() unless there is
an explicit BIND(C) attribute.

Fixes https://github.com/llvm/llvm-project/issues/89439 and
https://github.com/llvm/llvm-project/issues/89558.
2024-04-24 14:57:00 -07:00
Peter Klausler
59bf49a632
[flang] Fix bogus error on statement function (#89402)
When a statement function in a nested scope has a name that clashes with
a name that exists in the host scope, the compiler can handle it
correctly (with a portability warning)... unless the host scope acquired
the name via USE association. Fix.

Fixes https://github.com/llvm/llvm-project/issues/88678.
2024-04-22 15:12:32 -07:00
Peter Klausler
cb1b846eda
[flang] Improve error reporting for procedures determined by usage (#88184)
When a symbol is known to be a procedure due to its being referenced as
a function or subroutine, improve the error messages that appear if the
symbol is also used as an object by attaching the source location of its
procedural use. Also, for errors spotted in name resolution due to how a
given symbol has been used, don't unconditionally set the symbol's error
flag (which is otherwise generally a good idea, to prevent cascades of
errors), so that more unrelated errors related to usage will appear.
2024-04-22 14:27:39 -07:00
Peter Klausler
e1ad2735c3
[flang] Clean up ISO_FORTRAN_ENV, fix NUMERIC_STORAGE_SIZE (#87566)
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-04-08 11:57:01 -07:00
Peter Klausler
aace1e1719
[flang] Improve error message with declaration (#87294)
When a program attempts to use a non-object entity as the base of a
component reference or type parameter inquiry, the message is somewhat
uninformative and the position of the entity's declaration will not
reflect any updates made to the symbol during name resolution.

Includes some NFC C++17 style clean-up on some code noticed while
debugging (missing mandatory braces).
2024-04-08 11:55:03 -07:00
Peter Klausler
af61d08280
[flang] Handle forward reference to shadowing derived type from IMPLICIT (#87280)
A derived type name in an IMPLICIT statement might be a host association
or it might be a forward reference to a local derived type, which may be
shadowing a host-associated name. Add a scan over the specification part
in search of derived type definitions to determine the right
interpretation.

Fixes https://github.com/llvm/llvm-project/issues/87215.
2024-04-08 11:54:37 -07:00
Peter Klausler
92ecc22b8d
[flang] Fix crash in semantics on bad program (#87199)
Don't accept a putative statement function definition for a symbol that
is a subprogram but can't possibly be a statement function.

Fixes https://github.com/llvm/llvm-project/issues/86936.
2024-04-08 11:53:49 -07:00
Peter Klausler
8f01ecaeb8
[flang] Special-case handling of INTRINSIC in type-decl-stmt (#86518)
Fortran allows the INTRINSIC attribute to be specified with a distinct
attribute statement, and also as part of the attribute list of a
type-declaration-stmt. This is an odd case (especially as the declared
type is mandated to be ignored if it doesn't match the type of the
intrinsic function) that can lead to odd error messages and crashes,
since the rest of name resolution expects that intrinsics with explicit
declarations will have been declared with INTRINSIC attribute
statements. Resolve by handling an "inline" INTRINSIC attribute as a
special case while processing a type-declaration-stmt, so that

  real, intrinsic :: acos, asin, atan

is processed exactly as if it had been

  intrinsic acos, asin, atan; real acos, asin, atan

Fixes https://github.com/llvm/llvm-project/issues/86382.
2024-03-26 09:50:37 -07:00
Peter Klausler
f50f0caf87
[flang] Fix crash in name resolution (#85835)
ConvertToObjectEntity() returns true for use- and host-associated object
symbols, too. Ensure in this case that the symbol really is a
non-associated object.

Fixes https://github.com/llvm/llvm-project/issues/85776.
2024-03-26 08:59:22 -07:00
harishch4
a7eaae4ec6
[Flang] Fix to the module procedure interface block ignoring implicit… (#85735)
… of host scoping unit.

Fix as proposed by @thtsikas [here
](11d07d9ef6 (commitcomment-139798026)).
2024-03-19 22:46:57 +05:30
Peter Klausler
702a86a8f1
[flang] Correct accessibility of name that is both generic and derive… (#85098)
…d type

When the same name is used for a derived type and generic interface in a
module, and no explicit PUBLIC or PRIVATE statement appears for the name
but the derived type definition does have an explicit accessibility,
that accessibility must also apply to the generic interface.
2024-03-13 15:13:56 -07:00
Peter Klausler
83ca78deb9
[flang] Emit "raw" name for procedure interface in module file (#83915)
Save both the raw procedure interface symbol as well as the result of
passing it through GetUltimate() and BypassGeneric() in symbol table
entries with ProcEntityDetails. The raw symbol of the interface needs to
be the one used for emitting procedure symbols to module files.

Fixes https://github.com/llvm/llvm-project/issues/83836.
2024-03-05 12:00:46 -08:00
Peter Klausler
13cd0a905b
[flang] Skim usage before marking unknown module externals as subrout… (#83897)
…ines

Name resolution needs to delay its default determination of module
external procedures as subroutines until after it has skimmed the
execution parts of module procedures.

Fixes https://github.com/llvm/llvm-project/issues/83622.
2024-03-05 11:41:12 -08:00
Peter Klausler
e09e9567fc
[flang] Downgrade error to warning (#83032)
It's probably a bad idea to have a Cray pointer whose type is a derived
type that is not a sequence type, but the feature is a nonstandard
extension in the first place. Downgrade the message to a warning.

Fixes https://github.com/llvm/llvm-project/issues/82210.
2024-03-01 16:54:35 -08:00
Peter Klausler
2445a96ff2
[flang] Enforce F'2023 C1520 correctly (#82842)
When a procedure declaration statement has a binding label, it must
declare no more than one procedure.

Fixes https://github.com/llvm/llvm-project/issues/82528.
2024-03-01 16:49:43 -08:00
Peter Klausler
f4215f7140
[flang] Fix handling of shadowed procedure name used as interface (#82837)
Use BypassGeneric() to process the name of an interface in a procedure
declaration statement, so that if it's the name of a generic with a
homonymous specific procedure, that's what defines the interface.

Fixes https://github.com/llvm/llvm-project/issues/82267.
2024-03-01 16:42:00 -08:00
Peter Klausler
8bcb1ceded
[flang] Allow PROCEDURE() with explicit type elsewhere (#82835)
Fortran allows a procedure declaration statement with no interface or
type, with an explicit type declaration statement elsewhere being used
to define a function's result.

Fixes https://github.com/llvm/llvm-project/issues/82006.
2024-03-01 16:31:13 -08:00
Peter Klausler
189d89a92c
[flang] Ensure names resolve in DATA statement objects (#82825)
When DATA statement objects have derived types obtained by implicit
typing rules, their types aren't known until specification part
processing is complete. In the case of a derived type, any component
name in a designator may still be in need of name resolution. Take care
of it in the deferred check visitor that runs at the end of name
resolution in each specification and execution part.

Fixes https://github.com/llvm/llvm-project/issues/82069.
2024-03-01 16:19:01 -08:00
Peter Klausler
1c530b3d9f
[flang] Whether a procedure's interface is explicit or not is not a d… (#82796)
…istinguishing characteristic

We note whether a procedure's interface is explicit or implicit as an
attribute of its characteristics, so that other semantics can be checked
appropriately, but this internal attribute should not be used as a
distinguishing characteristic in itself.

Fixes https://github.com/llvm/llvm-project/issues/81876.
2024-03-01 15:56:40 -08:00
Peter Klausler
a56ef9f9ce
[flang] Catch attempt to type a subroutine (#82704)
The presence of a type in the prefix of a SUBROUTINE statement should
elicit an error message, not a crash.

Fixes https://github.com/llvm/llvm-project/issues/80530.
2024-03-01 15:23:24 -08:00
Peter Klausler
8f80d466d5
[flang] Fix crash in statement function semantics (bug #80532) (#82702)
When statement function expressions are analyzed, ensure that the
semantics context has a valid location set, otherwise a type spec (like
"integer::") can lead to a crash.

Fixes https://github.com/llvm/llvm-project/issues/80532.
2024-03-01 15:10:47 -08:00
Peter Klausler
8f141490b9
[flang] Fix separate MODULE PROCEDURE when binding label exists (#82686)
When a separate module procedure is defined with a MODULE PROCEDURE and
its corresponding interface has a binding label, the compiler was
emitting an error about mismatching binding labels because the binding
label wasn't being copied into the subprogram's definition.
2024-03-01 14:57:28 -08:00
Peter Klausler
f31ac3cb1f
[flang] Handle implied ASYNCHRONOUS attribute (#82638)
The standard states that data objects involved in an asynchronous data
transfer statement gain the ASYNCHRONOUS attribute implicitly in the
surrounding subprogram or BLOCK scope. This attribute affects the checks
in call semantics, as an ASYNCHRONOUS actual object associated with an
ASYNCHRONOUS dummy argument must not require data copies in or out.

(Most compilers don't implement implied ASYNCHRONOUS attributes
correctly; XLF gets these right, and GNU is close.)
2024-03-01 14:43:31 -08:00
Peter Klausler
f7a15e0021
[flang] Use module file hashes for more checking and disambiguation (#80354)
f18's module files are Fortran with a leading header comment containing
the module file format version and a hash of the following contents.
This hash is currently used only to protect module files against
corruption and truncation.

Extend the use of these hashes to catch or avoid some error cases. When
one module file depends upon another, note its hash in additional module
file header comments. This allows the compiler to detect when the module
dependency is on a module file that has been updated. Further, it allows
the compiler to find the right module file dependency when the same
module file name appears in multiple directories on the module search
path.

The order in which module files are written, when multiple modules
appear in a source file, is such that every dependency is written before
the module(s) that depend upon it, so that their hashes are known.

A warning is emitted when a module file is not the first hit on the
module file search path.

Further work is needed to add a compiler option that emits (larger)
stand-alone module files that incorporate copies of their dependencies
rather than relying on search paths. This will be desirable for
application libraries that want to ship only "top-level" module files
without needing to include their dependencies.

Another future work item would be to admit multiple modules in the same
compilation with the same name if they have distinct hashes.
2024-03-01 13:58:36 -08:00
Peter Klausler
31ab2c4f61
[flang] Ensure USE-associated objects can be in NAMELIST (#82846)
The name resolution for NAMELIST objects didn't allow for symbols that
are not ObjectEntityDetails symbols.

Fixes https://github.com/llvm/llvm-project/issues/82574.
2024-02-23 21:15:32 -06:00
Pete Steinfeld
cc02e50e77
Revert "[Flang] Update the fix of PR 80738 to cover generic interface… (#81321)
… inside modules (#81087)"

This reverts commit 0802596df3d1ffd15f6b828a0f5c1e5b687a730f.

See comments in PR #81087 for a test case that shows why I'm reverting.
2024-02-09 18:04:53 -08:00
Daniel Chen
0802596df3
[Flang] Update the fix of PR 80738 to cover generic interface inside modules (#81087)
The following test cases crashes. The problem is that the fix for PR
https://github.com/llvm/llvm-project/pull/80738 is not quite complete.
It should `GetUltimate()` of the `interface_` before check if it is
generic.


```
  MODULE M

    CONTAINS

    FUNCTION Int(Arg)
    INTEGER :: Int, Arg
      Int = Arg
    END FUNCTION

    FUNCTION Int8(Arg)
    INTEGER(8) :: Int8, Arg
      Int8 = 8_8
    END FUNCTION

  END MODULE

  MODULE M1
  USE M

    INTERFACE Int8
      MODULE PROCEDURE  Int
      MODULE PROCEDURE  Int8
    END INTERFACE

  END MODULE

  PROGRAM PtrAssignGen
  USE M
  USE M1
  IMPLICIT NONE

  INTERFACE Int
    MODULE PROCEDURE  Int
    MODULE PROCEDURE  Int8
  END INTERFACE

  PROCEDURE(Int8),   POINTER :: PtrInt8

  PtrInt8 => Int8
  IF ( PtrInt8(100_8) .NE. 8_8 ) ERROR STOP 12

  END
  ```
2024-02-08 10:38:50 -05:00
Daniel Chen
7e4ac8541d
[Flang] Use specific symbol rather than generic symbol as procInterface to declare procedure pointer. (#80738)
Flang crashes when lowering the type of `p1` with the following code.
The problem is when it sets up the `procInterface`, it uses the generic
symbol `int`, not the specific `int`. This PR is to correct that.

```
  INTERFACE Int
    integer FUNCTION Int(arg)
      integer :: arg
    END FUNCTION
  END INTERFACE

  integer :: res
  procedure(int), pointer :: p1
  p1 => int
  res = p1(4)
  end
  ```
2024-02-07 11:36:26 -05:00
Peter Klausler
c322e92841
[flang] Silence bogus USE statement error (#79896)
When there are multiple USE statement for a particular module using
renaming, it is necessary to collect a set of all of the original
renaming targets before processing any of USE statements that don't have
ONLY: clauses.

Currently, if there is a name in the module that can't be added to the
current scope -- due to a conflict with an internal or module
subprogram, or with a previously use-associated name -- the compiler
will emit a bogus error message even if that conflicting name appear on
a later USE statement of the same module as the target of a renaming.

The new regression test case added with this patch provides a motivating
example.
2024-01-29 14:51:47 -08:00
Peter Klausler
2b7a928dd9
[flang] Improve USE merging of homonymous types, interfaces, and proc… (#79364)
…edures

Fortran allows a generic interface to have the same name as a derived
type in the same scope. It also allows a generic interface to have the
same name as one of its specific procedures.

When two modules define the same name, possibly more than once each,
things get exciting. The standard is not clear, and other compilers do
variously different things. We are currently emitting some errors
prematurely for some usage in pfUnit due to how it combines two versions
of a package together via USE association.

This patch handles combinations of derived types and generic interfaces
and their specific procedures in a more principled way. Errors due to
ambiguity are deferred to actual usage of derived types and specific
procedures -- and when they're not used, the program is unambiguous and
no error issues.
2024-01-25 16:51:30 -08:00
Peter Klausler
5bd87e65d6
[flang] Silence spurious errors about SAVE (#78765)
When an attribute specification statement follows a declaration that
applies the SAVE attribute to a symbol, name resolution can produce a
spurious error message about redundant SAVEs.

Fixes llvm-test-suite/Fortran/gfortran/regression/proc_ptr_9.f90.
2024-01-25 15:33:26 -08:00
Peter Klausler
c66645da55
[flang] Catch more initialization errors (#77850)
[flang] Catch more initialization errors
    
    Diagnose some error cases related to initialization that are
slipping past semantic checking: don't allow multiple initializations
    of the same symbol, and don't allow an object that was initialized
    as a scalar to become an array afterward.
    
Fixes llvm-test-suite/Fortran/gfortran/regression/initialization_17.f90.
2024-01-15 13:02:04 -08:00
Peter Klausler
6e0a2031f0
[flang] Catch name resolution error due to global scoping (#77683)
In
    CALL FOO
    PRINT *, ABS(FOO)
we currently resolve the first FOO to a global external subprogram, but
then the second FOO is treated as an implicitly typed local variable.
This happens because the name FOO is not present in the local scope.

Fix by adding FOO to the local scope using a place-holding
HostAssocDetails symbol whose existence prevents the creation of another
FOO in the local scope. The symbol stored in the parser::Name parse tree
nodes or used in typed expressions will all continue to point to the
global external subprogram.

Resolves llvm-test-suite/Fortran/gfortran/regression/pr71859.f90.
2024-01-15 12:40:46 -08:00
Peter Klausler
90828d67ea
[flang] Weird restrictions on index variables (#77019)
There are some very odd (even for Fortran) rules in F'2023 subclause
19.4 (paras 6 & 8) pertaining to the index variables of FORALL and DO
CONCURRENT constructs/statements, and they are not currently implemented
correctly.

Although these index variables are construct entities, they have
restrictions in the standard that would essentially allow them to also
be variables in their enclosing scopes. If their names are present in
the enclosing scope, and the construct does not have an explicit type
specification for its indices, then the names in the enclosing scope
must either be scalar variables or COMMON blocks, and their type must be
integer.

Reimplement these restrictions largely with portability warnings rather
than hard errors. Retain the semantic interpretation that the type of an
untyped index variable be taken from the type of a variable of the same
name in the enclosing scope, if it exists, although that bit of the
standard could be interpreted otherwise.

Fixes https://github.com/llvm/llvm-project/issues/76978.
2024-01-15 10:50:40 -08:00
Peter Klausler
b29d632eea
[flang] Accept BIND(C) derived type for Cray pointees (#76538)
The compiler requires that a Cray pointee have a SEQUENCE type, but a
recent bug report points out that a BIND(C) type should also be
accepted.

Fixes https://github.com/llvm/llvm-project/issues/76529.
2024-01-02 09:04:26 -08:00
Peter Klausler
571ad7324f
[flang] Defer processing of non-pointer variable initializers (#76475)
Initializers in entity-decls don't need to have their expressions
analyzed immediately in name resolution unless of course they are
defining the values of named constants. By deferring the expression
analysis, the compiler can better handle references to module and
internal procedures that might appear in structure constructors; at
present, these are typically rejected as being forward references (which
they can be) to subprogram names that can't yet be checked for
compatibility with the characteristics of the corresponding procedure
component.
2024-01-02 08:29:06 -08:00
Peter Klausler
5a402c5622
[flang] USE-associated explicit INTRINSIC names (#76199)
The compiler doesn't USE-associate names of intrinsic procedures from
modules (in the absence of ONLY:), so that the associating scope doesn't
get populated with names of intrinsics that were used only in
declarations (e.g., SELECTED_REAL_KIND). A recent bug report (below)
shows that we should modify that policy in the case of names that appear
in explicit INTRINSIC attribute statements. The behaviors of other
Fortran compilers are not consistent and the requirements of the
standard are not clear; this fix follows the precedent set by gfortran
and nvfortran.

Fixes https://github.com/llvm/llvm-project/issues/72084.
2023-12-26 16:03:03 -08:00
Peter Klausler
a4745ff99b
[flang] Detect more misparsed statement functions (same name as funct… (#73852)
…ion result)

A function can't return a statement function, so an apparent attempt to
define a statement function with the same name as the function's result
must be a misparsed assignment statement.
2023-11-30 13:35:07 -08:00
Peter Klausler
fddadd2939
[flang] Address case of under-processed array symbol (#73169)
Array element references are frequently parsed as function references
due to the ambiguous syntax of Fortran, and the parse tree is repaired
by semantics once the relevant symbol table entries are in hand. This
patch fixes a case in which the correction takes a path that leaves the
type of a symbol undetermined, leading to later spurious errors in
expression analysis.

Fixes https://github.com/llvm/llvm-project/issues/68652.
2023-11-30 13:07:49 -08:00
Peter Klausler
89165e8b1d
[flang][openacc] Disable CUDA argument checks in OpenACC regions (#72310)
Checks for CUDA Fortran data attribute compatibility don't need to be
applied in OpenACC regions.
2023-11-30 10:58:51 -08:00
Kiran Chandramohan
63a6e51f8a
[Flang][OpenMP] Fix issue with empty critical or critical without surrounding context (#71944)
Add the sourcerange for critical directive.

Fixes #65571
2023-11-27 15:56:39 +00:00
Peter Klausler
c3148e9f69
[flang] Identify misparsed statement function in BLOCK in ASSOCIATE (#72148)
When a BLOCK construct is within an ASSOCIATE or related construct,
don't misinterpret an assignment to an array element of a construct
entity as being an impermissible definition of a local statement
function.
2023-11-13 16:37:18 -08:00
Peter Klausler
94d47e6325
[flang] Catch nasty order-of-declarations case (#71881)
It is possible to declare the rank of an object after that object has
been used in the same specification part in a specification function
reference whose result or generic resolution may well have depended on
the object being apparently a scalar.

Catch this case, and emit a warning -- not an error, yet, due to fear of
false positives.

See the new test for examples.
2023-11-13 16:24:43 -08:00