Commit Graph

254 Commits

Author SHA1 Message Date
Krzysztof Parzyszek
7d60232b38 [flang][Frontend] Implement printing defined macros via -dM (#87627)
This should work the same way as in clang.
2024-04-10 10:41:20 -05:00
Valentin Clement (バレンタイン クレメン)
e953c862e9 [flang][cuda] Add UNIFIED data attribute (#88171)
Latest version of the specification introduced the `UNIFIED` attribute
for data.


https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/#cfref-var-attr-unified-data

This patch adds the attribute to parsing, semantic and lowering. 

The matching rules for dummy/actual arguments is not part of this patch.
2024-04-09 13:32:21 -07:00
Mats Petersson
040e0d4fa4 [flang]Accept directive inside type definition (#87804)
Some applications have alignment directives for members inside types.

This allows those to be present, but generally getting ignored [with a warning]
later on in the processing. This is just to allow the compilation to complete.
2024-04-09 12:54:24 +01:00
Peter Klausler
8a84596310 [flang] Dodge bogus GCC 13.2.0 error message in new code (#86708)
Rearrange some new code a little bit to avoid a bogus error message
coming out from GCC 13.2.0 about an uninitialized data member in a
parser.
2024-03-26 12:41:54 -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
6e261d9c37 [flang] Accept more unrecognized !DIR$ compiler directives (#85829)
When encountering an unparsable !DIR$ compiler directive line, accept it
as a whole source line and emit a warning that it is unrecognizable.

Fixes https://github.com/llvm/llvm-project/issues/59107,
https://github.com/llvm/llvm-project/issues/82212, and
https://github.com/llvm/llvm-project/issues/82654.
2024-03-26 08:46:21 -07:00
Peter Klausler
60fa2b0670 [flang] Parse !$CUF KERNEL DO <<< (*) (#85338)
Accept and represent asterisks within the parenthesized grid and block
specification lists.
2024-03-15 13:57:42 -07:00
Krzysztof Parzyszek
1def98d9f2 [flang] Avoid forming a reference from null pointer (#84787)
Doing so is an undefined behavior.

This was detected by the undefined behavior sanitizer.
2024-03-11 14:35:31 -05: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
Mats Petersson
601a9587a1 [Flang] Add support for assume_aligned directive (#81747)
This adds the parsing (and unparse) of the compiler drective assume_aligned.

The compiler will issue a warning that the directive is ignored.
2024-03-01 15:28:20 +00:00
Peter Klausler
5a20a20803 [flang] Resolve "possible performance problem" issue spam (#79769)
Four "issues" on GitHub report possible performance problems, likely
detected by static analysis. None of them would ever make a measureable
difference in compilation time, but I'm resolving them to clean up the
open issues list.

Fixes https://github.com/llvm/llvm-project/issues/79703, .../79705,
.../79706, & .../79707.
2024-02-20 14:08:37 -08:00
Peter Klausler
1db2859dd9 [flang] Handle more use cases reported for issues/78797 (#79628)
I implemented legacy "token pasting" via line continuation for

  call prefix&
    &MACRO&
    &suffix(1)

in a recent patch; this patch addresses the related cases

  call prefix&
    &MACRO&
    &(1)

and

  call &
    &MACRO&
    &suffix(1)

Fixes the latest https://github.com/llvm/llvm-project/issues/79590.
2024-02-20 13:21:21 -08:00
Kazu Hirata
ab9a69878c [flang] Simplify a string comparison (NFC) 2024-02-03 09:36:43 -08:00
Peter Klausler
60860079ec [flang][preprocessor] Replace macros in some #include directives (#80039)
Ensure that #include FOO undergoes macro replacement. But, as is the
case with C/C++, continue to not perform macro replacement in a #include
directive with <angled brackets>.
2024-01-31 11:50:51 -08:00
Peter Klausler
776e25af6d [flang] Inhibit case of false tokenization of Hollerith (#79029)
https://github.com/llvm/llvm-project/issues/78927 contains a case of
fixed-form source in which a Hollerith literal is mistakenly tokenized,
leading to grief later due to apparently unbalanced parentheses.

The source looks like "REAL*8 R8HEAP(SCRSIZE)" and the Hollerith literal
is misrecognized as such because it follows "8R". In order to properly
tokenize Hollerith literals in old comma-free FORMAT statements like "1
FORMAT(3I5HFLANG)", the tokenizer in the prescanner treats a letter
after an integer token ("3I") as a special case. The fix is to do this
only when the characters involved are nested in parentheses and
Hollerith is a possibility.

Fixes https://github.com/llvm/llvm-project/issues/78927.
2024-01-25 16:09:17 -08:00
Peter Klausler
4299d9b1af [flang] Accomodate historic preprocessing usage (#78868)
Some Fortran codes use line continuation as a form of token pasting; see
https://github.com/llvm/llvm-project/issues/78797. This works in
compilers that run a C-like preprocessor and then apply line
continuation to its output; f18 implements line continuation during
tokenization and preprocessing, but can still handle this case.

In the rare case when an identifier is split across two or more
continuation lines, this patch allows its parts to be distinct
preprocessing tokens for the purpose of macro replacemnt. They (or their
replacement texts) can be effectively rejoined later as a single
identifier when the cooked character stream is tokenized in parsing.

Fixes https://github.com/llvm/llvm-project/issues/78797.
2024-01-25 16:00:57 -08:00
Peter Klausler
c6dfb62d4d [flang] Support \u Unicode escape sequences (#76757)
Support \uNNNN and \uNNNNNNNN escape sequences for CHARACTER(KIND=2) and
CHARACTER(KIND=4) literal constants for better GNU Fortran
compatibility.

Fixes llvm-test-suite/Fortran/gfortran/regression/achar_6.F90 and
.../widechar_1.f90.
2024-01-15 09:35:17 -08:00
jeanPerier
c87e94b030 [flang] Get ProvenanceRange from CharBlock starting with expanded macro (#77791)
When a CharBlock starts with an expanded macro but does not end in this
macro expansion, GetProvenanceRange fails to return a ProvenanceRange
which may cause error message to be emitted without location or lowering
to emit code without source location (which is problematic if this code
contains calls to procedures defined in the same file since LLVM will
later crash with the error:
"inlinable function call in a function with a DISubprogram location must
have a debug location"

Fix this situation by returning the ProvenanceRange starting at the
replaced macro reference.
2024-01-12 13:04:50 +01:00
Valentin Clement
c8ad802443 [flang][openacc] Carry device dependent info for routine in the module file 2024-01-11 13:57:23 -08:00
Krzysztof Parzyszek
d447304768 Revert "[Flang][Parser] Add missing dependencies to CMakeLists.txt (#77483)"
This reverts commit cc53ec82ea.

This commit hasn't accomplished anything. The original issue was that
`DumpTree`, when called from lowering, caused linker errors due to some
directive-naming functions being absent. Adding FrontendOpenMP to the
parser library didn't fix that problem, and according to the notes in
PR #77483, calling `DumpTree` from lowering isn't really supported.
2024-01-11 15:04:26 -06:00
Krzysztof Parzyszek
cc53ec82ea [Flang][Parser] Add missing dependencies to CMakeLists.txt (#77483)
Add FrontendOpenMP as an additional component library dependency.
2024-01-11 05:39:16 -06:00
Katherine Rasmussen
a2d7af757b [flang] Add notify-type and notify-wait-stmt (#76594)
Add `notify-type` to `iso_fortran_env` module. Add `notify-wait-stmt` to
the parser and add checks for constraints on the statement, `C1177` and
`C1178`, from the Fortran 2023 standard. Add three semantics tests for
`notify-wait-stmt`.
2024-01-02 10:40:47 -08:00
Peter Klausler
7c55dd8de6 [flang] Accept multiple spaces after compiler directive sentinel (#76541)
The prescanner allows multiple spaces within a compiler directive, but
not between the directive's sentinel (e.g., !DIR$) and the directive's
first token.

Fixes https://github.com/llvm/llvm-project/issues/76537.
2024-01-02 09:15:04 -08:00
Peter Klausler
3bbdbb22a5 [flang] Fix parsing time explosion (#76533)
When parsing a deeply-nested expression like
  A1(A2(A3(A4(A5(A6(...A99(i)...))))))
the parser can get into an exponential state due to the need to consider
the possibility that each "An(...)" might be the beginning of a
reference to a procedure component ("An(...)%PROC(...)") so that
alternative has to be attempted first before proceeding to try parsing
"An(...)" as a function reference or as an array element designator. The
parser for a structure component, which is used by the procedure
designator parser, was not protected with the usual failure memoization
technique, leading to exponentially bad behavior parsing a deeply-nested
expression. Fix by exploiting the instrumented() parser combinator so
that failed structure component parsers aren't repeated.

Fixes https://github.com/llvm/llvm-project/issues/76477.
2024-01-02 08:54:10 -08:00
Kazu Hirata
11efccea8f [flang] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 23:48:53 -08:00
Peter Klausler
ea3a3b25b9 [flang] Handle continuation line edge case (#74751)
For a character literal that is split over more than one source line
with free form line continuation using '&'
at the end of one line but missing the standard-required '&' on the
continuation line, also handle the case of spaces at the beginning of
the continuation line.
    
For example,
    
PRINT *, 'don'&
   't poke the bear'
    
now prints "don't poke the bear", like nearly all other Fortran
compilers do.
    
This is not strictly standard conforming behavior, and the compiler
emits a portability warning with -pedantic.
    
Fixes llvm-test-suite/Fortran/gfortran/regression/continuation_1.f90,
.../continuation_12.f90, and .../continuation_13.f90.
2023-12-11 13:09:12 -08:00
Peter Klausler
d3e5c20ab8 [flang] Handle preprocessor macro expansion edge case (#73835)
When a reference to a function-like macro begins during the rescanning
of the expansion of another macro but is not completed by the end of
that expansion, it is necessary to abort that rescanning of that
expansion and try again when more tokens can be acquired. (See the new
unclosed-FLM.F90 test case.) All other Fortran preprocessors to which I
have access can handle this situation.
2023-11-30 13:23:14 -08:00
Shraiysh
8840eb3fb5 [flang][OpenMP] Add semantic check for declare target (#72770) 2023-11-22 16:13:14 -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
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
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
Valentin Clement (バレンタイン クレメン)
ba2f40a775 [flang][openacc] Allow acc routine before implicit part (#71460)
Allow position of the acc routine in the implicit part.
2023-11-06 17:49:04 -08:00
SiHuaN
8b91de5d6a [Flang][OpenMP] Correctly handling continuation lines with Fixed Source Form Conditional Compilation Sentinels (#70309)
Fixes #67947

---------

Co-authored-by: SiHuaN <liyongtai@iscas.ac.cn>
Co-authored-by: Leandro Lupori <leandro.lupori@gmail.com>
2023-11-01 09:05:33 +08:00
Peter Klausler
297230acda [flang] Accept directive sentinels in macro-replaced source better (#70699)
At present, the prescanner emits an error if a source line or compiler
directive, after macro replacement or not, contains a token with a
non-Fortran character. In the particular case of the '!' character, the
code that checks for bad character will accept the '!' if it appears
after a ';', since the '!' might begin a compiler directive.

This current implementation fails when a compiler directive appears
after some other character that might (by means of further source
processing not visible to the prescanner) be replaced with a ';' or
newline.

Extend the bad character check for '!' to actually check for a compiler
directive sentinel instead.
2023-10-31 12:35:01 -07:00
Peter Klausler
f706411f71 [flang][preprocessor] Handle compiler directives with continuations a… (#70128)
…fter macro expansion

When compiler directives (!$omp) and/or their continuations (!$omp &)
are produced by macro expansion, handle those continuations. Also allow
a continuation marker (&) to appear in a macro actual argument.
2023-10-31 11:38:25 -07:00
Valentin Clement (バレンタイン クレメン)
f706837e2b [flang][mlir][openacc] Switch device_type representation to an enum (#70250)
Switch the representation from scalar integer to a enumeration. The
parser transform the string in the input to the correct enumeration.
2023-10-30 09:51:42 -07:00
Z572
7de70e0f72 [Flang][OpenMP] Fix comments that should not be Sentinels on fixed format. (#68911)
Fixes #68653
2023-10-31 00:20:00 +08:00
Valentin Clement (バレンタイン クレメン)
828674395b [flang][openacc] Allow acc routine at the top level (#69936)
Some compilers allow the `$acc routine(<name>)` to be placed at the
program unit level. To be compatible, this patch enables the use of acc
routine at this level. These acc routine directives must have a name.
2023-10-24 09:17:48 -07:00
Valentin Clement (バレンタイン クレメン)
f0812480d2 [flang][openacc] Support fixed form sentinel format (#69970)
The OpenACC standard mentions directive format for fixed form source
files. The following sentinels are accepted:

```
!$acc directive-name [clause-list]
c$acc directive-name [clause-list]
*$acc directive-name [clause-list]
```

Update the parser to accepts these. A new option is added to `bbc` so
the change can be tested.
2023-10-23 14:27:39 -07:00
Valentin Clement (バレンタイン クレメン)
d2e7a15dfb [flang][openacc] Warn about misplaced end loop directive and ignore it (#69512)
Instead of raising an error for a misplaced `end loop directive`, just
warn about it and ignore it. This directive is an extension and is
optional.
2023-10-19 08:49:01 -07:00
Peter Klausler
81d04709f8 [flang] Fix construct names on labeled DO (#67622)
Fortran requires that a DO construct with a construct name end with an
END DO statement bearing the same name. This is true even if the DO
construct begins with a label DO statement; e.g., "constrName: do 10
j=1,10" must end with "10 end do constrName".

The compiler presently basically ignores construct names that appear on
label DO statements, because only non-label DO statements can be parsed
as DO constructs. This causes us to miss some errors, and (worse) breaks
the usage of the construct name on CYCLE and EXIT statements.

To fix this, this patch changes the parse tree and parser so that a DO
construct name on a putative label DO statement causes it to be parsed
as a "non-label" DO statement... with a label. Only true old-style
labeled DO statements without construct names are now parsed as such.

I did not change the class name NonLabelDoStmt -- it's widely used
across the front-end, and is the name of a production in the standard's
grammar. But now it basically means DoConstructDoStmt.

Fixes https://github.com/llvm/llvm-project/issues/67283.
2023-10-16 17:29:25 -07:00
Valentin Clement (バレンタイン クレメン)
6ade518323 [flang][openacc][NFC] Issue better error message when directive is wrong (#69034) 2023-10-16 08:52:02 -07:00
Raghu Maddhipatla
80b571c66c [Flang] [OpenMP] [Semantics] Add semantic support for IS_DEVICE_PTR nd HAS_DEVICE_ADDR clauses on OMP TARGET directive and add more semantic checks for OMP TARGET. (#67290)
Summary of this patch

- Add semantic support for HAS_DEVICE_ADDR and IS_DEVICE_PTR clauses.
- A list item that appears in an IS_DEVICE_PTR clause must be a valid
device pointer for the device data environment.
- A list item may not be specified in both an IS_DEVICE_PTR clause and a
HAS_DEVICE_ADDR clauses on the directive.
- A list item that appears in an IS_DEVICE_PTR or a HAS_DEVICE_ADDR
clauses must not be specified in any data-sharing attribute clause on
the same target construct.
2023-09-28 11:50:26 -05:00
Peter Klausler
fa44ec72d6 [flang] Allow continuation of D lines (#66242)
When the old extension of D debug lines in fixed form source is enabled,
recognize continuation lines that begin with a D.

(No test is added, since the community's driver doesn't support the GNU
Fortran option -fd-lines-as-code.)
2023-09-18 09:37:01 -07:00
Valentin Clement (バレンタイン クレメン)
16cf9c9af0 [flang][openacc] Support labeled DO loop after acc combined directive (#66296)
This patch adds support for labeled do loop after combined directive. It
relaxes the initial parser and canonicalize labeled do loop into the
OpenACCCombinedConstruct.
2023-09-13 20:50:42 -07:00
Valentin Clement (バレンタイン クレメン)
bc32346082 [flang][openacc] Support labeled DO loop after acc loop directive (#66294)
Make the `DoConstruct` in `OpenACCLoopConstruct` optional and move the
labeled do construct in in the canonicalization step.
2023-09-13 20:50:20 -07:00
Sergio Afonso
edc2fb0733 [Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
Re-land commit 3787fd942f

This patch adds support for storing OpenMP REQUIRES information in the
semantics symbols for programs/subprograms and modules/submodules, and
populates them during directive resolution. A pass is added to name resolution
that makes sure this information is also propagated across top-level programs,
functions and subprograms.

Storing REQUIRES information inside of semantics symbols will also allow
supporting the propagation of this information across Fortran modules. This
will come as a separate patch.

The `bool DirectiveAttributeVisitor::Pre(const parser::SpecificationPart &x)`
method is removed since it resulted in specification parts being visited twice.

This is patch 3/5 of a series splitting D149337 to simplify review.

Differential Revision: https://reviews.llvm.org/D157983
2023-09-11 15:01:57 +01:00
Sergio Afonso
4b9259b947 Revert "[Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units"
Changes in this commit make some gfortran tests crash the compiler. It is
likely trying to dereference undefined symbol pointers.

This reverts commit 3787fd942f.
2023-09-11 13:01:29 +01:00
Sergio Afonso
3787fd942f [Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
This patch adds support for storing OpenMP REQUIRES information in the
semantics symbols for programs/subprograms and modules/submodules, and
populates them during directive resolution. A pass is added to name resolution
that makes sure this information is also propagated across top-level programs,
functions and subprograms.

Storing REQUIRES information inside of semantics symbols will also allow
supporting the propagation of this information across Fortran modules. This
will come as a separate patch.

The `bool DirectiveAttributeVisitor::Pre(const parser::SpecificationPart &x)`
method is removed since it resulted in specification parts being visited twice.

This is patch 3/5 of a series splitting D149337 to simplify review.

Differential Revision: https://reviews.llvm.org/D157983
2023-09-11 11:48:07 +01:00