Commit Graph

1117 Commits

Author SHA1 Message Date
Peter Klausler
f58f089164 [flang] Correct definability checking for INTENT(IN) pointers (#74158)
An INTENT(IN) attribute on a pointer dummy argument prevents
modification of the pointer itself only, not modification of any
component of its target. Fix this case without breaking definability
checking for pointer components of non-pointer INTENT(IN) dummy
arguments.
2023-12-11 12:03:59 -08:00
Raghu Maddhipatla
decf0277a7 [Flang][OpenMP][Semantics] Modify errors to warnings for semantic checks in IS_DEVICE_PTR related to list-items being dummy arguments. (#74370)
Changed semantic check from giving error to giving a warning about
deprecation from OpenMP 5.2 and later about checks for dummy argument
list-items present on IS_DEVICE_PTR clause.

This P is blocker for
https://github.com/llvm/llvm-project/pull/71255
2023-12-08 16:06:03 -06:00
Brad Smith
74e59e7752 [flang] Remove GCC 7.2 workarounds (#73574)
The minimum GCC version was bumped from 7.1 to 7.4 so garbage collect
the 7.2 workarounds.

https://reviews.llvm.org/D156286
2023-12-04 11:44:56 -05:00
Kiran Kumar T P
666a61972f [Flang] Add semantic check for usage of COPYPRIVATE and NOWAIT clauses (#73486)
1. COPYPRIVATE clause should be specified on END SINGLE construct.
2. NOWAIT clause should be specified on END DO/DO SIMD/SINGLE/SECTIONS
construct.

Special handling for semantic checks for nowait/copyprivate clause is
needed in Fortran due to the fact that Openmp pragmas for C/C++ doesn't
have end directive (clause). nowait/copyprivate clauses are allowed in
begin directive clause lists for C/C++ and it is not allowed for
Fortran.
2023-12-04 17:27:24 +05:30
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
Valentin Clement (バレンタイン クレメン)
a1db874d35 [flang][openacc] Allow multiple clauses when in preceded by device_type (#73976)
Some clauses can be repeated on the compute construct when they are
placed after `device_type`. The semantic check was reporting an error
for these cases. This patch fixes this.
2023-11-30 13:16:53 -08:00
Peter Klausler
828bfbef17 [flang] Suppress error meant to prevent discontiguous association whe… (#73175)
…n actual argument is contiguous

When an element of a contiguous pointer array or assumed-shape array is
associated as an actual argument with an assumed-size dummy array, don't
flag the usage as an error.
2023-11-30 13:15:42 -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
e86591b37d [flang] Improve procedure interface compatibility checking for dummy … (#72704)
…arrays

When comparing dummy array extents, cope with references to symbols
better (including references to other dummy arguments), and emit
warnings in dubious cases that are not equivalent but not provably
incompatible.
2023-11-30 12:22:04 -08:00
Peter Klausler
bf4a876309 [flang] Move and extend REDUCE() compile-time checking (#72570)
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-30 11:44:43 -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
Valentin Clement (バレンタイン クレメン)
a6c02edd6e [flang][openacc] Keep CYCLE check for compute and data construct (#73897)
Unlike mentioned in #73839, some OpenACC construct still need the cycle
branching check to be performed. This patch adds a list of construct
where the check is not needed (loop and combined construct) and add
tests to check where it is still needed.
2023-11-29 21:34:12 -08:00
Valentin Clement (バレンタイン クレメン)
a87ca1bbd9 [flang][openacc] Do not check for unlabelled CYCLE branching (#73839)
There is no such restriction for any OpenACC construct. This patch adds
a constexpr condition on the type of Directive.
2023-11-29 15:37:53 -08:00
Valentin Clement (バレンタイン クレメン)
f4c5c470cd [flang][openacc] Enforce no branching out of compute region for combined construct (#73581)
`A program may not branch into or out of a compute construct.` This
restriction is also true for combined constructs. This patch enforce
this rule.
2023-11-28 08:50:30 -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
Sunil Kuravinakop
d033f51a0a [OpenMP] atomic compare fail : Parser & AST support
Diff Revision: https://reviews.llvm.org/D123235
2023-11-26 13:34:34 -06:00
Shraiysh
8840eb3fb5 [flang][OpenMP] Add semantic check for declare target (#72770) 2023-11-22 16:13:14 -06:00
Valentin Clement (バレンタイン クレメン)
575c9bf940 [flang][openacc] Avoid crash when collapse loop nest has extra directive (#73166)
The compiler was crashing when the collapse loop nest could not be
retrieved because of extra acc loop directive inside it.
2023-11-22 13:01:12 -08:00
Shraiysh
525396a3ae [flang][OpenMP] Add semantic check for device clause (#72789)
This patch adds the following semantic check:

```
The ancestor device-modifier must not appear on the device clause on any
directive other than the target construct.
```
2023-11-20 19:54:22 -06:00
Krzysztof Parzyszek
ddfed815c9 Revert "[OpenMP] atomic compare fail : Parser & AST support"
This reverts commit edd675ac28.

This breaks clang build where every component is a shared library.

The file clang/lib/Basic/OpenMPKinds.cpp, which is a part of
libclangBasic.so, uses `getOpenMPClauseName` which isn't:

/usr/bin/ld: CMakeFiles/obj.clangBasic.dir/OpenMPKinds.cpp.o: in functio
n `clang ::getOpenMPSimpleClauseTypeName(llvm::omp::Clause, unsigned int
)':
OpenMPKinds.cpp:(.text._ZN5clang29getOpenMPSimpleClauseTypeNameEN4llvm3o
mp6ClauseEj+0x9b): undefined reference to `llvm::omp::getOpenMPClauseNam
e(llvm::omp::Clause)'
2023-11-20 10:48:06 -06:00
Sunil Kuravinakop
edd675ac28 [OpenMP] atomic compare fail : Parser & AST support
Diff Revision: https://reviews.llvm.org/D123235
2023-11-20 03:05:31 -06:00
Shraiysh
c06700bd75 Revert "[flang][OpenMP] Add semantic check for declare target" (#72592)
Reverts llvm/llvm-project#71861
2023-11-16 19:17:56 -06:00
Shraiysh
7ff8094a39 [flang][OpenMP] Add semantic check for declare target (#71861)
This patch adds the following check from OpenMP 5.2.

```
If the directive has a clause, it must contain at least one enter clause
or at least one link clause.
```

Also added a warning for the deprication of `TO` clause on `DECLARE
TARGET` construct.

```
The clause-name to may be used as a synonym for the clause-name enter.
This use has been deprecated.
```

Based on the tests for to clause, the tests for enter clause are added.

This patch does not add tests where both to and enter clause are used together.
2023-11-16 18:03:32 -06: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
Peter Klausler
1c91d9bdea [flang] Ensure that portability warnings are conditional (#71857)
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 16:13:50 -08:00
Peter Klausler
a5eb6bdd8e [flang] Relax overindexing error to warning for last dummy dimension (#71725)
Compilation-time subscript value range checking should emit a warning,
not an error, when the indexed array is a dummy argument; there's
old-school codes out there that should have used assumed-size dummy
arguments but didn't.
2023-11-13 15:59:34 -08:00
Peter Klausler
f06ea103e7 [flang] Do definability checking in RANK() clauses (#71607)
I explicitly skipped definability checking for construct entities under
a RANK() clause. I don't know what I was thinking at the time; it's
obviously incorrect! Fix, and add tests.
2023-11-13 15:37:54 -08:00
Peter Klausler
f2bf44b6ec [flang][preprocessor] Finesse disabling of function-like macros (#71589)
During function-like macro expansion in a standard C/C++ preprocessor,
the macro being expanded is disabled from recursive macro expansion. The
implementation in this compiler's preprocessor, however, was too broad;
the macro expansion needs to be disabled for the "rescanning" phase
only, not for actual argument expansion.

(Also corrects an obsolete comment elsewhere that was noticed during
reduction of an original test case.)
2023-11-13 15:25:10 -08:00
Peter Klausler
36ad3431bb [flang] Don't accept NULL() actual for assumed-rank dummy (#71574)
A NULL() pointer without MOLD= cannot be allowed to be associated with
an assumed-rank dummy argument, as its rank is not well-defined and
neither the RANK() intrinsic function or the SELECT RANK construct will
work in the callee.
2023-11-13 15:14:05 -08:00
Peter Klausler
13893a08d9 [flang] Compile-time checking of substring bounds (#71453)
When the bounds of a substring reference are known during compilation,
and are outside the valid range for the character base object, issue an
error message.
2023-11-13 15:03:17 -08:00
Peter Klausler
9652e9b741 [flang] Catch non-CONTIGUOUS assumed-rank with ASYNCHRONOUS/VOLATILE … (#71243)
…forwarded to CONTIGUOUS dummy

No object with the ASYNCHRONOUS or VOLATILE attribute can go through the
copy-in/copy-out protocol necessary for argument association with a
contiguous dummy array argument. The check for this constraint missed
the case of an assumed-rank array without an explicit CONTIGUOUS
attribute being forwarded on to a CONTIGUOUS dummy argument.
2023-11-13 14:41:50 -08:00
Peter Klausler
b288b412ed [flang] Enforce C839 (#71239)
An assumed-rank array may not be a coarray and may not have the VALUE
attribute.
2023-11-13 14:31:20 -08:00
Peter Klausler
3de9aa6b36 [flang] Catch READ(... SIZE=) with NML= or FMT=* (#71235)
The SIZE= specifier may not appear on a list-directed or namelist READ
statement.
2023-11-13 14:20:43 -08:00
Peter Klausler
29fd3e2aa8 [flang] Allow polymorphic actual to implicit interface (#70873)
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 13:31:58 -08:00
Krzysztof Parzyszek
9cdaeefc45 [flang] Fix typo in ExpressionAnalyzer::CheckIntrinsicKind, NFC 2023-11-08 08:31:58 -06:00
Mitch Phillips
a141a9fa97 Revert "[OpenMP] atomic compare fail : Parser & AST support"
This reverts commit 086b65340c.

Reason: Broke under -Werror. More details in
https://reviews.llvm.org/D123235
2023-11-08 11:20:17 +01:00
Sunil Kuravinakop
086b65340c [OpenMP] atomic compare fail : Parser & AST support
This is a support for " #pragma omp atomic compare fail ". It has Parser & AST support for now.

Reviewed By: tianshilei1992, ABataev

Differential Revision: https://reviews.llvm.org/D123235
2023-11-07 16:57:50 -06:00
Valentin Clement (バレンタイン クレメン)
c3629923aa [flang][openacc] Allow constant variable in data clause (#71580)
The check introduced in #71444 was to restrictive and this patch relax
it so data clause can accept constant.
2023-11-07 14:28:30 -08:00
Shraiysh
6846258aa6 [flang][OpenMP] Add semantic check for declare target (#71425)
This patch adds a semantic check for the following:

```
If a list item is a procedure name, it must not be a generic name,
procedure pointer, entry name, or statement function name.
```
2023-11-06 20:42:05 -06:00
Shraiysh
ee1000573e [flang][OpenMP] Add semantic check for target update (#71305)
This patch adds the following semantic check for target update
construct.

```
A list item can only appear in a to or from clause, but not in both.
```
2023-11-06 17:16:14 -06:00
Valentin Clement (バレンタイン クレメン)
6be6081610 [flang][openacc] Issue an error when TBP are used in data clause (#71444)
Putting a type-bound procedure in a data clause was crashing the
lowering. Issue a proper semantic error in this case.
2023-11-06 14:52:41 -08:00
Shraiysh
d6b69a1bb9 [flang][OpenMP] Add semantic checks for is_device_ptr (#71255)
This patch adds the following semantic check for is_device_ptr

```
A list item that appears in an is_device_ptr clause must be a
dummy argument that does not have the ALLOCATABLE, POINTER or
VALUE attribute.
```
2023-11-06 12:07:31 -06:00
Kiran Chandramohan
742d8eb96d [Flang][OpenMP] Dont add PreDetermined Flag if symbol is privatized already (#70931)
If the symbol is already privatized due to a user specification then it
is not required to mark it as PreDetermined. This happens if there is a
sequential loop in a parallel region that has the private specification
for the index of the sequential loop.

Fixes #63143
2023-11-06 16:07:22 +00:00
Shraiysh
97c9c9429c [flang][OpenMP] Added semantic checks for target update (#71270)
This patch adds the following semantic check for target update

```
At least one motion-clause must be specified.
```

A motion clause is either a `to` or a `from` clause.

This patch also adds a test for the following semantic check which was
already supported.

```
At most one nowait clause can appear on the directive.
```
2023-11-04 15:20:43 -05:00
Peter Klausler
9191738764 [flang] Accept CONTIGUOUS attribute when redundant (#70853)
As an extension, accept the redundant use of the CONTIGUOUS attribute
when applied to scalars and to simply contiguous objects, with a
portability warning.
2023-10-31 16:04:35 -07:00
Peter Klausler
f19af90cf8 [flang][cuda] Remove check for obsolete constraint (#70707)
The online CUDA Fortran documentation states that a device subprogram
must be a top-level module subprogram, but this has turned out to be an
obsolete constraint. Stop enforcing it.
2023-10-31 12:39:18 -07:00
Peter Klausler
1bea0347bf [flang] Fix mod file generation of derived type initializers... (#70511)
... when the derived type used in the structure constructor(s) is from
another module and not use-associated into the current module.

This came up in a test with a derived type component default initializer
of "c_null_ptr", which is replaced with the expression
"__builtin_c_ptr(address=0_8)"; the derived type name "__builtin_c_ptr"
is not available in the current scope, and the module file would fail
semantic analysis when USE'd.

The best solution that I found was to extend module file generation to
detect this case and handle it by inserting the right USE association to
the ultimate derived type symbol, possibly with renaming to a
compiler-created name in the case of a conflict.

To implement this transformation, it was necessary to fix the utility
evaluate::CollectSymbols() to include the derived type symbol from a
structure constructor. This involved extending the expression traversal
framework to visit the derived type spec of a structure constructor.
Extending CollectSymbols() caused a lowering test to fail mysteriously,
so I tracked down the code in PFTBuilder that didn't expect to see a
DerivedTypeDetails symbol and dealt with it there.
2023-10-31 12:17:00 -07:00
Peter Klausler
11529d5b3b [flang] Fine-tune function result equivalence checking (#70260)
When a separate module function's definition has a redundant interface
-- it's defined with MODULE FUNCTION, not MODULE PROCEDURE -- the check
for result type equivalence needs to allow for character lengths that
are the results of specification expressions. At present,
identical-looking length specification expression don't compare equal,
since they can refer to distinct dummy argument symbols. Ensure just
that they are both constant or not, and if constant, that the lengths
have the same value.
2023-10-31 12:05:29 -07:00
Peter Klausler
fa6b574215 [flang] Account for shadowed symbols when skimming executable part (#70246)
Name resolution takes a quick pass over the executable part of a
(sub)program in search of symbols that appear to be called as
procedures, so that those names don't get mistakenly converted into
objects when finishing up specification part processing. This pass
doesn't currently cope with symbol shadowing by nested declarations in
executable constructs. This patch ensures that nested declarations for
symbols that could be used in contexts that might have been parsed as
function references properly shadow symbols of the same name in outer
scopes.
2023-10-31 11:51:00 -07:00