Commit Graph

2918 Commits

Author SHA1 Message Date
peter klausler f187d64c80 [flang][nfc] Fix comments, remove needless API, tweak script
* Remove an unimplemented and unused member function declaration
* Remove a misleading comment about an unrelated constraint number
* Fix a comment
* Add f18 crash message to "flang" driver script

Differential Revision: https://reviews.llvm.org/D95180
2021-01-22 10:55:53 -08:00
peter klausler 07f1e1f44c [flang] Correct shape analysis for transformational intrinsic functions
Correct the analysis of references to transformational intrinsic
functions that have different semantics based on the presence or
absence of a DIM= argument; add shape analysis for UNPACK().

Differential Revision: https://reviews.llvm.org/D94716
2021-01-22 10:48:58 -08:00
peter klausler 59bf9a89d8 [flang] Remove some needless operations in expr rewriting
Expressions emitted to module files and error messages
sometimes contain conversions of integer results of inquiry
intrinsics; these are usually not needed, and can conflict
with "int" in the user's namespace.  Improve folding so that
these conversions don't appear, and do some other clean-up
in adjacent code.

Differential Revision: https://reviews.llvm.org/D95172
2021-01-22 10:08:51 -08:00
Peter Steinfeld 02e174e8f7 [flang] Fix typo in error message
The title says it all.

Differential Revision: https://reviews.llvm.org/D95233
2021-01-22 07:28:37 -08:00
peter klausler 2de5ea3b3e [flang] Fix bogus error message with binding
ProcedureDesignator::GetInterfaceSymbol() needs to return
the procedure bound to a bindings.

Differential Revision: https://reviews.llvm.org/D95178
2021-01-21 16:59:51 -08:00
peter klausler 0cfadb37f4 [flang] Allow NULL() actual argument for pointer dummy
Fixes a bogus error message about an actual argument not being an
object.

Differential Revision: https://reviews.llvm.org/D95176
2021-01-21 16:37:35 -08:00
peter klausler 3738447c96 [flang] Address name resolution problems
Don't emit a bogus error message about a bad forward reference
when it's an IMPORT of a USE-associated symbol; don't ignore
intrinsic functions when USE-associating the contents of a
module when the intrinsic has been explicitly USE'd; allow
PUBLIC or PRIVATE accessibility attribute to be specified
for an enumerator before the declaration of the enumerator.

Differential Revision: https://reviews.llvm.org/D95175
2021-01-21 16:15:38 -08:00
peter klausler a75840a09c [flang] Better C_LOC and C_ASSOCIATED in flang/module
The place-holding implementation of C_LOC just didn't work
when used with our more complete semantic checking, specifically
in the case of a polymorphic argument; convert it to an external
function with an implicit interface.  C_ASSOCIATED needs to be
a generic interface with specific implementations for C_PTR and
C_FUNPTR.

Differential Revision: https://reviews.llvm.org/D94714
2021-01-21 09:41:05 -08:00
Andrzej Warzynski aba24c1580 [flang][driver] Move fixed/free from detection out of FrontendAction API
All Fortran options should be set in `CompilerInstance` (via its
`CompilerInvocation`) before any of `FrontendAction` is entered -
that's one of the tasks of the driver. However, this is a bit tricky
with fixed and free from detection introduced in
https://reviews.llvm.org/D94228.

Fixed-free form detection needs to happen:
  * before any frontend action (we need to specify `isFixedForm` in
    `Fortran::parser::Options` before running any actions)
  * separately for every input file (we might be compiling multiple
    Fortran files, some in free form, some in fixed form)
In other words, we need this to happen early (before any
`FrontendAction`), but not too early (we need to know what the current
input file is). In practice, `isFixedForm` can only be set later
than other options (other options are inferred from compiler flags). So
we can't really set all of them in one place, which is not ideal.

All changes in this patch are NFCs (hence no new tests). Quick summary:
  * move fixed/free form detection from `FrontendAction::ExecuteAction` to
    `CompilerInstance::ExecuteAction`
  * add a bool flag in `FrontendInputFile` to mark a file as fixed/free
    form
  * updated a few comments

