1134 Commits

Author SHA1 Message Date
Krystian Stasiowski
dec94b04c0 [Clang][Sema] Make UnresolvedLookupExprs in class scope explicit specializations instantiation dependent (#100392)
A class member named by an expression in a member function that may instantiate to a static _or_ non-static member is represented by a `UnresolvedLookupExpr` in order to defer the implicit transformation to a class member access expression until instantiation. Since `ASTContext::getDecltypeType` only creates a `DecltypeType` that has a `DependentDecltypeType` as its canonical type when the operand is instantiation dependent, and since we do not transform types unless they are instantiation dependent, we need to mark the `UnresolvedLookupExpr` as instantiation dependent in order to correctly build a `DecltypeType` using the expression as its operand with a `DependentDecltypeType` canonical type. Fixes #99873.

(cherry picked from commit 55ea36002bd364518c20b3ce282640c920697bf7)
2024-08-15 09:34:14 +02:00
Krzysztof Parzyszek
e9709899db [clang][OpenMP] Avoid names that hide existing variables, NFC 2024-07-22 10:22:20 -05:00
Michael Kruse
5c93a94f5a
[Clang][OpenMP] Add interchange directive (#93022)
Add the interchange directive which will be introduced in the upcoming
OpenMP 6.0 specification. A preview has been published in [Technical
Report 12](https://www.openmp.org/wp-content/uploads/openmp-TR12.pdf).
2024-07-19 09:24:40 +02:00
Michael Kruse
80865c01e1
[Clang][OpenMP] Add reverse directive (#92916)
Add the reverse directive which will be introduced in the upcoming
OpenMP 6.0 specification. A preview has been published in [Technical
Report 12](https://www.openmp.org/wp-content/uploads/openmp-TR12.pdf).

---------

Co-authored-by: Alexey Bataev <a.bataev@outlook.com>
2024-07-18 10:35:32 +02:00
Krzysztof Parzyszek
97ebc97949 [clang[OpenMP] Revert accidentally included changes from previous commit 2024-07-15 09:10:11 -05:00
Krzysztof Parzyszek
a1dfe15632
[clang][OpenMP] Simplify check for taskloop in `ActOnOpenMPLoopInitia… (#98633)
…lization`

Replace the explicit list of compound directives ending with taskloop
with checking for the last leaf construct.
2024-07-15 08:53:14 -05:00
Krzysztof Parzyszek
861a8ed68b
[clang][OpenMP] Remove compound directives from checkNestingOfRegions (#98387)
Express the constraints via constituent directives.
2024-07-15 08:20:18 -05:00
Krzysztof Parzyszek
ba29e3a58d [clang][OpenMP] Add early exit to/unindent ActOnOpenMPLoopInitialization
NFC
2024-07-12 08:18:28 -05:00
Krzysztof Parzyszek
81cdf9472c
[clang][OpenMP] Fix region nesting check for scan directive (#98386)
The previous check was inconsistent. For example, it would allow
```
#pragma omp target
#pragma omp parallel for
  for (...) {
#pragma omp scan
  }
```
but not
```
#pragma omp target parallel for
  for (...) {
#pragma omp scan
  }
```

Make the check conform to the wording on the specification.
2024-07-11 08:07:58 -05:00
Krzysztof Parzyszek
2c42c2263d
[clang][OpenMP] Make getOpenMPCaptureRegionForClause more generic (#98180)
Rewrite `getOpenMPCaptureRegionForClause` with more generic code,
relying on directive composition instead of listing individual
directives.
2024-07-09 15:12:46 -05:00
Krzysztof Parzyszek
6461b921fd
[clang][OpenMP] Change ActOnOpenMPRegionStart to use captured regions (#97445)
Instead of checking specific directives, this function now gets the list
of captured regions, and processes them individually. This makes this
function directive-agnostic (except a few cases of leaf constructs).
2024-07-03 07:58:01 -05:00
Krzysztof Parzyszek
acaa0262a9
[clang][OpenMP] Use leaf constructs in mapLoopConstruct (#97446)
This removes mentions of specific combined directives.

Also, add a quote from the OpenMP spec to explain the code dealing with
the `bind` clause.
2024-07-03 07:57:31 -05:00
Krzysztof Parzyszek
deda50fd79
[clang][OpenMP] Implement isOpenMPCapturingDirective (#97090)
Check if the given directive can capture variables, and thus needs a
captured statement.

Simplify some code using this function.
2024-07-01 15:46:04 -05:00
Krzysztof Parzyszek
51797a7c55 [clang][OpenMP] Unindent checkNestingOfRegions, NFC
The entire body of the function is inside of an if-statement, followed
by a "return false". Invert the condition and return early, unindent
and clang-format the function.
2024-07-01 10:46:37 -05:00
Krzysztof Parzyszek
0ce801f91c
[clang][OpenMP] Implement isOpenMPExecutableDirective (#97089)
What is considered "executable" in clang differs slightly from the
OpenMP's "executable" category. In addition to the executable category,
subsidiary directives, and OMPD_error are considered executable.

Implement a function that performs that check.
2024-06-29 09:37:32 -05:00
Julian Brown
6ba764a54e
[OpenMP] [NFC] SemaOpenMP.cpp and StmtOpenMP.cpp spelling fixes (#96814)
This patch just fixes a few spelling mistakes in the above two files. (I
changed one British spelling to American -- analyse to analyze --
because the latter spelling is used elsewhere in file, and it's probably
best to be consistent.)
2024-06-28 12:36:20 -05:00
Krzysztof Parzyszek
08892cc07d
[clang][OpenMP] Simplify handling of if clause (#96936)
Get the allowed name modifiers from the list of constituent leaf
directives.
2024-06-28 07:46:18 -05:00
Krzysztof Parzyszek
4ed8796bfe [clang][OpenMP] clang-format SemaOpenMP.cpp, NFC
There are only a handful of changes, and now the entire file can be
kept clang-formatted.
2024-06-27 09:05:48 -05:00
Krzysztof Parzyszek
34fe6da6e4
[clang][OpenMP] Place some common code in functions (#96811)
There are chunks of code repeated in a number of functions. This patch
moves some of that code into individual functions.
2024-06-27 07:16:27 -05:00
Mike Rice
b097018fda
[clang][OpenMP] Fix teams nesting of region check (#94806)
The static verifier flagged dead code in the check since the loop will
only execute once and never reach the iterator increment.

The loop needs to iterate twice to correctly diagnose when a statement
is after the teams.

Since there are two iterations again, reset the iterator to the first
teams directive when the double teams case is seen so the diagnostic can
report both locations.
2024-06-24 13:31:39 -07:00
Mike Rice
65d300989b
[OpenMP][NFC] Fix argument order of SourceLocations for allocate clause (#94777)
Static verifier caught passing ColonLoc/LParenLoc in wrong order. Marked
as NFC since these don't seem to be used for anything currently that I
can think to test for.
2024-06-10 08:24:03 -07:00
Mike Rice
cb3ff9a393
[clang][OpenMP][NFC] Remove unnecessary nullptr check (#94680)
Static verifier reports unchecked use of pointer after explicitly
checking earlier in the function. It appears the pointer won't be a
nullptr, so remove the unneeded check for consistency.
2024-06-10 08:12:12 -07:00
Vlad Serebrennikov
6b755b0cf4
[clang] Split up SemaDeclAttr.cpp (#93966)
This patch moves language- and target-specific functions out of
`SemaDeclAttr.cpp`. As a consequence, `SemaAVR`, `SemaM68k`,
`SemaMSP430`, `SemaOpenCL`, `SemaSwift` were created (but they are not
the only languages and targets affected).

Notable things are that `Sema.h` actually grew a bit, because of
templated helpers that rely on `Sema` that I had to make available from
outside of `SemaDeclAttr.cpp`. I also had to left CUDA-related in
`SemaDeclAttr.cpp`, because it looks like HIP is building up on top of
CUDA attributes.

This is a follow-up to #93179 and continuation of efforts to split
`Sema` up. Additional context can be found in #84184 and #92682.
2024-06-05 09:46:37 +04:00
Vlad Serebrennikov
baabaa4ce9
[clang][NFC] Move PDiag into SemaBase (#93849)
This patch moves `PDiag` into `SemaBase`, making it readily available
everywhere across `Sema` without `SemaRef`, like the regular `Diag`.
2024-05-30 23:38:46 +04:00
Oleksandr T
7b77301c22
[clang] fix(93002): clang/lib/Sema/SemaOpenMP.cpp:7405: Possible & / && mixup ? (#93093)
Fixes #93002
2024-05-30 07:58:34 -05:00
Michael Kruse
9120562dfc
[Clang][OpenMP] Enable tile/unroll on iterator- and foreach-loops (#91459)
OpenMP loop transformation did not work on a for-loop using an iterator
or range-based for-loops. The first reason is that it combined the
iterator's type for generated loops with the type of `NumIterations` as
generated for any `OMPLoopBasedDirective` which is an integer. Fixed by
basing all generated loop variables on `NumIterations`.

Second, C++11 range-based for-loops include syntactic sugar that needs
to be executed before the loop. This additional code is now added to the
construct's Pre-Init lists.

Third, C++20 added an initializer statement to range-based for-loops
which is also added to the pre-init statement. PreInits used to be a
`DeclStmt` which made it difficult to add arbitrary statements from
`CXXRangeForStmt`'s syntactic sugar, especially the for-loops init
statement which does not need to be a declaration. Change it to be a
general `Stmt` that can be a `CompoundStmt` to hold arbitrary Stmts,
including DeclStmts. This also avoids the `PointerUnion` workaround used
by `checkTransformableLoopNest`.

End-to-end tests are added to verify the expected number and order of
loop execution and evaluations of expressions (such as iterator
dereference). The order and number of evaluations of expressions in
canonical loops is explicitly undefined by OpenMP but checked here for
clarification and for changes to be noticed.
2024-05-22 14:30:31 +02:00
SunilKuravinakop
ce67fcf15f
Avoid unevaluated implicit private (#92055)
For every variable used under `#pragma omp task` directive
(`DeclRefExpr`) an ImplicitPrivateVariable is created in the AST, if
`private` or `shared` clauses are not present. If the variable has the
property of `non_odr_use_unevaluated` e.g. for statements which use
`sizeof( i )` `i` will have `non_odr_use_unevaluated` . In such cases
CodeGen was asserting by avoiding emitting of LLVM IR for such
variables. To prevent this assertion this checkin avoids adding the
ImplicitPrivateVariable for variables with `non_odr_use_unevaluated`.

---------

Authored-by: Sunil Kuravinakop <kuravina@pe28vega.us.cray.com>
2024-05-16 12:25:53 -04:00
Michael Kruse
b0b6c16b47
[Clang][OpenMP][Tile] Allow non-constant tile sizes. (#91345)
Allow non-constants in the `sizes` clause such as
```
#pragma omp tile sizes(a)
for (int i = 0; i < n; ++i)
```
This is permitted since tile was introduced in [OpenMP
5.1](https://www.openmp.org/spec-html/5.1/openmpsu53.html#x78-860002.11.9).

It is possible to sneak-in negative numbers at runtime as in
```
int a = -1;
#pragma omp tile sizes(a)
```
Even though it is not well-formed, it should still result in every loop
iteration to be executed exactly once, an invariant of the tile
construct that we should ensure. `ParseOpenMPExprListClause` is
extracted-out to be reused by the `permutation` clause of the
`interchange` construct. Some care was put into ensuring correct behavior
in template contexts.
2024-05-13 16:10:58 +02:00
Michael Kruse
f0590581aa [Clang][OpenMP] Fix unused lambda capture warning. 2024-05-13 14:55:34 +02:00
Michael Kruse
e76b257483
[Clang][OpenMP][Tile] Ensure AST node uniqueness. (#91325)
One of the constraints of an AST is that every node object must appear
at most once, hence we define lamdas that create a new AST node at every
use.
2024-05-13 14:31:39 +02:00
Krystian Stasiowski
8009bbec59
Reapply "[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" (#90152)
Reapplies #84050, addressing a bug which cases a crash when an
expression with the type of the current instantiation is used as the
_postfix-expression_ in a class member access expression (arrow form).
2024-04-30 14:25:09 -04:00
Pranav Kant
0c6e1ca1c7 Revert "[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)"
This reverts commit a8fd0d029dca7d17eee72d0445223c2fe1ee7758.
2024-04-26 00:18:08 +00:00
Krystian Stasiowski
a8fd0d029d
[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)
Consider the following:
```cpp
template<typename T>
struct A
{
    auto f()
    {
        return this->x;
    }
};
```
Although `A` has no dependent base classes and the lookup context for
`x` is the current instantiation, we currently do not diagnose the
absence of a member `x` until `A<T>::f` is instantiated. This patch
moves the point of diagnosis for such expressions to occur at the point
of definition (i.e. prior to instantiation).
2024-04-25 14:50:53 -04:00
Erich Keane
39adc8f423
[NFC] Generalize ArraySections to work for OpenACC in the future (#89639)
OpenACC is going to need an array sections implementation that is a
simpler version/more restrictive version of the OpenMP version. 

This patch moves `OMPArraySectionExpr` to `Expr.h` and renames it `ArraySectionExpr`,
 then adds an enum to choose between the two.

This also fixes a couple of 'drive-by' issues that I discovered on the way,
but leaves the OpenACC Sema parts reasonably unimplemented (no semantic
analysis implementation), as that will be a followup patch.
2024-04-25 10:22:03 -07:00
Krystian Stasiowski
5c4b923c72
Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541, #88311)" (#88731)
Reapplies #87541 and #88311 (again) addressing the bug which caused
expressions naming overload sets to be incorrectly rebuilt, as well as
the bug which caused base class members to always be treated as overload
sets.

The primary change since #88311 is `UnresolvedLookupExpr::Create` is called directly in `BuildPossibleImplicitMemberExpr` with `KnownDependent` as `true` (which causes the expression type to be set to `ASTContext::DependentTy`). This ensures that any further semantic analysis involving the type of the potentially implicit class member access expression is deferred until instantiation.
2024-04-22 11:48:13 -04:00
Vlad Serebrennikov
458328ae23 [clang][NFC] Refactor Sema::RedeclarationKind
This patch converts the enum into scoped enum, and moves it into its own header for the time being. It's definition is needed in `Sema.h`, and is going to be needed in upcoming `SemaObjC.h`. `Lookup.h` can't hold it, because it includes `Sema.h`.
2024-04-17 18:02:48 +03:00
Vlad Serebrennikov
f69ded0d99
[clang] Introduce SemaOpenMP (#88642)
This patch moves OpenMP-related entities out of `Sema` to a newly
created `SemaOpenMP` class. This is a part of the effort to split `Sema`
up, and follows the recent example of CUDA, OpenACC, SYCL, HLSL.
Additional context can be found in
https://github.com/llvm/llvm-project/pull/82217,
https://github.com/llvm/llvm-project/pull/84184,
https://github.com/llvm/llvm-project/pull/87634.
2024-04-16 16:36:53 +04:00
Bill Wendling
fca51911d4
[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)
The IdentifierInfo isn't typically modified. Use 'const' wherever
possible.
2024-04-11 00:33:40 +00:00
David Pagan
a12836647e
[OpenMP][CodeGen] Improved codegen for combined loop directives (#87278)
IR for 'target teams loop' is now dependent on suitability of associated
loop-nest.

If a loop-nest:

- does not contain a function call, or
- the -fopenmp-assume-no-nested-parallelism has been specified,
- or the call is to an OpenMP API AND
- does not contain nested loop bind(parallel) directives

then it can be emitted as 'target teams distribute parallel for', which
is the current default. Otherwise, it is emitted as 'target teams
distribute'.

Added debug output indicating how 'target teams loop' was emitted. Flag
is -mllvm -debug-only=target-teams-loop-codegen

Added LIT tests explicitly verifying 'target teams loop' emitted as a
parallel loop and a distribute loop.

Updated other 'loop' related tests as needed to reflect change in IR.
- These updates account for most of the changed files and
additions/deletions.
2024-04-10 13:09:17 -07:00
Chris B
28ddbd4a86
[NFC] Refactor ConstantArrayType size storage (#85716)
In PR #79382, I need to add a new type that derives from
ConstantArrayType. This means that ConstantArrayType can no longer use
`llvm::TrailingObjects` to store the trailing optional Expr*.

This change refactors ConstantArrayType to store a 60-bit integer and
4-bits for the integer size in bytes. This replaces the APInt field
previously in the type but preserves enough information to recreate it
where needed.

To reduce the number of places where the APInt is re-constructed I've
also added some helper methods to the ConstantArrayType to allow some
common use cases that operate on either the stored small integer or the
APInt as appropriate.

Resolves #85124.
2024-03-26 14:15:56 -05:00
Krzysztof Parzyszek
5cf8cf3ac8
[clang][OpenMP] Fix directive in ActOnOpenMPTargetParallelForSimdDire… (#85217)
…ctive

The function `ActOnOpenMPTargetParallelForSimdDirective` gets the number
of capture levels for OMPD_target_parallel_for, whereas the intended
directive is OMPD_target_parallel_for_simd.
2024-03-14 12:28:39 -05:00
Sirraide
2b5f68a5f6
[Clang][C++23] Implement P1774R8: Portable assumptions (#81014)
This implements the C++23 `[[assume]]` attribute.

Assumption information is lowered to a call to `@llvm.assume`, unless the expression has side-effects, in which case it is discarded and a warning is issued to tell the user that the assumption doesn’t do anything. A failed assumption at compile time is an error (unless we are in `MSVCCompat` mode, in which case we don’t check assumptions at compile time).

Due to performance regressions in LLVM, assumptions can be disabled with the `-fno-assumptions` flag. With it, assumptions will still be parsed and checked, but no calls to `@llvm.assume` will be emitted and assumptions will not be checked at compile time.
2024-03-09 12:07:16 +01:00
Sandeep Kosuri
6d3bb85471
[OpenMP] Parse and Sema support for declare target in local scope (#83223)
- adds Parse and Sema support for the `declare target` directive inside
a function scope.
2024-03-06 19:46:23 +05:30
Animesh Kumar
3246c44789
[OpenMP][Clang] Enable inscan modifier for generic datatypes (#82220)
This patch fixes the #67002 ([OpenMP][Clang] Scan Directive not
supported for Generic types). It disables the Sema checks/analysis that
are run on the helper arrays which go into the implementation of the
`omp scan` directive until the template instantiation happens.
Grateful to @alexey-bataev for suggesting these changes.
2024-02-29 11:54:50 +05:30
Shourya Goel
b89eb9790a
[Clang][OpenMP] Fix `!isNull() && "Cannot retrieve a NULL type pointer"' fail. (#81015)
Fixes : #69085 , #69200

**PR SUMMARY**: "Added Null check for negative sized array and a test
for the same"
2024-02-07 13:38:22 -06:00
SunilKuravinakop
a74e9ce5dc
[OpenMP] atomic compare weak : Parser & AST support (#79475)
This is a support for " #pragma omp atomic compare weak". It has Parser
& AST support for now.

---------

Authored-by: Sunil Kuravinakop <kuravina@pe28vega.us.cray.com>
2024-01-31 06:32:06 -05:00
Jonas Paulsson
34dd8ec8ae
[clang, SystemZ] Support -munaligned-symbols (#73511)
When this option is passed to clang, external (and/or weak) symbols
are not assumed to have the minimum ABI alignment normally required.
Symbols defined locally that are not weak are however still given the
minimum alignment.

This is implemented by passing a new parameter to getMinGlobalAlign()
named HasNonWeakDef that is used to return the right alignment value.

This is needed when external symbols created from a linker script may
not get the ABI minimum alignment and must therefore be treated as
unaligned by the compiler.
2024-01-27 18:29:37 +01:00
Krystian Stasiowski
68ae1e49d2
[Clang][Sema][NFC] Remove unused Scope* parameter from Sema::GetTypeForDeclarator and Sema::ActOnTypeName (#78325)
Split from #78274
2024-01-17 05:47:57 -05:00
SunilKuravinakop
782c525007
[OpenMP] Patch for Support to loop bind clause : Checking Parent Region (#76938)
Changes uploaded to the phabricator on Dec 16th are lost because the
phabricator is down. Hence re-uploading it to the github.com.

  Changes to be committed:
 	modified:   clang/include/clang/Sema/Sema.h
 	modified:   clang/lib/Sema/SemaOpenMP.cpp
 	modified:   clang/test/OpenMP/generic_loop_ast_print.cpp
 	modified:   clang/test/OpenMP/loop_bind_messages.cpp
 	modified:   clang/test/PCH/pragma-loop.cpp

---------

Co-authored-by: Sunil Kuravinakop
2024-01-09 11:14:56 +05:30
SunilKuravinakop
49ee8b53ef
[OpenMP] atomic compare fail : Codegen support (#75709)
This is a continuation of https://reviews.llvm.org/D123235 ([OpenMP]
atomic compare fail : Parser & AST support). In this branch Support for
codegen support for atomic compare fail is being added.

---------

Co-authored-by: Sunil Kuravinakop
2024-01-02 22:46:02 +05:30