Skip to content

Commit 5e174f8

Browse files
committed
Merge from 'main' to 'sycl-web' (36 commits)
CONFLICT (content): Merge conflict in clang/include/clang/Sema/SemaSYCL.h CONFLICT (content): Merge conflict in clang/lib/Sema/SemaSYCL.cpp
2 parents cb35278 + 8fb4230 commit 5e174f8

File tree

203 files changed

+14164
-7343
lines changed

Some content is hidden

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

203 files changed

+14164
-7343
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ Bug Fixes to C++ Support
971971
- Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033)
972972
- Fixed a nested lambda substitution issue for constraint evaluation. (#GH123441)
973973
- Fixed various false diagnostics related to the use of immediate functions. (#GH123472)
974+
- Fix immediate escalation not propagating through inherited constructors. (#GH112677)
974975

975976
Bug Fixes to AST Handling
976977
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class ASTNodeTraverser
158158
ConstStmtVisitor<Derived>::Visit(S);
159159

160160
// Some statements have custom mechanisms for dumping their children.
161-
if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S) ||
162-
isa<RequiresExpr>(S) || isa<OpenACCWaitConstruct>(S))
161+
if (isa<DeclStmt, GenericSelectionExpr, RequiresExpr,
162+
OpenACCWaitConstruct, SYCLKernelCallStmt>(S))
163163
return;
164164

165165
if (Traversal == TK_IgnoreUnlessSpelledInSource &&
@@ -585,6 +585,12 @@ class ASTNodeTraverser
585585

586586
void VisitTopLevelStmtDecl(const TopLevelStmtDecl *D) { Visit(D->getStmt()); }
587587

588+
void VisitOutlinedFunctionDecl(const OutlinedFunctionDecl *D) {
589+
for (const ImplicitParamDecl *Parameter : D->parameters())
590+
Visit(Parameter);
591+
Visit(D->getBody());
592+
}
593+
588594
void VisitCapturedDecl(const CapturedDecl *D) { Visit(D->getBody()); }
589595

590596
void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
@@ -815,6 +821,12 @@ class ASTNodeTraverser
815821
Visit(Node->getCapturedDecl());
816822
}
817823

824+
void VisitSYCLKernelCallStmt(const SYCLKernelCallStmt *Node) {
825+
Visit(Node->getOriginalStmt());
826+
if (Traversal != TK_IgnoreUnlessSpelledInSource)
827+
Visit(Node->getOutlinedFunctionDecl());
828+
}
829+
818830
void VisitOMPExecutableDirective(const OMPExecutableDirective *Node) {
819831
for (const auto *C : Node->clauses())
820832
Visit(C);

clang/include/clang/AST/Decl.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4689,6 +4689,83 @@ class BlockDecl : public Decl, public DeclContext {
46894689
}
46904690
};
46914691

4692+
/// Represents a partial function definition.
4693+
///
4694+
/// An outlined function declaration contains the parameters and body of
4695+
/// a function independent of other function definition concerns such
4696+
/// as function name, type, and calling convention. Such declarations may
4697+
/// be used to hold a parameterized and transformed sequence of statements
4698+
/// used to generate a target dependent function definition without losing
4699+
/// association with the original statements. See SYCLKernelCallStmt as an
4700+
/// example.
4701+
class OutlinedFunctionDecl final
4702+
: public Decl,
4703+
public DeclContext,
4704+
private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
4705+
private:
4706+
/// The number of parameters to the outlined function.
4707+
unsigned NumParams;
4708+
4709+
/// The body of the outlined function.
4710+
llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4711+
4712+
explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
4713+
4714+
ImplicitParamDecl *const *getParams() const {
4715+
return getTrailingObjects<ImplicitParamDecl *>();
4716+
}
4717+
4718+
ImplicitParamDecl **getParams() {
4719+
return getTrailingObjects<ImplicitParamDecl *>();
4720+
}
4721+
4722+
public:
4723+
friend class ASTDeclReader;
4724+
friend class ASTDeclWriter;
4725+
friend TrailingObjects;
4726+
4727+
static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
4728+
unsigned NumParams);
4729+
static OutlinedFunctionDecl *
4730+
CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
4731+
4732+
Stmt *getBody() const override;
4733+
void setBody(Stmt *B);
4734+
4735+
bool isNothrow() const;
4736+
void setNothrow(bool Nothrow = true);
4737+
4738+
unsigned getNumParams() const { return NumParams; }
4739+
4740+
ImplicitParamDecl *getParam(unsigned i) const {
4741+
assert(i < NumParams);
4742+
return getParams()[i];
4743+
}
4744+
void setParam(unsigned i, ImplicitParamDecl *P) {
4745+
assert(i < NumParams);
4746+
getParams()[i] = P;
4747+
}
4748+
4749+
// Range interface to parameters.
4750+
using parameter_const_iterator = const ImplicitParamDecl *const *;
4751+
using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
4752+
parameter_const_range parameters() const {
4753+
return {param_begin(), param_end()};
4754+
}
4755+
parameter_const_iterator param_begin() const { return getParams(); }
4756+
parameter_const_iterator param_end() const { return getParams() + NumParams; }
4757+
4758+
// Implement isa/cast/dyncast/etc.
4759+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4760+
static bool classofKind(Kind K) { return K == OutlinedFunction; }
4761+
static DeclContext *castToDeclContext(const OutlinedFunctionDecl *D) {
4762+
return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
4763+
}
4764+
static OutlinedFunctionDecl *castFromDeclContext(const DeclContext *DC) {
4765+
return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
4766+
}
4767+
};
4768+
46924769
/// Represents the body of a CapturedStmt, and serves as its DeclContext.
46934770
class CapturedDecl final
46944771
: public Decl,

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "clang/AST/StmtObjC.h"
3838
#include "clang/AST/StmtOpenACC.h"
3939
#include "clang/AST/StmtOpenMP.h"
40+
#include "clang/AST/StmtSYCL.h"
4041
#include "clang/AST/TemplateBase.h"
4142
#include "clang/AST/TemplateName.h"
4243
#include "clang/AST/Type.h"
@@ -1581,6 +1582,11 @@ DEF_TRAVERSE_DECL(BlockDecl, {
15811582
ShouldVisitChildren = false;
15821583
})
15831584