Differential Revision: https://reviews.llvm.org/D95042
2021-01-21 16:57:22 +00:00
Andrzej Warzynski 0eeb15741b [flang][driver] Make the driver report diagnostics from the prescanner
This patch makes sure that diagnostics from the prescanner are reported
when running `flang-new -E` (i.e. only the preprocessor phase is
requested). More specifically, the `PrintPreprocessedAction` action is
updated.

With this patch we make sure that the `f18` and `flang-new` provide
identical output when running the preprocessor and the prescanner
generates diagnostics.

Differential Revision: https://reviews.llvm.org/D94782
2021-01-21 15:06:32 +00:00
Peter Steinfeld bebbe64075 [flang] Fix creation of deferred shape arrays by POINTER statement
It's possible to  declare deferred shape array using the POINTER
statement, for example:

  POINTER :: var(:)

When analyzing POINTER declarations, we were not capturing the array
specification information, if present.  I fixed this by changing the
"Post" function for "parser::PointerDecl" to check to see if the
declaration contained a "DeferredShapeSpecList".  In such cases, I
analyzed the shape and used to information to declare an "ObjectEntity"
that contains the shape information rather than an "UnknownEntity".

I also added a couple of small tests that fail to compile without these
changes.

Differential Revision: https://reviews.llvm.org/D95080
2021-01-20 13:08:11 -08:00
peter klausler 0996b590aa [flang] Infrastructure improvements in utility routines
* IsArrayElement() needs another option to control whether it
  should ignore trailing component references.
* Add IsObjectPointer().
* Add const Scope& variants of IsFunction() and IsProcedure().
* Make TypeAndShape::Characterize() work with procedure bindings.
* Handle CHARACTER length in MeasureSizeInBytes().
* Fine-tune FindExternallyVisibleObject()'s handling of dummy arguments
  to conform with Fortran 2018: only INTENT(IN) and dummy pointers
  in pure functions signify; update two tests accordingly.

Also: resolve some stylistic inconsistencies and add a missing
"const" in the expression traversal template framework.

Differential Revision: https://reviews.llvm.org/D95011
2021-01-20 12:40:25 -08:00
Andrzej Warzynski b564b12bc6 [flang][driver] Refactor one unit-test case to use fixtures (nfc)
Move the unit test from InputOutputTest.cpp to FrontendActionTest.cpp
and re-implement it in terms of the FrontendActionTest fixture. This is
just a small code clean-up and a continuation of:
  * https://reviews.llvm.org/D93544

Moving forward, we should try be implementing all unit-test cases for
Flang's frontend actions in terms of FrontendActionTest.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D94922
2021-01-20 19:36:38 +00:00
peter klausler ff3b51b054 [flang] Fix ASSOCIATE statement name resolution
F18 Clause 19.4p9 says:

  The associate names of an ASSOCIATE construct have the scope of the
  block.

Clause 11.3.1p1 says the ASSOCIATE statement is not itself in the block:

  R1102 associate-construct is:  associate-stmt block end-associate-stmt

Associate statement associations are currently fully processed from left
to right, incorrectly interposing associating entities earlier in the
list on same-named entities in the host scope.

    1  program p
    2    logical :: a = .false.
    3    real :: b = 9.73
    4    associate (b => a, a => b)
    5      print*, a, b
    6    end associate
    7    print*, a, b
    8  end

Associating names 'a' and 'b' at line 4 in this code are now both
aliased to logical host entity 'a' at line 2.  This happens because the
reference to 'b' in the second association incorrectly resolves 'b' to
the entity in line 4 (already associated to 'a' at line 2), rather than
the 'b' at line 3.  With bridge code to process these associations,
f18 output is:

 F F
 F 9.73

It should be:

 9.73 F
 F 9.73

To fix this, names in right-hand side selector variables/expressions
must all be resolved before any left-hand side entities are resolved.
This is done by maintaining a stack of lists of associations, rather
than a stack of associations.  Each ASSOCIATE statement's list of
assocations is then visited once for right-hand side processing, and
once for left-hand side processing.

