Commit Graph

3095 Commits

Author SHA1 Message Date
Andrzej Warzynski af8056889a [flang][cmake] Improve how CLANG_DIR is handled
* Added a sanity check with `Clang_FOUND` to verify that find_package
succeeded
* Made sure that find_package won't use any of CMake's standard paths
to guarantee that only the path provided with CLANG_DIR is considered
(implemented through NO_DEFAULT_PATH)
* Made the call to get_filename_component more explicit (so that it is
clear what the base directory is)
* Updated comments to clarify what CLANG_DIR means

Differential Revision: https://reviews.llvm.org/D99088
2021-03-23 15:14:51 +00:00
Peter Steinfeld e97d92f0bb [flang] Disallow erroneous procedure declarations
When writing tests for a previous problem, I ran across situations where we
were not producing error messages for declarations of specific procedures of
generic interfaces where every other compiler I tested (except nvfotran) did.
I added a check to CheckExtantExternal() and renamed it since it now checks for
erroneous extant symbols generally.

I also removed a call to this function from processing for ENTRY statements,
since it seemed unnecessary and its presence caused bogus error messages.

I also added some tests for erroneous declarations where we were not producing
error messages.

Differential Revision: https://reviews.llvm.org/D99111
2021-03-22 14:52:45 -07:00
Peter Steinfeld 5727df2714 [flang] Specific procedures named the same as the generic and a derived type
If you specify a specific procedure of a generic interface that has the same
name as both the generic interface and a preceding derived type, the compiler
would fail an internal call to CHECK().  I fixed this by testing for this
situation when processing specific procedures.  I also added a test that will
cause the call to CHECK() to fail without this new code.

Differential Revision: https://reviews.llvm.org/D99085
2021-03-22 10:52:50 -07:00
Arnamoy Bhattacharyya e27654f737 [Flang][OpenMP] Add more sema checks for ordered construct
This patch fixes a bug to allow ordered construct within a non-worksharing loop, also adds more sema checks.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D98733
2021-03-19 14:56:40 -04:00
peter klausler 0d8331c06b [flang] Refine symbol sorting
Replace semantics::SymbolSet with alternatives that clarify
whether the set should order its contents by source position
or not.  This matters because positionally-ordered sets must
not be used for Symbols that might be subjected to name
replacement during name resolution, and address-ordered
sets must not be used (without sorting) in circumstances
where the order of their contents affects the output of the
compiler.

All set<> and map<> instances in the compiler that are keyed
by Symbols now have explicit Compare types in their template
instantiations.  Symbol::operator< is no more.

Differential Revision: https://reviews.llvm.org/D98878
2021-03-18 11:18:14 -07:00
Asher Mancinelli 168b206cd8 [flang] Unittests for runtime terminator
Create test fixture for runtime tests which enables verification
of failure cases. Test some runtime IO APIs for failure cases.
Support testing efforts in D98303. Expand on effort discussed
in D98601.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D98652
2021-03-18 15:54:48 +00:00
Andrzej Warzynski eefda605fe [flang][driver] Add support for `-fget-symbols-sources`
Adds support for `-fget-symbols-sources` in the new Flang driver. All
relevant tests are updated to use the new driver when
`FLANG_BUILD_NEW_DRIVER` is set.

`RUN` lines in tests are updated so `-fsyntax-only`
comes before `-fget-symbols-sources`. That's because:
  * both `-fsyntax-only` and `-fget-symbols-sources` are
    action flags, and
  * the new driver, flang-new, will only consider the right-most
    action flag.
In other words, this change is needed so that the tests work with both
`f18` (requires both flags) and `flang-new` (only considers the last
action flag).

Differential Revision: https://reviews.llvm.org/D98191
2021-03-18 14:13:24 +00:00
Mike Rice c615927c8e [OPENMP51]Initial support for the use clause.
Added basic parsing/sema/serialization support for the 'use' clause.

Differential Revision: https://reviews.llvm.org/D98815
2021-03-17 15:46:14 -07:00
Mike Rice 410f09af09 [OPENMP51]Initial support for the interop directive.
Added basic parsing/sema/serialization support for interop directive.
Support for the 'init' clause.

Differential Revision: https://reviews.llvm.org/D98558
2021-03-17 09:42:07 -07:00
Praveen 1d7960a601 [Flang][OpenMP][OpenACC] Add function for mapping parser clause classes with the corresponding clause kind.
1. Generate the mapping for clauses between the parser class and the
   corresponding clause kind for OpenMP and OpenACC using tablegen.

2. Add a common function to get the OmpObjectList from the OpenMP
   clauses to avoid repetition of code.

