Skip to content

Commit 2428a5e

Browse files
Merge from 'main' to 'sycl-web' (22 commits)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaLambda.cpp
2 parents 9a1612a + 44f2baa commit 2428a5e

File tree

101 files changed

+1398
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1398
-416
lines changed

clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,8 @@ bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
785785
const LambdaCapture *C,
786786
Expr *Init) {
787787
if (C->capturesVariable()) {
788-
const VarDecl *VDecl = C->getCapturedVar();
789-
if (areSameVariable(IndexVar, cast<ValueDecl>(VDecl))) {
788+
const ValueDecl *VDecl = C->getCapturedVar();
789+
if (areSameVariable(IndexVar, VDecl)) {
790790
// FIXME: if the index is captured, it will count as an usage and the
791791
// alias (if any) won't work, because it is only used in case of having
792792
// exactly one usage.

clang/docs/ReleaseNotes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ C++ Language Changes in Clang
105105
C++20 Feature Support
106106
^^^^^^^^^^^^^^^^^^^^^
107107

108+
- Support capturing structured bindings in lambdas
109+
(`P1091R3 <https://wg21.link/p1091r3>`_ and `P1381R1 <https://wg21.link/P1381R1>`).
110+
This fixes issues `GH52720 <https://github.com/llvm/llvm-project/issues/52720>`_,
111+
`GH54300 <https://github.com/llvm/llvm-project/issues/54300>`_,
112+
`GH54301 <https://github.com/llvm/llvm-project/issues/54301>`_,
113+
and `GH49430 <https://github.com/llvm/llvm-project/issues/49430>`_.
114+
115+
116+
117+
108118
C++2b Feature Support
109119
^^^^^^^^^^^^^^^^^^^^^
110120

clang/include/clang/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ class ValueDecl : public NamedDecl {
690690
/// or declared with the weak or weak-ref attr.
691691
bool isWeak() const;
692692

693+
/// Whether this variable is the implicit variable for a lambda init-capture.
694+
/// Only VarDecl can be init captures, but both VarDecl and BindingDecl
695+
/// can be captured.
696+
bool isInitCapture() const;
697+
693698
// Implement isa/cast/dyncast/etc.
694699
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
695700
static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }

clang/include/clang/AST/DeclCXX.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,9 @@ class CXXRecordDecl : public RecordDecl {
10571057
///
10581058
/// \note No entries will be added for init-captures, as they do not capture
10591059
/// variables.
1060-
void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1061-
FieldDecl *&ThisCapture) const;
1060+
void
1061+
getCaptureFields(llvm::DenseMap<const ValueDecl *, FieldDecl *> &Captures,
1062+
FieldDecl *&ThisCapture) const;
10621063

10631064
using capture_const_iterator = const LambdaCapture *;
10641065
using capture_const_range = llvm::iterator_range<capture_const_iterator>;

clang/include/clang/AST/LambdaCapture.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class LambdaCapture {
7171
/// capture that is a pack expansion, or an invalid source
7272
/// location to indicate that this is not a pack expansion.
7373
LambdaCapture(SourceLocation Loc, bool Implicit, LambdaCaptureKind Kind,
74-
VarDecl *Var = nullptr,
74+
ValueDecl *Var = nullptr,
7575
SourceLocation EllipsisLoc = SourceLocation());
7676

7777
/// Determine the kind of capture.
@@ -86,7 +86,7 @@ class LambdaCapture {
8686

8787
/// Determine whether this capture handles a variable.
8888
bool capturesVariable() const {
89-
return isa_and_nonnull<VarDecl>(DeclAndBits.getPointer());
89+
return isa_and_nonnull<ValueDecl>(DeclAndBits.getPointer());
9090
}
9191

9292
/// Determine whether this captures a variable length array bound
@@ -101,9 +101,9 @@ class LambdaCapture {
101101
///
102102
/// This operation is only valid if this capture is a variable capture
103103
/// (other than a capture of \c this).
104-
VarDecl *getCapturedVar() const {
104+
ValueDecl *getCapturedVar() const {
105105
assert(capturesVariable() && "No variable available for capture");
106-
return static_cast<VarDecl *>(DeclAndBits.getPointer());
106+
return static_cast<ValueDecl *>(DeclAndBits.getPointer());
107107
}
108108

109109
/// Determine whether this was an implicit capture (not

clang/include/clang/AST/Stmt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class RecordDecl;
5959
class SourceManager;
6060
class StringLiteral;
6161
class Token;
62+
class ValueDecl;
6263
class VarDecl;
6364

6465
//===----------------------------------------------------------------------===//

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4722,7 +4722,7 @@ AST_MATCHER_P(LambdaExpr, hasAnyCapture, internal::Matcher<LambdaCapture>,
47224722
/// In the matcher
47234723
/// lambdaExpr(hasAnyCapture(lambdaCapture(capturesVar(hasName("x")))),
47244724
/// capturesVar(hasName("x")) matches `x` and `x = 1`.
4725-
AST_MATCHER_P(LambdaCapture, capturesVar, internal::Matcher<VarDecl>,
4725+
AST_MATCHER_P(LambdaCapture, capturesVar, internal::Matcher<ValueDecl>,
47264726
InnerMatcher) {
47274727
auto *capturedVar = Node.getCapturedVar();
47284728
return capturedVar && InnerMatcher.matches(*capturedVar, Finder, Builder);

clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ namespace dataflow {
3030
/// analysis.
3131
class ControlFlowContext {
3232
public:
33-
/// Builds a ControlFlowContext from an AST node.
33+
/// Builds a ControlFlowContext from an AST node. `D` is the function in which
34+
/// `S` resides and must not be null.
35+
static llvm::Expected<ControlFlowContext> build(const Decl *D, Stmt &S,
36+
ASTContext &C);
37+
38+
// DEPRECATED. Use overload above.
3439
static llvm::Expected<ControlFlowContext> build(const Decl *D, Stmt *S,
3540
ASTContext *C);
3641

42+
/// Returns the `Decl` containing the statement used to construct the CFG, if
43+
/// available.
44+
const Decl *getDecl() const { return ContainingDecl; }
45+
3746
/// Returns the CFG that is stored in this context.
3847
const CFG &getCFG() const { return *Cfg; }
3948

@@ -43,10 +52,15 @@ class ControlFlowContext {
4352
}
4453

4554
private:
46-
ControlFlowContext(std::unique_ptr<CFG> Cfg,
55+
// FIXME: Once the deprecated `build` method is removed, mark `D` as "must not
56+
// be null" and add an assertion.
57+
ControlFlowContext(const Decl *D, std::unique_ptr<CFG> Cfg,
4758
llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock)
48-
: Cfg(std::move(Cfg)), StmtToBlock(std::move(StmtToBlock)) {}
59+
: ContainingDecl(D), Cfg(std::move(Cfg)),
60+
StmtToBlock(std::move(StmtToBlock)) {}
4961

62+
/// The `Decl` containing the statement used to construct the CFG.
63+
const Decl *ContainingDecl;
5064
std::unique_ptr<CFG> Cfg;
5165
llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock;
5266
};

clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "clang/AST/ASTContext.h"
2222
#include "clang/AST/Stmt.h"
23-
#include "clang/Analysis/CFG.h"
2423
#include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
2524
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
2625
#include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"

clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/AST/Decl.h"
1919
#include "clang/AST/Expr.h"
2020
#include "clang/AST/TypeOrdering.h"
21+
#include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
2122
#include "clang/Analysis/FlowSensitive/Solver.h"
2223
#include "clang/Analysis/FlowSensitive/StorageLocation.h"
2324
#include "clang/Analysis/FlowSensitive/Value.h"
@@ -254,6 +255,10 @@ class DataflowAnalysisContext {
254255

255256
LLVM_DUMP_METHOD void dumpFlowCondition(AtomicBoolValue &Token);
256257

258+
/// Returns the `ControlFlowContext` registered for `F`, if any. Otherwise,
259+
/// returns null.
260+
const ControlFlowContext *getControlFlowContext(const FunctionDecl *F);
261+
257262
private:
258263
struct NullableQualTypeDenseMapInfo : private llvm::DenseMapInfo<QualType> {
259264
static QualType getEmptyKey() {
@@ -360,6 +365,8 @@ class DataflowAnalysisContext {
360365
llvm::DenseMap<AtomicBoolValue *, llvm::DenseSet<AtomicBoolValue *>>
361366
FlowConditionDeps;
362367
llvm::DenseMap<AtomicBoolValue *, BoolValue *> FlowConditionConstraints;
368+
369+
llvm::DenseMap<const FunctionDecl *, ControlFlowContext> FunctionContexts;
363370
};
364371

365372
} // namespace dataflow

0 commit comments

Comments
 (0)