Note that other construct associations do not have this problem.
SELECT RANK and SELECT TYPE each have a single assocation, not a list.
Constraint C1113 prohibits the right-hand side of a CHANGE TEAM
association from referencing any left-hand side entity.

Differential Revision: https://reviews.llvm.org/D95010
2021-01-20 11:18:27 -08:00
peter klausler 24e8e21f19 [flang] Refine WhyNotModifiable()
The utility routine WhyNotModifiable() needed to become more
aware of the use of pointers in data-refs; the targets of
pointer components are sometimes modifiable even when the
leftmost ("base") symbol of a data-ref is not.

Added a new unit test for WhyNotModifiable() that uses internal
READ statements (mostly), since I/O semantic checking uses
WhyNotModifiable() for all its definability checking.

Differential Revision: https://reviews.llvm.org/D94849
2021-01-19 11:44:51 -08:00
Andrzej Warzynski cea3abc26f [flang][driver] Move isFixedFormSuffix and isFreeFormSuffix to flangFrontend
isFixedFormSuffix and isFreeFormSuffix should be defined in
flangFrontend rather than flangFrontendTool library. That's for 2
reasons:
  * these methods are used in flangFrontend rather than flangFrontendTool
  * flangFrontendTool depends on flangFrontend

As mentioned in the post-commit review for D94228, without this change
shared library builds fail.

Differential Revision: https://reviews.llvm.org/D94968
2021-01-19 17:47:40 +00:00
Valentin Clement 6bd0a4451c [flang][directive] Get rid of flangClassValue in TableGen
The TableGen emitter for directives has two slots for flangClass information and this was mainly
to be able to keep up with the legacy openmp parser at the time. Now that all clauses are encapsulated in
AccClause or OmpClause, these two strings are not necessary anymore and were the the source of couple
of problem while working with the generic structure checker for OpenMP.
This patch remove the flangClassValue string from DirectiveBase.td and use the string flangClass as the
placeholder for the encapsulated class.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D94821
2021-01-19 10:28:46 -05:00
Raul Tambre 480643a95c [CMake] Remove dead code setting policies to NEW
cmake_minimum_required(VERSION) calls cmake_policy(VERSION),
which sets all policies up to VERSION to NEW.
LLVM started requiring CMake 3.13 last year, so we can remove
a bunch of code setting policies prior to 3.13 to NEW as it
no longer has any effect.

Reviewed By: phosek, #libunwind, #libc, #libc_abi, ldionne

Differential Revision: https://reviews.llvm.org/D94374
2021-01-19 17:19:36 +02:00
Praveen c42f5ca3d8 [Flang][OpenMP] Add semantic checks for OpenMP Workshare Construct
Add Semantic checks for OpenMP 4.5 - 2.7.4 Workshare Construct.

 - The structured block in a workshare construct may consist of only
   scalar or array assignments, forall or where statements,
   forall, where, atomic, critical or parallel constructs.

 - All array assignments, scalar assignments, and masked array
   assignments must be intrinsic assignments.

 - The construct must not contain any user defined function calls unless
   the function is ELEMENTAL.

Test cases : omp-workshare03.f90, omp-workshare04.f90, omp-workshare05.f90

Resolve test cases (omp-workshare01.f90 and omp-workshare02.f90) marked as XFAIL

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D93091
2021-01-19 20:00:12 +05:30
Faris Rehman 197d9a55f1 [flang][driver] Add standard macro predefinitions for compiler version
Add the following standard predefinitions that f18 supports:
  * `__flang__`,
  * `__flang_major__`,
  * `__flang_minor__`,
  * `__flang_patchlevel__`

Summary of changes:
- Populate Fortran::parser::Options#predefinitions with the default
  supported predefinitions

Differential Revision: https://reviews.llvm.org/D94516
2021-01-19 13:22:59 +00:00
Faris Rehman 443d6957ca [flang][driver] Add support for fixed form detection
Currently the new flang driver always runs in free form mode. This patch
adds support for fixed form mode detection based on the file extensions.