Reviewed by: Kiranchandramohan @kiranchandramohan , Valentin Clement @clementval

Differential Revision: https://reviews.llvm.org/D98603
2021-03-17 12:20:43 +05:30
Sourabh Singh Tomar 8ca16e9778 [flang] Replace Arithmetic Ops with their builtin conunterpart
Replaces `fir.add, fir.sub, fir.mul, fir.div` with their builtin
conuterparts.

This part of upstreaming effort, upstreams some parts of:
PR:https://github.com/flang-compiler/f18-llvm-project/pull/681

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D98719
2021-03-17 08:58:10 +05:30
peter klausler 539bbbe7b5 [flang] Fix build error (unused data member warning)
Differential Revision: https://reviews.llvm.org/D98752
2021-03-16 17:21:09 -07:00
peter klausler 46ade6d0ef [flang] Order Symbols by source provenance
In parser::AllCookedSources, implement a map from CharBlocks to
the CookedSource instances that they cover.  This permits a fast
Find() operation based on std::map::equal_range to map a CharBlock
to its enclosing CookedSource instance.

Add a creation order number to each CookedSource.  This allows
AllCookedSources to provide a Precedes(x,y) predicate that is a
true source stream ordering between two CharBlocks -- x is less
than y if it is in an earlier CookedSource, or in the same
CookedSource at an earlier position.

Add a reference to the singleton SemanticsContext to each Scope.

All of this allows operator< to be implemented on Symbols by
means of a true source ordering.  From a Symbol, we get to
its Scope, then to the SemanticsContext, and then use its
AllCookedSources reference to call Precedes().

Differential Revision: https://reviews.llvm.org/D98743
2021-03-16 15:25:15 -07:00
Jean Perier 92d27b969a [flang] Save AllocateObject and PointerObject analyzed expression
`parser::AllocateObject` and `parser::PointerObject` can be represented
as typed expressions once analyzed. This simplifies the work for parse-tree
consumers that work with typed expressions to deal with allocatable and
pointer objects such as lowering.

This change also makes it easier to add typedExpr in the future by
automatically handling nodes that have this member when possible.

Changes:

- Add a `mutable TypedExpr typedExpr` field to `parser::PointerObject` and `parser::AllocateObject`.
- Add a `parser::HasTypedExpr<T>` helper to better share code relating to typedExpr in the parse tree.
- Add hooks in `semantics::ExprChecker` for AllocateObject and PointerObject nodes, and use
  ExprOrVariable on it to analyze and set the tyedExpr field during
  expression analysis. This required adding overloads for `AssumedTypeDummy`.
- Update check-nullify.cpp and check-deallocate.cpp to not re-analyze the StructureComponent but to
  use the typedExpr field instead.
- Update dump/unparse to use HasTypedExpr and use the typedExpr when there is one.

Differential Revision: https://reviews.llvm.org/D98256
2021-03-16 10:27:45 +01:00
Tim Keith bcf95cbb2c [flang] Create intrinsics modules directory (contd.)
Use -module-dir rather than WORKING_DIRECTORY because we are potentially
creating the working directory in this custom command.
2021-03-15 15:38:05 -07:00
Tim Keith 566a2c18bf [flang] Create intrinsics modules directory
A clean build fails using make because the intrinsics modules directory
doesn't exist. For some reason it works fine with ninja.
2021-03-15 15:19:30 -07:00
peter klausler 6811b96100 [flang] Runtime: implement INDEX intrinsic function
Implement INDEX in the runtime, reusing some infrastructure
(with generalization and renaming as needed) put into place
for its cousins SCAN and VERIFY.

I did not implement full Boyer-Moore substring searching
for the forward case, but did accelerate some advancement on
mismatches.

I (re)implemented unit testing for INDEX in the new gtest
framework, combining it with the tests that have recently
been ported to gtest for SCAN and VERIFY.

Differential Revision: https://reviews.llvm.org/D98553
2021-03-15 14:19:13 -07:00
Andrzej Warzynski da408d98d7 [flang][docs] Fix the time for the new Flang driver call 2021-03-15 17:25:55 +00:00
Tim Keith 8e1c09ee5f [flang] Build intrinsic .mod files in include/flang
The build was putting .mod files for intrinsic modules in
tools/flang/include/flang but the install puts them in include/flang,
as does the out-of-tree build. This confused things for the driver.
This change makes the build consistent with the install and simplifies
the flang script accordingly.

Also, clean up the cmake commands for building the .mod files.

