18 Commits

Author SHA1 Message Date
Kazu Hirata
63d9ef5e37
[AST] Migrate away from PointerUnion::{is,get} (NFC) (#117469)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2024-11-24 07:28:20 -08:00
Kazu Hirata
dec6324cb0
[AST] Remove unused includes (NFC) (#116549)
Identified with misc-include-cleaner.
2024-11-17 09:36:48 -08:00
Youngsuk Kim
0998e3c4e6
[clang] Add method 'backupStr' to ASTContext (#99417)
Method 'backupStr' extracts common code of dynamically allocating memory
with ASTContext to hold a copy of a string's contents.
2024-07-23 04:13:04 -04:00
Younan Zhang
fb19649535
[Clang][NFCI] Remove records of unsatisfied atomic expressions in ConstraintSatisfaction (#98654)
This expression doesn't appear to be ever used, so let's remove it from
the data structure.

Fixed some spelling issues as well.
2024-07-13 11:49:21 +08:00
Haojian Wu
099c1527f6
[AST] Print the separator "," for template arguments in ConceptReference::print (#91750) 2024-05-10 18:13:47 +02:00
Bill Wendling
671365225c [NFC] Cleanup some #includes in header files
Limit the #includes to the least necessary to still compile. Move the
"new" function into the .cpp file to remove the need to #include
ASTContext.h into ASTConcept.h.

Differential Revision: https://reviews.llvm.org/D159320
2023-09-01 15:23:46 -07:00
Utkarsh Saxena
b3ce872851 Make evaluation of nested requirement consistent with requires expr.
Fixes: https://github.com/llvm/llvm-project/issues/45563
```
template<class T>  concept True = true;

template <class T>
concept C1 = requires (T) {
   requires True<typename T::value> || True<T>;
};

template <class T>
constexpr bool foo()
requires True<typename T::value> || True<T> {
    return true;
}
static_assert(C1<double>); // Previously failed due to SFINAE error
static_assert(foo<int>()); // but this works fine.
```
The issue here is the discrepancy between how a [nested requirement is evaluated](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaTemplateInstantiate.cpp#L2331) Vs how a [non-nested requirement is evaluated](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaConcept.cpp#L167-L200).

This patch makes constraint checking consistent for nested requirement
and trailing requires expressions by reusing the same evaluator.

Differential Revision: https://reviews.llvm.org/D138914
2022-12-19 20:22:03 +01:00
Erich Keane
684a78968b Reapply "[Concepts] Recover properly from a RecoveryExpr in a concept"
This reverts commit 192d69f7e65a625e344421841e731e39f80595f5.

This fixes the condition to check whether this is a situation where we
are in a recovery-expr'ed concept a little better, so we don't access an
inactive member of a union, which should make the bots happy.

Differential Revision: https://reviews.llvm.org/D134542
2022-09-26 08:39:10 -07:00
Erich Keane
192d69f7e6 Revert "[Concepts] Recover properly from a RecoveryExpr in a concept"
This reverts commit e3d14bee238b672a7a112311eefee55e142eaefc.

There are apparently a large number of crashes in libcxx and some JSON
Parser thing, so clearly this has some sort of serious issue.  Reverting
so I can take some time to figure out what is going on.
2022-09-26 06:55:25 -07:00
Erich Keane
e3d14bee23 [Concepts] Recover properly from a RecoveryExpr in a concept
Discovered by reducing a different problem, we currently assert because
we failed to make the constraint expressions not dependent, since a
RecoveryExpr cannot be transformed.

This patch fixes that, and gets reasonably nice diagnostics by
introducing a concept (hah!) of "ContainsErrors" to the Satisfaction
types, which causes us to treat the candidate as non-viable.

However, just making THAT candidate non-viable would result in choosing
the 'next best' canddiate, which can result in awkward errors, where we
start evaluating a candidate that is not intended to be selected.
Because of this, and to make diagnostics more relevant, we now just
cause the entire lookup to result in a 'no-viable-candidates'.

This means we will only emit the list of candidates, rather than any
cascading failures.
2022-09-26 06:33:48 -07:00
Christopher Di Bella
c874dd5362 [llvm][clang][NFC] updates inline licence info
Some files still contained the old University of Illinois Open Source
Licence header. This patch replaces that with the Apache 2 with LLVM
Exception licence.

Differential Revision: https://reviews.llvm.org/D107528
2021-08-11 02:48:53 +00:00
Saar Raz
713562f548 [Concepts] Transform constraints of non-template functions to ConstantEvaluated
We would previously try to evaluate atomic constraints of non-template functions as-is,
and since they are now unevaluated at first, this would cause incorrect evaluation (bugs #44657, #44656).

Substitute into atomic constraints of non-template functions as we would atomic constraints
of template functions, in order to rebuild the expressions in a constant-evaluated context.
2020-01-25 23:00:24 +02:00
Saar Raz
bb9b964072 [Concepts] Fix circular AST->Sema dependency in ASTConcept.cpp
Remove inappropriate Sema include in ASTConcept.cpp introduced by D72552 for the finer-grained includes actually needed.
2020-01-22 04:08:59 +02:00
Saar Raz
b933d37cd3 [Concepts] Constraint Satisfaction Caching
Add a simple cache for constraint satisfaction results. Whether or not this simple caching
would be permitted in final C++2a is currently being discussed but it is required for
acceptable performance so we use it in the meantime, with the possibility of adding some
cache invalidation mechanisms later.

Differential Revision: https://reviews.llvm.org/D72552
2020-01-22 03:09:53 +02:00
Saar Raz
e7c2466781 [Concepts] Fix build failures in D41569
Fix build failures in previous commit.
2019-12-06 01:53:18 +02:00
Saar Raz
fdf80e86a5 [Concepts] Constraint Enforcement & Diagnostics
Part of the C++20 concepts implementation effort.
- Associated constraints (requires clauses, currently) are now enforced when instantiating/specializing templates and when considering partial specializations and function overloads.
- Elaborated diagnostics give helpful insight as to why the constraints were not satisfied.
Phabricator: D41569

Re-commit, after fixing some memory bugs.
2019-12-06 01:34:20 +02:00
Vlad Tsyrklevich
38839d08b8 Revert "[Concepts] Constraint Enforcement & Diagnostics"
This reverts commit ffa214ef22892d75340dc6720271863901dc2c90, it was
causing ASAN test failures on sanitizer-x86_64-linux-bootstrap.
2019-10-28 15:00:40 -07:00
Saar Raz
ffa214ef22 [Concepts] Constraint Enforcement & Diagnostics
Part of the C++20 concepts implementation effort.
- Associated constraints (requires clauses, currently) are now enforced when instantiating/specializing templates and when considering partial specializations and function overloads.
- Elaborated diagnostics give helpful insight as to why the constraints were not satisfied.
Phabricator: D41569
2019-10-25 00:19:51 +03:00