1585+
DEF_TRAVERSE_DECL(OutlinedFunctionDecl, {
1586+
TRY_TO(TraverseStmt(D->getBody()));
1587+
ShouldVisitChildren = false;
1588+
})
1589+
15841590
DEF_TRAVERSE_DECL(CapturedDecl, {
15851591
TRY_TO(TraverseStmt(D->getBody()));
15861592
ShouldVisitChildren = false;
@@ -2919,6 +2925,14 @@ DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
29192925
DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
29202926
DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
29212927

2928+
DEF_TRAVERSE_STMT(SYCLKernelCallStmt, {
2929+
if (getDerived().shouldVisitImplicitCode()) {
2930+
TRY_TO(TraverseStmt(S->getOriginalStmt()));
2931+
TRY_TO(TraverseDecl(S->getOutlinedFunctionDecl()));
2932+
ShouldVisitChildren = false;
2933+
}
2934+
})
2935+
29222936
DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
29232937
DEF_TRAVERSE_STMT(CXXRewrittenBinaryOperator, {
29242938
if (!getDerived().shouldVisitImplicitCode()) {

clang/include/clang/AST/StmtSYCL.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//===- StmtSYCL.h - Classes for SYCL kernel calls ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file defines SYCL AST classes used to represent calls to SYCL kernels.
10+
//===----------------------------------------------------------------------===//
11+
12+
#ifndef LLVM_CLANG_AST_STMTSYCL_H
13+
#define LLVM_CLANG_AST_STMTSYCL_H
14+
15+
#include "clang/AST/ASTContext.h"
16+
#include "clang/AST/Decl.h"
17+
#include "clang/AST/Stmt.h"
18+
#include "clang/Basic/SourceLocation.h"
19+
20+
namespace clang {
21+
22+
//===----------------------------------------------------------------------===//
23+
// AST classes for SYCL kernel calls.
24+
//===----------------------------------------------------------------------===//
25+
26+
/// SYCLKernelCallStmt represents the transformation that is applied to the body
27+
/// of a function declared with the sycl_kernel_entry_point attribute. The body
28+
/// of such a function specifies the statements to be executed on a SYCL device
29+
/// to invoke a SYCL kernel with a particular set of kernel arguments. The
30+
/// SYCLKernelCallStmt associates an original statement (the compound statement
31+
/// that is the function body) with an OutlinedFunctionDecl that holds the
32+
/// kernel parameters and the transformed body. During code generation, the
33+
/// OutlinedFunctionDecl is used to emit an offload kernel entry point suitable
34+
/// for invocation from a SYCL library implementation. If executed, the
35+
/// SYCLKernelCallStmt behaves as a no-op; no code generation is performed for
36+
/// it.
37+
class SYCLKernelCallStmt : public Stmt {
38+
friend class ASTStmtReader;
39+
friend class ASTStmtWriter;
40+
41+
private:
42+
Stmt *OriginalStmt = nullptr;
43+
OutlinedFunctionDecl *OFDecl = nullptr;
44+
45+
public:
46+
/// Construct a SYCL kernel call statement.
47+
SYCLKernelCallStmt(CompoundStmt *CS, OutlinedFunctionDecl *OFD)
48+
: Stmt(SYCLKernelCallStmtClass), OriginalStmt(CS), OFDecl(OFD) {}
49+
50+
/// Construct an empty SYCL kernel call statement.
51+
SYCLKernelCallStmt(EmptyShell Empty) : Stmt(SYCLKernelCallStmtClass, Empty) {}
52+
53+
/// Retrieve the model statement.
54+
CompoundStmt *getOriginalStmt() { return cast<CompoundStmt>(OriginalStmt); }
55+
const CompoundStmt *getOriginalStmt() const {
56+
return cast<CompoundStmt>(OriginalStmt);
57+
}
58+
void setOriginalStmt(CompoundStmt *CS) { OriginalStmt = CS; }
59+
60+
/// Retrieve the outlined function declaration.
61+
OutlinedFunctionDecl *getOutlinedFunctionDecl() { return OFDecl; }
62+
const OutlinedFunctionDecl *getOutlinedFunctionDecl() const { return OFDecl; }
63+
64+
/// Set the outlined function declaration.
65+
void setOutlinedFunctionDecl(OutlinedFunctionDecl *OFD) { OFDecl = OFD; }
66+
67+
SourceLocation getBeginLoc() const LLVM_READONLY {
68+
return getOriginalStmt()->getBeginLoc();
69+
}
70+
71+
SourceLocation getEndLoc() const LLVM_READONLY {
72+
return getOriginalStmt()->getEndLoc();
73+
}
74+
75+
SourceRange getSourceRange() const LLVM_READONLY {
76+
return getOriginalStmt()->getSourceRange();
77+
}
78+
79+
static bool classof(const Stmt *T) {
80+
return T->getStmtClass() == SYCLKernelCallStmtClass;
81+
}
82+
83+
child_range children() {
84+
return child_range(&OriginalStmt, &OriginalStmt + 1);
85+
}
86+
87+
const_child_range children() const {
88+
return const_child_range(&OriginalStmt, &OriginalStmt + 1);
89+
}
90+
};
91+
92+
} // end namespace clang
93+
94+
#endif // LLVM_CLANG_AST_STMTSYCL_H

clang/include/clang/AST/StmtVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/AST/StmtObjC.h"
2323
#include "clang/AST/StmtOpenACC.h"
2424
#include "clang/AST/StmtOpenMP.h"
25+
#include "clang/AST/StmtSYCL.h"
2526
#include "clang/Basic/LLVM.h"
2627
#include "llvm/ADT/STLExtras.h"
2728
#include "llvm/Support/Casting.h"

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ following requirements.
487487
* Is not a C variadic function.
488488
* Is not a coroutine.
489489
* Is not defined as deleted or as defaulted.
490+
* Is not defined with a function try block.
490491
* Is not declared with the ``constexpr`` or ``consteval`` specifiers.
491492
* Is not declared with the ``[[noreturn]]`` attribute.
492493

clang/include/clang/Basic/BuiltinsSPIRV.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ def SPIRVLength : Builtin {
1919
let Attributes = [NoThrow, Const];
2020
let Prototype = "void(...)";
2121
}
22+
23+
def SPIRVReflect : Builtin {
24+
let Spellings = ["__builtin_spirv_reflect"];
25+
let Attributes = [NoThrow, Const];
26+
let Prototype = "void(...)";
27+
}

clang/include/clang/Basic/DeclNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def Friend : DeclNode<Decl>;
101101
def FriendTemplate : DeclNode<Decl>;
102102
def StaticAssert : DeclNode<Decl>;
103103
def Block : DeclNode<Decl, "blocks">, DeclContext;
104+
def OutlinedFunction : DeclNode<Decl>, DeclContext;
104105
def Captured : DeclNode<Decl>, DeclContext;
105106
def Import : DeclNode<Decl>;
106107
def OMPThreadPrivate : DeclNode<Decl>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12593,7 +12593,8 @@ def err_sycl_entry_point_invalid : Error<
1259312593
"'sycl_kernel_entry_point' attribute cannot be applied to a"
1259412594
" %select{non-static member function|variadic function|deleted function|"
1259512595
"defaulted function|constexpr function|consteval function|"
12596-
"function declared with the 'noreturn' attribute|coroutine}0">;
12596+
"function declared with the 'noreturn' attribute|coroutine|"
12597+
"function defined with a function try block}0">;
1259712598
def err_sycl_entry_point_invalid_redeclaration : Error<
1259812599
"'sycl_kernel_entry_point' kernel name argument does not match prior"
1259912600
" declaration%diff{: $ vs $|}0,1">;

clang/include/clang/Basic/StmtNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def SwitchCase : StmtNode<Stmt, 1>;
2424
def CaseStmt : StmtNode<SwitchCase>;
2525
def DefaultStmt : StmtNode<SwitchCase>;
2626
def CapturedStmt : StmtNode<Stmt>;
27+
def SYCLKernelCallStmt : StmtNode<Stmt>;
2728

2829
// Statements that might produce a value (for example, as the last non-null
2930
// statement in a GNU statement-expression).

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13131,7 +13131,7 @@ class Sema final : public SemaBase {
1313113131
auto *FD = dyn_cast<FunctionDecl>(DC);
1313213132
S.PushFunctionScope();
1313313133
S.PushExpressionEvaluationContext(
13134-
(FD && FD->isConsteval())
13134+
(FD && FD->isImmediateFunction())
1313513135
? ExpressionEvaluationContext::ImmediateFunctionContext
1313613136
: ExpressionEvaluationContext::PotentiallyEvaluated);
1313713137
if (FD) {

clang/include/clang/Sema/SemaSYCL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ class SemaSYCL : public SemaBase {
666666
// Used to check whether the function represented by FD is a SYCL
667667
// free function kernel or not.
668668
bool isFreeFunction(const FunctionDecl *FD);
669+
670+
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body);
669671
};
670672

671673
} // namespace clang

clang/include/clang/Sema/Template.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,10 @@ enum class TemplateSubstitutionKind : char {
627627
#define EMPTY(DERIVED, BASE)
628628
#define LIFETIMEEXTENDEDTEMPORARY(DERIVED, BASE)
629629

630-
// Decls which use special-case instantiation code.
630+
// Decls which never appear inside a template.
631+
#define OUTLINEDFUNCTION(DERIVED, BASE)
632+
633+
// Decls which use special-case instantiation code.
631634
#define BLOCK(DERIVED, BASE)
632635
#define CAPTURED(DERIVED, BASE)
633636
#define IMPLICITPARAM(DERIVED, BASE)

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,9 @@ enum DeclCode {
13211321
/// A BlockDecl record.
13221322
DECL_BLOCK,
13231323

1324+
/// A OutlinedFunctionDecl record.
1325+
DECL_OUTLINEDFUNCTION,
1326+
13241327
/// A CapturedDecl record.
13251328
DECL_CAPTURED,
13261329

@@ -1605,6 +1608,9 @@ enum StmtCode {
16051608
/// A CapturedStmt record.
16061609
STMT_CAPTURED,
16071610

1611+
/// A SYCLKernelCallStmt record.
1612+
STMT_SYCLKERNELCALL,
1613+
16081614
/// A GCC-style AsmStmt record.
16091615
STMT_GCCASM,
16101616

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "clang/AST/StmtObjC.h"
7777
#include "clang/AST/StmtOpenACC.h"
7878
#include "clang/AST/StmtOpenMP.h"
79+
#include "clang/AST/StmtSYCL.h"
7980
#include "clang/AST/TemplateBase.h"
8081
#include "clang/AST/TemplateName.h"
8182
#include "clang/AST/Type.h"

0 commit comments

Comments
 (0)