Differential Revision: https://reviews.llvm.org/D98522
2021-03-15 08:03:02 -07:00
Arnamoy Bhattacharyya 3fc9ca87f1 [flang][OpenMP] Add support for getting parent context and clauses and modify the relevant sema checks to use the new functions.
Differential Revision: https://reviews.llvm.org/D98580
2021-03-13 17:50:50 -05:00
peter klausler 59f213c162 [flang] Fix static build of flang
An older version of a function (Fortran::semantics::FindFunctionResult) was
left in flang/lib/Semantics/tools.cpp, and this breaks the static library
build due to a conflict with the intended final version in another
file and library.  Remove the old code.

Differential Revision: https://reviews.llvm.org/D98568
2021-03-12 17:38:29 -08:00
peter klausler bbd0dc3d65 [flang] Ensure pointer function results are acceptable variables
Fortran permits a reference to a function whose result is a pointer
to be used as a definable variable in any context where a
designator could appear.  This patch wrings out remaining bugs
with such usage and adds more testing.

The utility predicate IsProcedurePointer(expr) had a misleading
name which has been corrected to IsProcedurePointerTarget(expr).

Differential Revision: https://reviews.llvm.org/D98555
2021-03-12 16:04:36 -08:00
peter klausler 170e906159 [flang] Update DE/ALLOCATE statement runtime message processing
Make error message descriptors on runtime DE/ALLOCATE API calls constant.
Fix a bug in error message truncation/padding.

Differential Revision: https://reviews.llvm.org/D98551
2021-03-12 15:42:06 -08:00
Arnamoy Bhattacharyya a59665930b [flang][OpenMP][FIX] Fix function to check nesting level of current directive. 2021-03-12 15:01:47 -05:00
Peter Steinfeld 085d794c5f [flang] Make the symbol count used for collating symbols static
I changed the declaration of symbolCount_ in the type Symbols to be
static to avoid possible problems in the future when we might have
multiple objects of type Symbols.  Thanks to Peter for pointing out the
need for this change.

Differential Revision: https://reviews.llvm.org/D98357
2021-03-12 10:56:39 -08:00
Yashaswini 96716e6749 Add Semantic check for Flang OpenMP 4.5 - 2.15.3.6 Reduction clause
Implementation of Reduction clause restriction checks.

Files:

flang/lib/Semantics/check-directive-structure.h
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/lib/Semantics/resolve-directives.cpp

Testcases:

flang/test/Semantics/omp-reduction01.f90
flang/test/Semantics/omp-reduction02.f90
flang/test/Semantics/omp-reduction03.f90
flang/test/Semantics/omp-reduction04.f90
flang/test/Semantics/omp-reduction05.f90
flang/test/Semantics/omp-reduction06.f90
flang/test/Semantics/omp-reduction07.f90
flang/test/Semantics/omp-reduction08.f90
flang/test/Semantics/omp-reduction09.f90
flang/test/Semantics/omp-reduction10.f90
flang/test/Semantics/omp-symbol08.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan and Valentin Clement @clementval.

Differential Revision: https://reviews.llvm.org/D90697
2021-03-12 22:58:14 +05:30
River Riddle 31bb8efd69 [mlir][StorageUniquer] Properly call the destructor on non-trivially destructible storage instances
This allows for storage instances to store data that isn't uniqued in the context, or contain otherwise non-trivial logic, in the rare situations that they occur. Storage instances with trivial destructors will still have their destructor skipped. A consequence of this is that the storage instance definition must be visible from the place that registers the type.

Differential Revision: https://reviews.llvm.org/D98311
2021-03-11 11:35:32 -08:00
Peter Steinfeld 868187df21 [flang] Handle type-bound procedures with alternate returns
If you specify a type-bound procedure with an alternate return, there
will be no symbol associated with that dummy argument.  In such cases,
the compiler's list of dummy arguments will contain a nullptr.  In our
analysis of the PASS arguments of type-bound procedures, we were
assuming that all dummy arguments had non-null symbols associated with
them and were using that assumption to get the name of the dummy
argument.  This caused the compiler to try to dereference a nullptr.

I fixed this by explicitly checking for a nullptr and, in such cases, emitting
an error message.  I also added tests that contain type-bound procedures with
alternate returns in both legal and illegal constructs to ensure that semantic
analysis is working for them.

Differential Revision: https://reviews.llvm.org/D98430
2021-03-11 10:20:34 -08:00
Arnamoy Bhattacharyya e361afb6c5 [flang][OpenMP] Add semantic check for occurrence of multiple list items in aligned clause for simd directive
Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D97964
2021-03-11 10:01:21 -05:00
Arnamoy Bhattacharyya 1fd4beecc8 [flang][driver] Add -fdebug-module-writer option 2021-03-11 08:04:37 -05:00
Leonard Chan baf637dcde Rename top-level LICENSE.txt files to LICENSE.TXT
This makes all the license filenames uniform across subprojects.