Like `f18`, `flang-new` will treat files ending with ".f", ".F" and
".ff" as fixed form. Additionally, ".for", ".FOR", ".fpp" and ".FPP"
file extensions are recognised as fixed form files. This is consistent
with gfortran [1]. In summary, files with the following extensions are
treated as fixed-form:
  * ".f", ".F", ".ff", ".for", ".FOR", ".fpp", ".FPP"

For consistency with flang/test/lit.cfg.py and f18, this patch also adds
support for the following file extensions:
  * ".ff", ".FOR", ".for", ".ff90", ".fpp", ".FPP"
This is added in flang/lib/Frontend/FrontendOptions.cpp. Additionally,
the following extensions are included:
  * ".f03", ".F03", ".f08", ".F08"
This is for compatibility with gfortran [1] and other popular Fortran
compilers [2].

NOTE: internally Flang will only differentiate between fixed and free
form files. Currently Flang does not support switching between language
standards, so in this regard file extensions are irrelevant. More
specifically, both `file.f03` and `file.f18` are represented with
`Language::Fortran` (as opposed to e.g. `Language::Fortran03`).

Summary of changes:
- Set Fortran::parser::Options::sFixedForm according to the file type
- Add isFixedFormSuffix and isFreeFormSuffix helper functions to
  FrontendTool/Utils.h
- Change FrontendOptions::GetInputKindForExtension to support the missing
  file extensions that f18 supports and some additional ones
- FrontendActionTest.cpp is updated to make sure that the test input is
  treated as free-form

[1] https://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-and-GCC.html
[2] https://github.com/llvm/llvm-project/blob/master/flang/docs/OptionComparison.md#notes

Differential Revision: https://reviews.llvm.org/D94228
2021-01-19 12:58:01 +00:00
Faris Rehman 87dfd5e012 [flang][driver] Add support for `-I` in the new driver
Add support for option -I in the new Flang driver. This will allow for
included headers and module files in other directories, as the default
search path is currently the working folder. The behaviour of this is
consistent with the current f18 driver, where the current folder (i.e.
".") has the highest priority followed by the order of '-I's taking
priority from first to last.

Summary of changes:
- Add SearchDirectoriesFromDashI to PreprocessorOptions, to be forwarded
  into the parser's searchDirectories
- Add header files and non-functional module files to be used in
  regression tests. The module files are just text files and are used to
  demonstrated that paths specified with `-I` are taken into account when
  searching for .mod files.

Differential Revision: https://reviews.llvm.org/D93453
2021-01-19 11:20:56 +00:00
peter klausler 1bd083b5d6 [flang] Create names to allow access to inaccessible specifics
When a reference to a generic interface occurs in a specification
expression that must be emitted to a module file, we have a problem
when the generic resolves to a function whose name is inaccessible
due to being PRIVATE or due to a conflict with another use of the
same name in the scope.  In these cases, construct a new name for
the specific procedure and emit a renaming USE to the module file.
Also, relax enforcement of PRIVATE when analyzing module files.

Differential Revision: https://reviews.llvm.org/D94815
2021-01-15 16:56:38 -08:00
Andrzej Warzynski b6e06a740c [flang][driver] Copy test file into a temp dir when testing (nfc)
The following driver invocation will generate an output file
in the same directory as the input file:

```
flang-new -fc1 -test-io test-input.f90
```

This is the desired behaviour. However, when testing we need to make
sure that we don't pollute the source directory. To this end, copy the
input file into a temporary directory before testing.

This is similar to https://reviews.llvm.org/D94243.
2021-01-15 17:12:42 +00:00
Peter Steinfeld 1e1a011b09 [flang] Disallow INTENT attribute on procedure dummy arguments
C843 states that "An entity with the INTENT attribute shall be a dummy
data object or a dummy procedure pointer."  This change enforces that
and fixes some tests that erroneously violated this rule.

Differential Revision: https://reviews.llvm.org/D94781
2021-01-15 08:53:43 -08:00
Yashaswini 39665d9aab Add Semantic check for Flang OpenMP 4.5 - 2.7.1 Do Loop restrictions on single directive and firstprivate clause.
Semantic checks added to check the worksharing 'single' region closely nested inside a worksharing 'do' region. And also to check whether the 'do' iteration variable is a variable in 'Firstprivate' clause.

