8992 Commits

Author SHA1 Message Date
David Truby
054eadcb11
[flang] Implement GETUID and GETGID intrinsics (#108017)
GETUID and GETGID are non-standard intrinsics supported by a number of
other Fortran compilers. On supported platforms these intrinsics simply
call the POSIX getuid() and getgid() functions and return the result.
The only platform we support that does not have these is Windows.

Windows does not have the same concept of UIDs and GIDs, so on Windows
we issue a warning indicating this and return 1 from both functions.

Co-authored-by: Yi Wu <yi.wu2@arm.com>

---------

Co-authored-by: Yi Wu <yi.wu2@arm.com>
2024-09-30 14:36:39 +01:00
Abid Qadeer
d556e38fe8
[flang][debug] Support derived type components with box types. (#109424)
Our support for derived types uses `getTypeSizeAndAlignment` to
calculate the offset of the members. The `fir.box` was not supported in
that function. It meant that any member which required descriptor was
not supported in the derived type.
    
We convert the type into an llvm type and then use the DataLayout to
calculate the size/offset of a member. There is no dependency on
`getTypeSizeAndAlignment` to get the size of the types.

There are 2 other changes in this PR:

1. The `recID` field is used to handle cases where we have a member
references its parent type.

2. A type cache is maintained to avoid duplication. It is also needed
for circular reference case.


Fixes #108001.
2024-09-30 10:31:56 +01:00
chandan singh
2a005bff18
[Flang][OpenMP] Fix for error in atomic read for different elements of the common symbol #80399 (#109265)
Fixes issue https://github.com/llvm/llvm-project/issues/80399
2024-09-28 08:12:29 +05:30
agozillon
3625f9f615
[Flang][Driver][Offload] Support -Xoffload-linker argument in Flang (#109907)
The -Xoffload-linker command allows forwarding of linker commands to the
clang-linker-wrapper used for linking offload libraries into the
resulting offload binaries amongst other tasks. This is a rather useful
command to have to support the offloading programming models flang-new
currently aims to support (OpenMP/OpenACC).

Currently this flag is utilised in the check-offload tests after a
recent addition and is used in conjunction with the Fortran OpenMP test
suite there, which fails at the moment due to flang-new not recognizing
the command, this fixes the issue. The alternative to this would of
course be to setup the test config to avoid using this flag with
Fortran, but I believe adding support of the flag to flang-new has more
merit as having the same compatability/communication capabilities as
Clang to the clang-linker-wrapper is important as it's a critical
component of the offload pipeline, and the command will likely see more
use in the near future.
2024-09-27 18:17:53 +02:00
Paul Osmialowski
84a0a3d3b3
[flang][driver] Make the -J option less restrictive so we would not have to struggle with autoconf (#110010)
There are autoconf-configured projects for which the generated Makefile
is invoking flang with more than one -J option, each one specifying the
same directory. Although only one module directory should be specified
(by either -J or -module-dir), it should not really matter how many
times this same directory has been specified.

Apparently, other compilers understand it that way, hence autoconf's
configure script may generate a Makefile with the repetitive -J's.

For example, when trying to build the ABINIT [1] project (which can be
configured by either CMake or the configure script) when configured by
autoconf, it fails to build as such:

```
make[3]: Entering directory 'src/98_main'
mpifort -DHAVE_CONFIG_H -I. -I../../../src/98_main -I../..  -I../../src/incs -I../../../src/incs -Ifallbacks/exports/include  -Jbuild/mods  -Jbuild/mods -c -o abinit-abinit.o `test -f 'abinit.F90' || echo '../../../src/98_main/'`abinit.F90
error: Only one '-module-dir/-J' option allowed
make[3]: *** [Makefile:3961: abinit-abinit.o] Error 1
```

This patch solves the problem.

[1] https://github.com/abinit/abinit.git
2024-09-27 16:01:25 +01:00
Tarun Prabhu
8ea2b41741
[flang][Driver] Support -fdiagnostics-color
Add support for -fdiagnostics-color and -fdiagnostics-color=. Add
documentation for -fdiagnostics-color= which should also be visible in
clang.

Partially addresses requests in #89888
2024-09-26 12:59:02 -06:00
Raghu Maddhipatla
f0162fcd7b
[NFC] [Flang] [Semantics] [OpenMP] Fix typo in error message. (#110147)
Fix typo which should be "at least" instead of "at lease".
2024-09-26 12:58:09 -05:00
Krzysztof Parzyszek
00ab44ee66
[flang][OpenMP] Add version checks for clauses (#110015)
If there is a clause that is allowed on a given directive in a later
version of the OpenMP spec, report an error and provide the minimal spec
version that allows the clause.

The case where a clause is not allowed on a directive at all is already
handled elsewhere.
2024-09-26 08:56:41 -05:00
Krzysztof Parzyszek
3b20a833cb
[flang][Semantics] Add LangOptions to SemanticsContext (#110013)
The motivation for this is to make OpenMP settings visible in the
semantic checks (OpenMP version in particular).
2024-09-26 08:56:22 -05:00
Krzysztof Parzyszek
58e8683a31
[flang][Frontend] Move LangOptions from Frontend to Common (#110012)
The information in LangOptions is not tied to any frontend code, and
could be used by any other component.
2024-09-26 08:56:04 -05:00
Kareem Ergawy
497523b695
[flang][OpenMP] Delayed privatization MLIR lowering support for distribute (#109632)
Starts delayed privatizaiton support for standalone `distribute`
directives. Other flavours of `distribute` are still TODO as well as
MLIR to LLVM IR lowering.
2024-09-26 12:28:14 +02:00
Kadir Cetinkaya
2ad435f9f6
Revert "[clang] Extend diagnose_if to accept more detailed warning information (#70976)"
This reverts commit e39205654dc11c50bd117e8ccac243a641ebd71f.

There are further discussions in
https://github.com/llvm/llvm-project/pull/70976, happening for past two
weeks. Since there were no responses for couple weeks now, reverting
until author is back.
2024-09-26 12:16:07 +02:00
jeanPerier
d9250061e1
[flang] add fir.proc_attrs attributes to func.func (#110002)
BIND(C) ABI need care in the TargetRewrite pass. currently, we are not
able to accurately identify fun.func that are BIND(C) in FIR (the
fir.bindc_name is used in other contexts, like for program names).

This patch adds the fir.proc_attrs to func.func just like it was done
for calls recently. This replace the previous named attribute for
PURE/ELEMENTAL/RECURSIVE (note that RECURSIVE is changed to
NON_RECURSIVE, which brings more data since RECURSIVE is the default for
procedures that do not have explicit RECURSIVE/NON_RECUSRIVE
attributes).
2024-09-26 11:11:44 +02:00
Abid Qadeer
69ef3b102c
[flang][debug] Allow variable length for dummy char arguments. (#109448)
As pointed out by @jeanPerier
[here](https://github.com/llvm/llvm-project/pull/108283#discussion_r1764528809),
we don't need to restrict the length of the dummy character argument
location to `fir.unboxchar`. This PR removes that restriction.
2024-09-26 10:08:48 +01:00
Sirui Mu
fde3c16ac9
[mlir][LLVM] Add operand bundle support (#108933)
This PR adds LLVM [operand
bundle](https://llvm.org/docs/LangRef.html#operand-bundles) support to
MLIR LLVM dialect. It affects these 3 operations related to making
function calls: `llvm.call`, `llvm.invoke`, and `llvm.call_intrinsic`.

This PR adds two new parameters to each of the 3 operations. The first
parameter is a variadic operand `op_bundle_operands` that contains the
SSA values for operand bundles. The second parameter is a property
`op_bundle_tags` which holds an array of strings that represent the tags
of each operand bundle.
2024-09-26 07:59:37 +02:00
Tarun Prabhu
c3201ddaea
[flang][NFC] Refactor to remove .inc file containing shared code (#109874)
Remove flang/include/flang/Tools/CLOptions.inc - which was included as
is in - several places. Move the code in it to header and source files
which are used used in the "standard" way. Some minor cleanup such as
removing trailing whitespace and excessive newlines and reordering
entries alphabetically for files that were modified along the way.
Update the documentation that referenced CLOptions.inc.
2024-09-25 14:04:38 -06:00
jeanPerier
3be8e3ad0c
[flang] translate pure and elemental attribute in FIR (#109954)
Follow-up from a previous patch that turned bind_c into an enum for
procedure attribute.

This patch carries the elemental and pure Fortran attribute into FIR so
that the optimizer can leverage that info in the future (I think debug
info may also need to know these aspects since DWARF has DW_AT_elemental
and DW_AT_pure nodes).

SIMPLE from F2023 will be translated once it is handled in the
front-end.

NON_RECURSIVE is only meaningful on func.func since we are not
guaranteed to know that aspect on the caller side (it is not part of
Fortran characteristics). There is a DW_AT_recursive DWARF node. I will
do it while dealing with func.func attributes.
2024-09-25 16:45:47 +02:00
harishch4
81dac7d613
[Flang][OpenMP] Add Semantic Checks for Atomic Capture Construct (#108516)
This PR adds semantic checks to ensure the atomic capture construct
conforms to one of the valid forms:
[capture-stmt, update-stmt], [capture-stmt, write-stmt] or [update-stmt,
capture-stmt].

Functions checkForSymbolMatch and checkForSingleVariableOnRHS are moved
from flang/lib/Lower/DirectivesCommon.h to flang/Semantics/tools.h for
reuse.

---------

Co-authored-by: Kiran Chandramohan <kiranchandramohan@gmail.com>
2024-09-25 09:29:44 +05:30
Valentin Clement (バレンタイン クレメン)
fa627d98e8
[flang][cuda] Add entry point for alloc/free and simple copy (#109867)
These will be used to translate simple cuf.alloc/cuf.free and
cuf.data_transfer on scalar and constant size arrays.
2024-09-24 20:00:11 -07:00
Valentin Clement (バレンタイン クレメン)
b15bd3fc65
[flang][cuda] Add global constructor for allocators registration (#109854)
This pass creates the constructor function to call the allocator
registration and adds it to the global_ctors.
2024-09-24 17:04:54 -07:00
Phoebe Wang
62f737f740
[Driver][X86] Add flang visibility for -m[no-]evex512 (#109598)
The `-m[no-]evex512` are nontrivial options which are used to control
vector size of other AVX512 features. Hence we expose both to flang for
Fortran users.
2024-09-23 11:21:48 +08:00
Valentin Clement (バレンタイン クレメン)
f760db1249
[flang][cuda][NFC] Expose conversion patterns from CUF to FIR calls (#109465)
Expose conversion patterns so they can be reused outside of this pass.
2024-09-20 22:28:10 -07:00
Valentin Clement (バレンタイン クレメン)
2e89e6b59a
[flang][cuda] Flag globals used in device function (#109460) 2024-09-20 18:03:25 -07:00
Peter Klausler
6959ec91d7
[flang] Extension intrinsics INT8 and INT2 (#109433)
These are legacy conversion intrinsic functions supported by nearly all
Fortran compilers (esp. INT8).
They are equivalent to INT(..., KIND=8 or 2), respectively.
2024-09-20 13:53:50 -07:00
Peter Klausler
8be575e498
[flang] Fix edge case regression (#109350)
A recent fix to the emission of derived type names to module files
exposed a regression in the case of a derived type that (1) has the same
name as a generic procedure interface and (2) has undergone renaming
through USE association before (3) being used in a declaration
significant to a module procedure interface. Fix.
2024-09-20 13:53:33 -07:00
Peter Klausler
e8335aef06
[flang] Avoid crash in name resolution on erroneous type extension (#109312)
Don't crash when a bad Fortran program tries to extend a derived type
with previous legitimate forward references but no prior definition.

Fixes https://github.com/llvm/llvm-project/issues/109268.
2024-09-20 13:53:12 -07:00
Peter Klausler
751389218e
[flang] Make IEEE_INT and IEEE_REAL into builtin intrinsic functions (#109191)
For proper error detection of bad KIND= arguments, make IEEE_INT and
IEEE_REAL actual intrinsic functions. Lowering will have to check for
the new __builtin_ names.
2024-09-20 13:52:02 -07:00
David Spickett
737c414e1d Revert "[clang][flang][mlir] Support -frecord-command-line option (#102975)"
This reverts commit b3533a156da92262eb19429d8c12f53e87f5ccec.

It caused test failures in shared library builds:
https://lab.llvm.org/buildbot/#/builders/80/builds/3854
2024-09-20 11:30:50 +00:00
Tarun Prabhu
b3533a156d
[clang][flang][mlir] Support -frecord-command-line option (#102975)
Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object
file. This behavior is also supported in clang. Some refactoring of the
code in flang to handle these command line options was carried out. The
corresponding -grecord-command-line option which saves the command line
in the debug information has not yet been enabled for flang.
2024-09-19 18:28:50 -06:00
Slava Zakharin
d5b7050d0a [flang] Fixed aarch64 buildbots after #109339. 2024-09-19 17:08:54 -07:00
Slava Zakharin
fc51c7f0cc
[flang][runtime] Disable LDBL_MANT_DIG == 113 for the offload builds. (#109339)
When compiling on aarch64 some `LDBL_MANT_DIG == 113` entries
end up trying to use `complex<long double>` for which there are
no certain specializations in `libcudacxx`. This change-set
includes a clean-up for `LDBL_MANT_DIG == 113` usage, which is replaced
with `HAS_LDBL128` that is set in `float128.h`.
2024-09-19 15:45:45 -07:00
Valentin Clement (バレンタイン クレメン)
434c9c50f9
[flang][cuf][NFC] Clean up unused header and library (#109326)
These were part of a previous attempt and are not needed anymore.
2024-09-19 12:56:26 -07:00
jeanPerier
94c024aded
[flang][lowering] delay stack save/restor emission in elemental calls (#109142)
stack save/restore emitted for character elemental function result
allocation inside hlfir.elemental in lowering created memory bugs
because result memory is actually still used after the stack restore
when lowering the elemental into a loop where the result element is
copied into the array result storage.

Instead of adding special handling for stack save/restore in lowering,
just avoid emitting those since the stack reclaim pass is able to emit
them in the generated loop. Not having those stack save/restore will
also help optimizations that want to elide the temporary allocation for
the element result when that is possible.
2024-09-19 13:52:58 +02:00
Valentin Clement (バレンタイン クレメン)
4194e8dea5
[flang][cuda][NFC] Fix grammar in CanCUDASymbolHasSave function name (#109234) 2024-09-18 22:14:30 -07:00
Valentin Clement (バレンタイン クレメン)
5e1a54b298
[flang][cuda][NFC] Add more descriptor inquiry tests for data transfer (#108094)
Make sure there is no data transfer generated when a device variable is
used in these intrinsic functions.
2024-09-18 21:45:32 -07:00
Valentin Clement
156035ed4d
[flang][cuda] Convert module allocation/deallocation to runtime calls
Convert `cuf.allocate` and `cuf.deallocate` to the runtime entry points added
in #109213

Was reviewed in https://github.com/llvm/llvm-project/pull/109214 but the
parent branch was closed for some reason.
2024-09-18 20:49:08 -07:00
Valentin Clement (バレンタイン クレメン)
cdf447baa5
[flang][cuda] Add function to allocate and deallocate device module variable (#109213)
This patch adds new runtime entry points that perform the simple
allocation/deallocation of module allocatable variable with cuda
attributes.
When the allocation is initiated on the host, the descriptor on the
device is synchronized. Both descriptors point to the same data on the
device.

This is the first PR of a stack.
2024-09-18 20:22:06 -07:00
Slava Zakharin
104f3c1806
Reland "[flang][runtime] Use cuda::std::complex in F18 runtime CUDA build. (#109078)" (#109207)
`std::complex` operators do not work for the CUDA device compilation
of F18 runtime. This change makes use of `cuda::std::complex` from
`libcudacxx`.
`cuda::std::complex` does not have specializations for `long double`,
so the change is accompanied with a clean-up for `long double` usage.

Additional change on top of #109078 is to use `cuda::std::complex`
only for the device compilation, otherwise the host compilation
fails because `libcudacxx` may not support `long double` specialization
at all (depending on the compiler).
2024-09-18 17:41:33 -07:00
Peter Klausler
1e19e1e1a4
[flang] Catch untyped entities in interfaces with IMPLICIT NONE (#109018)
The order of operations in name resolution wasn't converting named
entities to objects by the time that they were subjected to the implicit
typing rules in the case of interface blocks. This led to entities
remaining untyped without error, leading to a crash in module file
generation.

Fixes https://github.com/llvm/llvm-project/issues/108975.
2024-09-18 12:20:39 -07:00
Peter Klausler
5f11d38d01
[flang] Fix code that deletes unit from bad OPEN (#108994)
When an OPEN statement fails, a unit that was created for the OPEN needs
to be removed from the unit map. The code that tried to do this was
incorrect -- it needs to re-acquire the unit via LookUpForClose as a
CLOSE statement does. (The failure to do this completely was leaving a
zombie unit active that could break a later OPEN on the same unit
number.)
2024-09-18 12:19:18 -07:00
Peter Klausler
b0bdc7fcc9
[flang] Fix subtle type naming bug in module file output (#108892)
A derived type specification in semantics holds both its source name
(for location purposes) and its ultimate derived type symbol. But for
correct module file generation of a structure constructor using that
derived type spec, the original symbol may be needed so that USE
association can be exposed.

Save both the original symbol and its ultimate symbol in the
DerivedTypeSpec, and collect the right one when traversing expressions
(specifically for handling initialization in module files).

Fixes https://github.com/llvm/llvm-project/issues/108827.
2024-09-18 12:18:50 -07:00
Youngsuk Kim
84d7f294c4 [flang] Tidy uses of raw_string_ostream (NFC)
As specified in the docs,
1) raw_string_ostream is always unbuffered and
2) the underlying buffer may be used directly

( 65b13610a5226b84889b923bae884ba395ad084d for further reference )

Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2024-09-18 13:26:29 -05:00
Slava Zakharin
36192fdfb9
Revert "[flang][runtime] Use cuda::std::complex in F18 runtime CUDA build." (#109173)
Reverts llvm/llvm-project#109078
2024-09-18 11:22:31 -07:00
Slava Zakharin
be187a6812
[flang][runtime] Use cuda::std::complex in F18 runtime CUDA build. (#109078)
`std::complex` operators do not work for the CUDA device compilation
of F18 runtime. This change makes use of `cuda::std::complex` from
`libcudacxx`.
`cuda::std::complex` does not have specializations for `long double`,
so the change is accompanied with a clean-up for `long double` usage.
2024-09-18 10:59:05 -07:00
Vakhurin Sergei
eda72fac54
Fix OOM in FormatDiagnostic (2nd attempt) (#108866)
Resolves: #70930 (and probably latest comments from clangd/clangd#251)
by fixing racing for the shared DiagStorage value which caused messing with args inside the storage and then formatting the following message with getArgSInt(1) == 2:

def err_module_odr_violation_function : Error<
  "%q0 has different definitions in different modules; "
  "%select{definition in module '%2'|defined here}1 "
  "first difference is "

which causes HandleSelectModifier to go beyond the ArgumentLen so the recursive call to FormatDiagnostic was made with DiagStr > DiagEnd that leads to infinite while (DiagStr != DiagEnd).

The Main Idea:
Reuse the existing DiagStorageAllocator logic to make all DiagnosticBuilders having independent states.
Also, encapsulating the rest of state (e.g. ID and Loc) into DiagnosticBuilder.

The last attempt failed -
https://github.com/llvm/llvm-project/pull/108187#issuecomment-2353122096
so was reverted - #108838
2024-09-18 11:46:25 -04:00
Abid Qadeer
76347ee958
[flang][debug] Improve handling of dummy character arguments. (#108283)
As described in #107998, we were not handling the case well when length
of the character is not part of the type. This PR handles one of the
case when the length can be calculated by looking at the result of
corresponding `fir.unboxchar`.

The DIStringTypeAttr have a `stringLength` field that can be a variable.
We create an artificial variable that will hold the length and used as
value of `stringLength` field. The variable is then attached with
a `DbgValueOp`.

Fixes #107998.
2024-09-18 13:52:23 +01:00
Tom Eccles
41d5fed09e
[flang][Semantics] set scope even for module subroutines outside modules (#109009)
The missing scope information led to a crash in OpenMP semantic checks
run before printing the error that was already discovered in the code.

The following block has to be skipped for this invalid code so that we
don't emit a second spurious error.

Fixes #82913
2024-09-18 10:40:41 +01:00
Tarun Prabhu
1c0958bd95
[flang][Driver] Support -nostdlib and -nodefaultlibs (#108868)
This partially addresses some requests in #89888
2024-09-17 13:59:14 -06:00
Valentin Clement (バレンタイン クレメン)
0bbebf6f3a
[flang][cuda] Convert cuf.data_transfer with descriptors (#108890)
Convert cuf.data_transfer operations involving descriptors to the newly
introduced entry points (#108244).
2024-09-17 11:00:31 -07:00
Youngsuk Kim
d5dd7d230e [flang] Tidy uses of raw_string_ostream (NFC)
As specified in the docs,
1) raw_string_ostream is always unbuffered and
2) the underlying buffer may be used directly

( 65b13610a5226b84889b923bae884ba395ad084d for further reference )

Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2024-09-17 12:20:21 -05:00