Differential Revision: https://reviews.llvm.org/D98380
2021-03-10 21:26:24 -08:00
Arnamoy Bhattacharyya 361e9bf97e [flang][driver] Formatting OpenMP sema check as per clang-format 2021-03-10 16:54:07 -05:00
Peter Steinfeld 40e261803b [flang] Fix call to CHECK() on overriding an erroneous type-bound procedure
You can define a base type with a type-bound procedure which is erroneously
missing a NOPASS attribute and then define another type that extends the base
type and overrides the erroneous procedure.  In this case, when we perform
semantic checking on the overriding procedure, we verify the "pass index" of
the overriding procedure.  The attempt to get the procedure's pass index fails
a call to CHECK().

I fixed this by calling SetError() on the symbol of the overridden procedure in
the base type.  Then, I check HasError() before executing the code that invokes
the failing call to CHECK().  I also added a test that will cause the compiler
to fail the call to CHECK() without this change.

Differential Revision: https://reviews.llvm.org/D98355
2021-03-10 09:38:29 -08:00
Andrzej Warzynski 547624af19 [flang][driver] Revert RUN-line change
In https://reviews.llvm.org/D98283, the RUN line in pre-fir-tree04.f90
was updated to use `%flang_fc1` instead of `%f18` (so that the test is
shared between the old and the new driver). Unfortunately, the new
driver does not know yet how to find standard intrinsics modules. As a
result, the test fails when `FLANG_BUILD_NEW_DRIVER` is set to On.

I'm restoring the original RUN line. This is rather straightforward, so
sending without a review. This should make Flang builders happy.
2021-03-10 16:58:24 +00:00
Eric Schweitz 987ee6e3cc [flang][fir] Upstream the pre-FIR tree changes.
The PFT has been updated to support Fortran 77.
clang-tidy cleanup.

Authors: Val Donaldson, Jean Perier, Eric Schweitz, et.al.

Differential Revision: https://reviews.llvm.org/D98283
2021-03-10 07:45:58 -08:00
Andrzej Warzynski 523d7bc6f4 [flang][driver] Add `-fdebug-dump-parsing-log`
This patch adds `-fdebug-dump-parsing-log` in the new driver. This option is
semantically identical to `-fdebug-instrumented-parse` in `f18` (the
former is added as an alias in `f18`).

As dumping the parsing log makes only sense for instrumented parses, we
set Fortran::parser::Options::instrumentedParse to `True` when
`-fdebug-dump-parsing-log` is used. This is consistent with `f18`.

To facilitate tweaking the configuration of the frontend based on the
action being requested, `setUpFrontendBasedOnAction` is introduced in
CompilerInvocation.cpp.

Differential Revision: https://reviews.llvm.org/D97457
2021-03-10 12:09:16 +00:00
Andrzej Warzynski 45da495f73 [flang][driver] Merge test/Driver and test/Flang-Driver directories
Until now we've been maintaining 2 test directories for Flang's drivers:
  * test/Driver for `f18` (the current driver)
  * test/Flang-Driver for `flang-new` (the new driver)
As we have started sharing tests between the drivers, this separation is
no longer required. This patch merges the two test directories. As
suggested in the review, moving forward we'll avoid having tests
specifically for the old driver.

A few notable changes:
  * Driver/version-test.f90 and Driver/no-files.f90 are deleted. The
  versions for the new driver are more robust, but tricky to share.
  * Driver/write-module.f90 is deleted in favour of
    Flang-Driver/write-module.f90 (see https://reviews.llvm.org/D97197
    for more context)

Differential Revision: https://reviews.llvm.org/D98257
2021-03-10 11:38:13 +00:00
Mehdi Amini 890afad954 Fix Flang build after MLIR API changes around `generatedTypeParser` 2021-03-09 23:19:30 +00:00
Peter Steinfeld 63200a058e [flang] Sort symbols by creation order
We have a "<" operator defined on the type semantics::Symbol that's based on
the symbols' locations in the cooked character stream.  This is potentially
problematic when comparing symbols from .mod files when the cooked character
streams themselves might be allocated to varying memory locations.

This change fixes that by using the order in which symbols are created as the
basis for the "<" operator.  Thanks to Tim and Peter for consultation on the
necessity of doing this and the idea for what to use as the basis of the sort.

This change in the "<" operator changed the expected results for three of the
tests.  I manually inspected the new results, and they look OK to me.  The
differences in data05.f90 and typeinfo01.f90 are entirely the order, offsets,
and sizes of the derived type components.  The changes in resolve102.f90 are
due to the new, different "<" operator used for sorting.