Files:
check-directive-structure.h
check-omp-structure.h
check-omp-structure.cpp

Testcases:
omp-do01-positivecase.f90
omp-do01.f90
omp-do05-positivecase.f90
omp-do05.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan , Valentin Clement @clementval

Differential Revision: https://reviews.llvm.org/D93205
2021-01-15 11:16:25 +05:30
Tim Keith d6acf3c201 [flang] Fix use-associated procedure in generic
When a use-associated procedure was included in a generic, we weren't
correctly recording that fact. The ultimate symbol was added rather than
the local symbol.

Also, improve the message emitted for the specific procedure by
mentioning the module it came from.

This fixes one of the problems in https://bugs.llvm.org/show_bug.cgi?id=48648.

Differential Revision: https://reviews.llvm.org/D94696
2021-01-14 16:31:52 -08:00
Valentin Clement ca98baa042 [openacc] Rename generated file from ACC.cpp.inc to ACC.inc to match D92955
This patch rename the tablegen generated file ACC.cpp.inc to ACC.inc in order
to match what was done in D92955. This file is included in header file as well as .cpp
file so it make more sense.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93485
2021-01-14 14:19:53 -05:00
peter klausler 4864d9f7e9 [flang] Fix some module file issues exposed by Whizard
Generic type-bound interfaces for user-defined operators need to be formatted
as "OPERATOR(.op.)", not just ".op."

PRIVATE generics need to be marked as such.

Declaration ordering: when a generic interface shadows a
derived type of the same name, it needs to be emitted to the
module file at the point of definition of the derived type;
otherwise, the derived type's definition may appear after its
first use.

The module symbol for a module read from a module file needs
to be marked as coming from a module file before semantic
processing is performed on the contents of the module so that
any special handling for declarations in module files can be
properly activated.

IMPORT statements were sometimes missing for use-associated
symbols in surrounding scopes; fine-tune NeedImport().

Differential Revision: https://reviews.llvm.org/D94636
2021-01-14 09:44:50 -08:00
Andrzej Warzynski 0afdbb4d2d [flang][driver] Use __FLANG_VERISION__ in f18.cpp (nfc)
Just a minor improvement suggested in a post-commit review here:
https://reviews.llvm.org/D94422
2021-01-14 16:51:49 +00:00
Tim Keith 3e41ab18db [flang] Fix dangling pointer in LabelEnforce
`DirectiveStructureChecker` was passing in a pointer to a temporary
string for the `construct` argument to the constructor for `LabelEnforce`.
The `LabelEnforce` object had a lifetime longer than the temporary,
resulting in accessing a dangling pointer when emitting an error message
for `omp-parallell01.f90`.

The fix is to make the lifetime of the temporary as long as the lifetime
of the `LabelEnforce` object.

