1163 Commits

Author SHA1 Message Date
刘雨培
128b3b61fe
[Clang] Defer the instantiation of explicit-specifier until constraint checking completes (#70548)
Modifications:

- Skip the instantiation of the explicit-specifier during Decl
substitution if we are deducing template arguments and the
explicit-specifier is value dependent.

- Instantiate the explicit-specifier after the constraint checking
completes.

- Make `instantiateExplicitSpecifier` a member function in order to
instantiate the explicit-specifier in different stages.


This PR doesn’t defer the instantiation of the explicit specifier for
deduction guides, because I’m not familiar with deduction guides yet.
I’ll dig into it after this PR.

According to my local test, GCC 13 tuple works with this PR.

Fixes #59827.

---------

Co-authored-by: Erich Keane <ekeane@nvidia.com>
2023-11-01 06:45:48 -07:00
Vlad Serebrennikov
50dec541f3 [clang][NFC] Refactor OMPDeclareReductionDecl::InitKind
This patch moves `OMPDeclareReductionDecl::InitKind` to DeclBase.h, so that it's complete at the point where corresponding bit-field is declared. This patch also converts it to scoped enum named `OMPDeclareReductionInitKind`
2023-11-01 12:40:13 +03:00
Erich Keane
98191d7c16
[CONCEPTS]Corrected comparison of constraints with out of line CTD (#69244)
Out of line class template declaration specializations aren't created at
the time they have their template arguments checked, so we previously
weren't doing any amount of work to substitute the constraints before
comparison. This resulted in the out of line definition's difference in
'depth' causing the constraints to compare differently.

This patch corrects that. Additionally, it handles ClassTemplateDecl
when collecting template arguments.

Fixes: #61763
2023-10-18 09:10:30 -07:00
Krystian Stasiowski
3a3b84b180
[clang] remove ClassScopeFunctionSpecializationDecl (#66636)
This removes the `ClassScopeFunctionSpecializationDecl` `Decl` node, and
instead uses `DependentFunctionTemplateSpecializationInfo` to handle
such declarations. `DependentFunctionTemplateSpecializationInfo` is also
changed to store a `const ASTTemplateArgumentListInfo*` to be more in
line with `FunctionTemplateSpecializationInfo`.

This also changes `FunctionDecl::isFunctionTemplateSpecialization` to
return `true` for dependent specializations, and
`FunctionDecl::getTemplateSpecializationKind`/`FunctionDecl::getTemplateSpecializationKindForInstantiation`
to return `TSK_ExplicitSpecialization` for non-friend dependent
specializations (the same behavior as dependent class scope
`ClassTemplateSepcializationDecl` & `VarTemplateSepcializationDecl`).
2023-10-07 10:55:31 +04:00
Botond István Hprváth
66c19167f1
[clang] Choose non-templated ctor as deduction guide unambiguously (#66487)
If there are two guides, one of them generated from a non-templated
constructor
and the other from a templated constructor, then the standard gives
priority to
the first. Clang detected ambiguity before, now the correct guide is
chosen.
The correct behavior is described in this paper:
http://wg21.link/P0620R0

Example for the bug: http://godbolt.org/z/ee3e9qG78

As an unrelated minor change, fix the issue
https://github.com/llvm/llvm-project/issues/64020,
which could've led to incorrect behavior if further development inserted
code after a call to
`isAddressSpaceSubsetOf()`, which specified the two parameters in the
wrong order.

---------

Co-authored-by: hobois <horvath.botond.istvan@gmial.com>
2023-10-04 09:11:43 -07:00
Sheng
548d67a039
[clang][Sema] Fix a bug when instantiating a lambda with requires clause (#65193)
Instantiating a lambda at a scope different from where it is defined
will paralyze clang if the trailing require clause refers to local
variables. This patch fixes this by re-adding the local variables to
`LocalInstantiationScope`.

Fixes #64462
2023-10-04 10:19:35 +08:00
Corentin Jabot
af4751738d [C++] Implement "Deducing this" (P0847R7)
This patch implements P0847R7 (partially),
CWG2561 and CWG2653.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D140828
2023-10-02 14:33:02 +02:00
Jakub Chlanda
3f8d4a8ef2
Reland [NVPTX] Add support for maxclusterrank in launch_bounds (#66496) (#67667)
This reverts commit 0afbcb20fd908f8bf9073697423da097be7db592.
2023-09-29 08:39:31 +02:00
Sam McCall
880fa7faa9 Revert "[clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated"
This reverts commit 491b2810fb7fe5f080fa9c4f5945ed0a6909dc92.

This change broke valid code and generated incorrect diagnostics, see
https://reviews.llvm.org/D155064
2023-09-27 18:58:01 +02:00
Sam McCall
0afbcb20fd Revert "[NVPTX] Add support for maxclusterrank in launch_bounds (#66496)"
This reverts commit dfab31b41b4988b6dc8129840eba68f0c36c0f13.

SemaDeclAttr.cpp cannot depend on Basic's private headers
(lib/Basic/Targets/NVPTX.h)
2023-09-27 10:59:04 +02:00
Jakub Chlanda
dfab31b41b
[NVPTX] Add support for maxclusterrank in launch_bounds (#66496)
Since SM_90 CUDA supports specifying additional argument to the
launch_bounds attribute: maxBlocksPerCluster, to express the maximum
number of CTAs that can be part of the cluster. See:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#cluster-dimension-directives-maxclusterrank
and

https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#launch-bounds
for details.
2023-09-27 08:51:26 +02:00
Takuya Shimizu
491b2810fb [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated
This patch makes clang diagnose extensive cases of consteval if and is_constant_evaluated usage that are tautologically true or false.
This introduces a new IsRuntimeEvaluated boolean flag to Sema::ExpressionEvaluationContextRecord that means the immediate appearance of if consteval or is_constant_evaluated are tautologically false(e.g. inside if !consteval {} block or non-constexpr-qualified function definition body)
This patch also pushes new expression evaluation context when parsing the condition of if constexpr and initializer of constexpr variables so that Sema can be aware that the use of consteval if and is_consteval are tautologically true in if constexpr condition and constexpr variable initializers.
BEFORE this patch, the warning for is_constant_evaluated was emitted from constant evaluator. This patch moves the warning logic to Sema in order to diagnose tautological use of is_constant_evaluated in the same way as consteval if.

This patch separates initializer evaluation context from InitializerScopeRAII.
This fixes a bug that was happening when user takes address of function address in initializers of non-local variables.

Fixes https://github.com/llvm/llvm-project/issues/43760
Fixes https://github.com/llvm/llvm-project/issues/51567

Reviewed By: cor3ntin, ldionne
Differential Revision: https://reviews.llvm.org/D155064
2023-09-27 09:26:06 +09:00
Tom Honermann
256a0b298c [clang] Correct source locations for instantiations of function templates.
This change corrects some cases where the source location for an
instantiated specialization of a function template or a member function
of a class template was assigned the location of a non-defining
declaration rather than the location of the definition the
specialization was instantiated from.

Fixes https://github.com/llvm/llvm-project/issues/26057

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D64087
2023-09-18 12:51:45 -07:00
Corentin Jabot
3ed9e9e3ac [Clang] Add captures to the instantiation scope of lambda call operators
Like concepts checking, a trailing return type of a lambda
in a dependent context may refer to captures in which case
they may need to be rebuilt, so the map of local decl
should include captures.

This patch reveal a pre-existing issue.
`this` is always recomputed by TreeTransform.

`*this` (like all captures) only become `const`
after the parameter list.

However, if try to recompute the value of `this` (in a parameter)
during template instantiation while determining the type of the call operator,
we will determine  it to be const (unless the lambda is mutable).

There is no good way to know at that point that we are in a parameter
or not, the easiest/best solution is to transform the type of this.

Note that doing so break a handful of HLSL tests.
So this is a prototype at this point.

Fixes #65067
Fixes #63675

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D159126
2023-09-08 17:50:27 +02:00
Corentin Jabot
98062d8fef Revert "[Clang] Add captures to the instantiation scope of lambda call operators"
The change causes some libcxx regressions

This reverts commit eaf725bc9371a6699902d67d97662caaa3332799.
2023-09-07 09:50:25 +02:00
Corentin Jabot
eaf725bc93 [Clang] Add captures to the instantiation scope of lambda call operators
Like concepts checking, a trailing return type of a lambda
in a dependent context may refer to captures in which case
they may need to be rebuilt, so the map of local decl
should include captures.

This patch reveal a pre-existing issue.
`this` is always recomputed by TreeTransform.

`*this` (like all captures) only become `const`
after the parameter list.

However, if try to recompute the value of `this` (in a parameter)
during template instantiation while determining the type of the call operator,
we will determine  it to be const (unless the lambda is mutable).

There is no good way to know at that point that we are in a parameter
or not, the easiest/best solution is to transform the type of this.

Note that doing so break a handful of HLSL tests.
So this is a prototype at this point.

Fixes #65067
Fixes #63675

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D159126
2023-09-06 21:59:45 +02:00
Nick Desaulniers
f0f395e00e Revert "Reland "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions""
This reverts commit 92023b15099012a657da07ebf49dd7d94a260f84.

Further issues were uncovered:
- False positive -Wunused-variable on function-static variables with the
  used attribute. https://github.com/ClangBuiltLinux/linux/issues/1926
  A test case needs to be added for this.
- Request for a new flag for these.
  https://reviews.llvm.org/D152495#4628877
  https://reviews.llvm.org/D152495#4628887
2023-08-31 11:58:41 -07:00
Takuya Shimizu
92023b1509 Reland "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions"
This patch marks the declarations with initializations in condition expressions such as
if (int var = init) as unused and unreferenced so that -Wunused can warn on them.

Fixes https://github.com/llvm/llvm-project/issues/61681

Reviewed By: cor3ntin
Differential Revision: https://reviews.llvm.org/D152495
2023-08-30 10:05:10 +09:00
Elizabeth Andrews
847186eb94 [NFC][Clang] Fix static analyzer concern
Fix a few static analyzer concerns about dereferencing
null value.

Differential Revision: https://reviews.llvm.org/D158671
2023-08-25 13:03:06 -07:00
Takuya Shimizu
5aded521ea Revert "Reland "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions""
This causes a lot of warning in sanitizer build:
https://lab.llvm.org/buildbot/#/builders/258/builds/5424
https://lab.llvm.org/buildbot/#/builders/36/builds/36560

This reverts commit 8e329caa944c377c51ef567d5aa67cfac9ffd0fa.
2023-08-15 19:54:51 +09:00
Takuya Shimizu
8e329caa94 Reland "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions"
This patch marks the declarations with initializations in condition expressions such as
if (int var = init) as unreferenced so that -Wunused can warn on them.

Fixes https://github.com/llvm/llvm-project/issues/61681

Reviewed By: cor3ntin
Differential Revision: https://reviews.llvm.org/D152495
2023-08-15 17:24:13 +09:00
Takuya Shimizu
18b6f6e0c7 Revert "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions"
Broke sanitizer buildbot:
https://lab.llvm.org/buildbot/#/builders/240/builds/12947
https://lab.llvm.org/buildbot/#/builders/19/builds/18369

Reverting while I figure out the cause.

This reverts commit bd0ed0abc31fa5a49e87eeca7aa872e7f6e4d1e7.
2023-08-06 17:02:01 +09:00
Takuya Shimizu
bd0ed0abc3 [Clang][SemaCXX] Add unused warning for variables declared in condition expressions
This patch marks the declarations with initializations in condition expressions such as
if (int var = init) as unreferenced so that -Wunused can warn on them.

Fixes https://github.com/llvm/llvm-project/issues/61681

Reviewed By: cor3ntin
Differential Revision: https://reviews.llvm.org/D152495
2023-08-06 16:24:09 +09:00
Corentin Jabot
47ccfd7a89 [Clang] Implement P2741R3 - user-generated static_assert messages
Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D154290
2023-07-20 08:33:19 +02:00
Serge Pavlov
fde5924dcc [clang] Reset FP options before template instantiation
AST nodes that may depend on FP options keep them as a difference
relative to the options outside the AST node. At the moment of
instantiation the FP options may be different from the default values,
defined by command-line option. In such case FP attributes would have
unexpected values. For example, the code:

    template <class C> void func_01(int last, C) {
      func_01(last, int());
    }
    void func_02() { func_01(0, 1); }
    #pragma STDC FENV_ACCESS ON

caused compiler crash, because template instantiation takes place at the
end of translation unit, where pragma STDC FENV_ACCESS is in effect. As
a result, code in the template instantiation would use constrained
intrinsics while the function does not have StrictFP attribute.

To solve this problem, FP attributes in Sema must be set to default
values, defined by command line options.

This change resolves https://github.com/llvm/llvm-project/issues/63542.

Differential Revision: https://reviews.llvm.org/D154359
2023-07-13 11:49:00 +07:00
Yuanfang Chen
632dd6a4ca [Clang] Implements CTAD for aggregates P1816R0 and P2082R1
Differential Revision: https://reviews.llvm.org/D139837
2023-06-29 14:22:24 -07:00
yronglin
f75b73549d [Clang][Attribute] Improve the AST/diagnoses fidelity of alignas and _Alignas
- Fix diagnoses when the argument to `alignas` or `_Alignas` is an incomplete type.

Before:
```
./alignas.cpp:1:15: error: invalid application of 'alignof' to an incomplete type 'void'
class alignas(void) Foo {};
             ~^~~~~
1 error generated.
```
Now:
```
./alignas.cpp:1:15: error: invalid application of 'alignas' to an incomplete type 'void'
class alignas(void) Foo {};
             ~^~~~~
1 error generated.
```

- Improve the AST fidelity of `alignas` and `_Alignas` attribute.

Before:
```
AlignedAttr 0x13f07f278 <col:7> alignas
    `-ConstantExpr 0x13f07f258 <col:15, col:21> 'unsigned long'
      |-value: Int 8
      `-UnaryExprOrTypeTraitExpr 0x13f07f118 <col:15, col:21> 'unsigned long' alignof 'void *'
```

Now:
```
AlignedAttr 0x14288c608 <col:7> alignas 'void *'
```

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D150528
2023-05-26 07:41:26 +08:00
Roy Jacobson
0f59bee3d5 [Sema] Mark ineligibility of special member functions correctly
I checked if the member function declaration was a copy constructor, but it's not sufficient; We need to check
the arguments against the instantiated class.

Fixed https://github.com/llvm/llvm-project/issues/62555

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D149961
2023-05-19 17:29:12 +03:00
Alexander Shaposhnikov
6db007a065 [Clang][Sema] Fix comparison of constraint expressions
This diff switches the approach to comparison of constraint expressions
to the new one based on template args substitution.
It continues the effort to fix our handling of out-of-line definitions
of constrained templates.
This is a recommit of 3a54022934.

Differential revision: https://reviews.llvm.org/D146178
2023-05-09 18:14:39 +00:00
Alexander Shaposhnikov
3b9ed6e532 Revert "[Clang][Sema] Fix comparison of constraint expressions"
This reverts commit 3a540229341e3c8dc6d8ee61309eafaf943ea254.
A new regression is discovered and needs to be investigated.
2023-05-05 00:02:26 +00:00
David Stone
6d6880554c [clang][Sema][NFC] Move EnterExpressionEvaluationContext to its own file
Sema.h is huge. This makes a small reduction to it by moving
EnterExpressionEvaluationContext into a new header, since it is an
independent component.

Differential Revision: https://reviews.llvm.org/D149796
2023-05-04 13:06:53 -04:00
Alexander Shaposhnikov
3a54022934 [Clang][Sema] Fix comparison of constraint expressions
This diff switches the approach to comparison of constraint expressions
to the new one based on template args substitution.
It continues the effort to fix our handling of out-of-line definitions
of constrained templates.
This is a recommit of e3b1083e00.

Differential revision: https://reviews.llvm.org/D146178
2023-05-03 21:06:12 +00:00
Erich Keane
3e850a6eea Revert "[Clang][Sema] Fix comparison of constraint expressions"
This reverts commit e3b1083e00e62f5d157d15cb8c63a1c3dfdf12e2.

This was reverted because it breaks a number of libstdc++ examples, AND
required a workaround that causes hiding of legitimate bugs.
2023-05-02 08:09:35 -07:00
Alexander Shaposhnikov
e3b1083e00 [Clang][Sema] Fix comparison of constraint expressions
This diff switches the approach to comparison of constraint expressions
to the new one based on template args substitution.
It continues the effort to fix our handling of out-of-line definitions
of constrained templates.
This is a recommit of 60bee9ff5445.

Differential revision: https://reviews.llvm.org/D146178
2023-04-27 21:33:32 +00:00
Congcong Cai
921b45a855 [Sema]Select correct lexical context during template instantiate
This patch wants to fix inline friend decl like
```
template <class F1> int foo(F1 X);
template <int A1> struct A {
  template <class F1> friend int foo(F1 X) { return A1; }
};

template struct A<1>;
int a = foo(1.0);
```

Differential Revision: https://reviews.llvm.org/D149009
2023-04-27 00:29:13 +02:00
Alexander Shaposhnikov
13d44a8f56 Revert "[Clang][Sema] Fix comparison of constraint expressions"
This temporarily reverts commit
60bee9ff544541e83ffbd4be31923d0e8b644690.
The diff will be recommitted once the newly discovered
regressions are fixed.
2023-04-07 18:41:57 +00:00
Shafik Yaghmour
d89c6530fd [Clang] Fix filtering of inline namespaces for friend functions
PR D135370 implemented a performance improvement but it restricted the filtering
of declaration from inline namespace too much. In particular it did not filter
for the function template case.

This led to a regression and this PR removes that check.

This fixes: https://github.com/llvm/llvm-project/issues/61851

Differential Revision: https://reviews.llvm.org/D147762
2023-04-07 08:58:39 -07:00
Alexander Shaposhnikov
60bee9ff54 [Clang][Sema] Fix comparison of constraint expressions
This diff switches the approach to comparison of constraint expressions
to the new one based on template args substitution.
It continues the effort to fix our handling of out-of-line definitions
of constrained templates.

The associated GitHub issue: https://github.com/llvm/llvm-project/issues/61414

Test plan:
1/ ninja check-all
2/ bootstrapped Clang passes tests

Differential revision: https://reviews.llvm.org/D146178
2023-04-04 02:31:13 +00:00
Erich Keane
18fe663969 Correct deferred concepts with NTTP placeholder constraints
Seemingly we never tested this, but the constraint on a NTTP was being
swtiched to the 'instantiated' version, but constraints need to be
relative to the 'top level', so this was causing us to not be able to
check the constraint on final use.

This patch corrects the issue by making the constraint created with the
un-instantiated version in the case of dependent constraint attachment.

Fixes: #61777
2023-03-30 06:15:02 -07:00
Serge Pavlov
5cc91f977e [Clang] Copy strictfp attribute from pattern to instantiation
If a template function contained a pragma that made it strictfp, code
generation for such function crashed, because the instantiation did not
have strictfp attribute. As a solution this attribute is copied from the
template to instantiation.

Differential Revision: https://reviews.llvm.org/D143919
2023-02-27 11:19:20 +07:00
Doru Bercea
49d47c4d2f Add Parse/Sema for iterator for map clause. 2023-01-20 12:54:49 -06:00
Kazu Hirata
6ad0788c33 [clang] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to remove #include "llvm/ADT/Optional.h".

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 12:31:01 -08:00
Kazu Hirata
a1580d7b59 [clang] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 11:07:21 -08:00
serge-sans-paille
a3c248db87
Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ part
This is a follow-up to https://reviews.llvm.org/D140896, split into
several parts as it touches a lot of files.

Differential Revision: https://reviews.llvm.org/D141139
2023-01-09 12:15:24 +01:00
Chuanqi Xu
d0ce367a97 [C++20] [Modules] Fix a crash when instantiate hidden friends
Closes https://github.com/llvm/llvm-project/issues/54457.

This removes a FIXME we found previously. But we didn't remove the FIXME
that time due to the lack of the corresponding test. And now we found
the corresponding test so we can remove it.
2023-01-03 13:37:57 +08:00
Fangrui Song
53e5cd4d3e llvm::Optional::value => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.

This makes `ninja clang` work in the absence of llvm::Optional::value.
2022-12-17 06:37:59 +00:00
Kazu Hirata
8595f2e54d [Sema] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 11:13:39 -08:00
Rageking8
94738a5ac3 Fix duplicate word typos; NFC
This revision fixes typos where there are 2 consecutive words which are
duplicated. There should be no code changes in this revision (only
changes to comments and docs). Do let me know if there are any
undesirable changes in this revision. Thanks.
2022-11-08 07:21:23 -05:00
Yuanfang Chen
5d086cce8b [Clang] perform "maximum TLS alignment" check for template instantiation
follow up d30e2eefc3

Reviewed By: mizvekov

Differential Revision: https://reviews.llvm.org/D136744
2022-10-30 22:39:47 -07:00
Liming Liu
ae48d1c76a [P0857R0 Part-B] Allows `require' clauses appearing in
template-template parameters. Although it effects whether a template can be
used as an argument for another template, the constraint seems not to
be checked, nor other major implementations (GCC, MSVC, et al.) check it.

Additionally, Part-A of the document seems to have been implemented.
So mark P0857R0 as completed.

Differential Revision: https://reviews.llvm.org/D134128
2022-10-27 06:41:43 -07:00