Differential Revision: https://reviews.llvm.org/D98225
2021-03-09 12:35:32 -08:00
Andrzej Warzynski b04fbc1913 [flang][driver] Refine tests for module search directories
This patch refactors include-module.f90:
  * rename the test file as use-module.f90 to better highlight which
  driver feature is being tested
  * move tests for diagnostics to use-module-error.f90 (it tests that
  `-J/-module-dir` can only be used once)
  * make sure that `f18` is tested when `FLANG_BUILD_NEW_DRIVER` is
  set to `Off`
  * add tests for when all module files are successfully discovered and
  loaded

With this patch, there should be a clear separation into 3 scenarios in
use-module.f90:
  * Everything is OK
  * One module file wasn't found (missing include path for
  basictestingmoduletwo.mod)
  * Two module files are found, but the test requires
  `basictestingmoduleone.mod` from both `Inputs` and `Inputs/module-dir`.
  Only the latter is found.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D97197
2021-03-09 15:26:48 +00:00
Asher Mancinelli 95193ac5ba [flang] update character tests to use gtest
Move character tests to gtest, according to reviews from revision
D97349. Create a new temporary directory parallel to old runtime
unittests directory to facilitate the transition. Once patches for all
tests have been accepted using GTest, the old directory may be removed.
The new directory is required because LLVM's CMake unit test
infrastructure requires that the test depends on all source files in
the `CMAKE_CURRENT_SOURCE_DIR` directory.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D97403
2021-03-09 08:31:20 +00:00
Peter Steinfeld cfd7d8123a [flang] Fix bad dereference of NULLIFY pointer object
When we have a subprogram that has been determined to contain errors, we do not
perform name resolution on its execution part.  In this case, if the subprogram
contains a NULLIFY statement, the parser::Name of a pointer object in a NULLIFY
statement will not have had name resolution performed on it.  Thus, its symbol
will not have been set.  Later, however, we do semantic checking on the NULLIFY
statement.  The code that did this assumed that the parser::Name of the
pointer object was non-null.

I fixed this by just removing the null pointer check for the "symbol" member of
the "parser::Name" of the pointer object when doing semantic checking for
NULLIFY statements.  I also added a test that will make the compiler crash
without this change.

Differential Revision: https://reviews.llvm.org/D98184
2021-03-08 15:01:36 -08:00
Yashaswini a89a3c2c7d Add Semantic check for Flang OpenMP 4.5 - 2.7.1 Do Loop restrictions for Threadprivate.
Implementation of Do loop threadprivate check.

Files:

resolve-directives.cpp

Testcases:

omp-do04-positivecase.f90
omp-do04.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan

Differential Revision: https://reviews.llvm.org/D96686
2021-03-08 20:32:26 +05:30
Valentin Clement c3e5f504a0 [flang][fir] Add FIR Types parser diagnostic tests + cleanup
Add diagnostic tests for Types parsers and remove duplicated diagnostics handled by the MLIR
parser.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D97643
2021-03-05 14:58:44 -05:00
Valentin Clement d090f42778 [flang][fir] Add diagnostic tests for FIR ops verifier
Add diagnostic tests with fir-opt for the diagnostics emitted by the ops verifier

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D97996
2021-03-05 10:21:17 -05:00
Eric Schweitz 21c8e1b00a [flang][fir][NFC] Update comments. 2021-03-04 13:31:21 -08:00
Arnamoy Bhattacharyya ab971c29a5 [flang][driver] Add options for -fdefault* and -flarge-sizes
Add support for the following Fortran dialect options:
  - -default*
  - -flarge-sizes

It also adds two test cases:
  # For checking whether `flang-new` is passing options correctly to `flang-new -fc1`.
  # For checking if `fdefault-` arguments are processed properly.

Also moves the Dialect related option parsing to a dedicated function
and adds a member `defaultKinds()` to `CompilerInvocation`

Depends on: D96032

Differential Revision: https://reviews.llvm.org/D96344
2021-03-04 13:29:07 +00:00
Alex Zinenko 32c49c7d73 [mlir] ODS: change OpBuilderDAG to OpBuilder
We no longer have the non-DAG version.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D97856
2021-03-04 10:55:02 +01:00
Alex Zinenko 19db802e7b [mlir] make implementations of translation to LLVM IR interfaces private
There is no need for the interface implementations to be exposed, opaque
registration functions are sufficient for all users, similarly to passes.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D97852
2021-03-04 09:16:32 +01:00
River Riddle 64be3fcb7a Fix flang build after D97804 2021-03-03 15:07:03 -08:00