Differential Revision: https://reviews.llvm.org/D94618
2021-01-14 06:52:21 -08:00
Andrzej Warzynski a1bbd1ef1d [flang][driver] Unify f18_version.h.in and Version.inc.in
Flang has two CMake configurable header files that define compiler
version numbers:
* f18_version.h.in - only used in f18.cpp (uses version numbers from
  LLVM's macro definitions)
* Version.inc.in - not currently used (uses version numbers hard-coded
  in Flang's top CMake script)

Currently only f18_version.h.in provides version numbers consistent with
other subprojects in llvm-project. However, its location and name are
inconsistent with e.g. Clang. This patch merges the two headers
together:
  * hard-coded version numbers in Flang's top CMake script are deleted
  * Version.inc.in is updated to provide string versions of version
  numbers (required by f18.cpp)
  * f18_version.h.in is deleted as it's no longer needed

Differential Revision: https://reviews.llvm.org/D94422
2021-01-14 13:50:46 +00:00
Peter Steinfeld 3de92ca78c [flang] Add tests for procedure arguments with implicit interfaces
It's possible to declare an external procedure and then pass it as an
actual argument to a subprogram expecting a procedure argument.  I added
tests for this and added an error message to distinguish passing an
actual argument with an implicit interface from passing an argument with
a mismatched explicit interface.

Differential Revision: https://reviews.llvm.org/D94505
2021-01-13 16:43:09 -08:00
Tim Keith 18278ff1aa [flang] Fix accessibility of USEd name in .mod file
If a module specifies default private accessibility, names that have
been use-associated are private by default. This was not reflected in
.mod files.

Differential Revision: https://reviews.llvm.org/D94602
2021-01-13 12:52:44 -08:00
peter klausler 166e5c335c [flang] Do not create HostAssoc symbols in derived type scopes
When needed due to a specification expression in a derived type,
the host association symbols should be created in the surrounding
subprogram's scope instead.

Differential Revision: https://reviews.llvm.org/D94567
2021-01-13 11:01:27 -08:00
peter klausler a50bb84ec0 [flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required.  The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not).  Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed.  Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.

Differential Revision: https://reviews.llvm.org/D94561
2021-01-13 10:05:14 -08:00
sameeran joshi 6f4d460762 [Flang][openmp][openacc] Extend CheckNoBranching to handle branching provided by LabelEnforce.
`CheckNoBranching` is currently handling only illegal branching out for constructs
with `Parser::Name` in them.
Extend the same for handling illegal branching out caused by `Parser::Label` based statements.
This patch could possibly solve one of the issues(typically branching out) mentioned in D92735.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D93447
2021-01-13 00:04:45 +05:30
Valentin Clement 47567ca5fa [flang][openxx][NFC] Remove duplicated function to check required clauses
Remove duplicated function to check for required clauses on a directive. This was
still there from the merging of OpenACC and OpenMP common semantic checks and it can now be
removed so we use only one function.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93575
2021-01-11 14:08:51 -05:00
Andrzej Warzynski 8298ec2d62 [flang][driver] Copy input files into a temp dir when testing
The following frontend driver invocation will generate 2 output files
in the same directory as the input files:
```
flang-new -fc1 input-1.f input-2.f
```
This is the desired behaviour. However, when testing we need to make
sure that we don't pollute the source directory. To this end, copy test
input files into a temporary directory.

Differential Revision: https://reviews.llvm.org/D94243
2021-01-11 13:54:19 +00:00
Peter Steinfeld ae0d1d2e5c [flang] Fix bogus message on internal subprogram with alternate return
Internal subprograms have explicit interfaces.  If an internal subprogram has
an alternate return, we check its explicit interface.  But we were not
putting the label values of alternate returns into the actual argument.

I fixed this by changing the definition of actual arguments to be able
to contain a common::Label and putting the label for an alternate return
into the actual argument.

I also verified that we were already doing all of the semantic checking
required for alternate returns and removed a "TODO" for this.

I also added the test altreturn06.f90.

Differential Revision: https://reviews.llvm.org/D94017
2021-01-08 10:14:21 -08:00
Valentin Clement b73736a404 [flang][openacc] Enforce delcare directive restriction
Add semantic check for most of the restrictions for the declare directive.

Reviewed By: kiranktp

Differential Revision: https://reviews.llvm.org/D92741
2021-01-07 09:28:55 -05:00
Andrzej Warzynski a2957f80f8 [flang][driver] Rename driver tests (nfc)
As per [1]:
```
File names should use dashes, not underscores.
```

This patch updates the names of Flang driver tests accordingly.

[1] https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md
2021-01-07 14:05:48 +00:00
Andrzej Warzynski e5cdb6c56e [flang][driver] Add support for `-c` and `-emit-obj`
This patch adds a frontend action for emitting object files. While Flang
does not support code-generation, this action remains a placeholder.
This patch simply provides glue-code to connect the compiler driver
with the appropriate frontend action.

The new action is triggered with the `-c` compiler driver flag, i.e.
`flang-new -c`. This is then translated to `flang-new -fc1 -emit-obj`,
so `-emit-obj` has to be marked as supported as well.

As code-generation is not available yet, `flang-new -c` results in a
driver error:
```
error: code-generation is not available yet
```
Hopefully this will help communicating the level of available
functionality within Flang.

The definition of `emit-obj` is updated so that it can be shared between
Clang and Flang. As the original definition was enclosed within a
Clang-specific TableGen `let` statement, it is extracted into a new `let`
statement. That felt like the cleanest option.

I also commented out `-triple` in Flang::ConstructJob and updated some
comments there. This is similar to https://reviews.llvm.org/D93027. I
wanted to make sure that it's clear that we can't support `-triple`
until we have code-generation. However, once code-generation is
available we _will need_ `-triple`.

As this patch adds `-emit-obj`, the emit-obj.f90 becomes irrelevant and
is deleted. Instead, phases.f90 is added to demonstrate that users can
control compilation phases (indeed, `-c` is a phase control flag).

Reviewed By: SouraVX, clementval

Differential Revision: https://reviews.llvm.org/D93301
2021-01-07 10:52:38 +00:00
Valentin Clement 322e98bc27 [flang][openacc] Add more parsing/sema tests for init and shutdown directives
This patch adds some positive and failure tests for init and shutdown directives.

Reviewed By: kiranktp

Differential Revision: https://reviews.llvm.org/D90786
2021-01-06 14:15:19 -05:00
Faris Rehman 7809fa2040 [flang][driver] Add support for `-D`, `-U`
Add support for options -D and -U in the new Flang driver.

Summary of changes:
  - Create PreprocessorOptions, to be used by the driver then translated
    into Fortran::parser::Options
  - Create CompilerInvocation::setFortranOpts to pass preprocessor
    options into the parser options
  - Add a dedicated method, Flang::AddPreprocessingOptions, to extract
    preprocessing options from the driver arguments into the preprocessor
    command arguments

Macros specified like -DName will default to definition 1.

When defining macros, the new driver will drop anything after an
end-of-line character. This is consistent with gfortran and clang, but
different to what currently f18 does. However, flang (which is a bash
wrapper for f18), also drops everything after an end-of-line character.
So gfortran-like behaviour felt like the natural choice. Test is added
to demonstrate this behaviour.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D93401
2021-01-06 16:17:13 +00:00
Andrzej Warzynski fa1e543e0b [flang][driver] Update error messages (nfc)
As per Flang's coding guidelines
(flang/docs/C++style.md#error-messages):
```
Messages should start with a capital letter.
```

This patch updates error messages in the driver (new and old) so that
they conform with the guideline above.

This change was suggested in one of the recent reviews:
https://reviews.llvm.org/D93712. It felt like this deserved a dedicated
patch, so sending it separately.
2021-01-06 10:41:27 +00:00
Andrzej Warzynski e49dc2981c [flang][driver] Add checks for errors from `Prescan` and `Parse`
If either `Prescan` or `Parse` generate any fatal errors, the new driver
will:
  * report it (i.e. issue an error diagnostic)
  * exit early
  * return non-zero exit code
This behaviour is consistent with f18 (i.e. the old driver).

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93712
2021-01-06 10:19:44 +00:00
Valentin Clement 4d0aad96e4 [flang][openmp] Make Reduction clause part of OmpClause
After discussion in D93105 we found that the reduction clause was not following
the common OmpClause convention. This patch makes reduction clause part of OmpClause
with a value of OmpReductionClause in a similar way than task_reduction.
The unparse function for OmpReductionClause is adapted since the keyword and parenthesis
are issued by the corresponding unparse function for parser::OmpClause::Reduction.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93482
2021-01-04 15:19:00 -05:00
sameeran joshi 6280bc1cc3 [Flang][openmp][5.0] Add task_reduction clause.
See OMP-5.0 2.19.5.5 task_reduction Clause.
To add a positive test case we need `taskgroup` directive which is not added hence skipping the test.
This is a dependency for `taskgroup` construct.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D93105

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-01-04 08:48:11 +05:30
Tim Keith f782d5ea86 [flang] Detect call to abstract interface
A subroutine call or function reference to an abstract interface is
not legal.

Differential Revision: https://reviews.llvm.org/D93872
2020-12-28 16:36:34 -08:00