Skip to content

Commit 31bbcd5

Browse files
authored
Merge branch 'main' into fix/100394
2 parents 29f8470 + bb937e2 commit 31bbcd5

File tree

163 files changed

+3367
-1784
lines changed

Some content is hidden

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

163 files changed

+3367
-1784
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ C++23 Feature Support
171171
^^^^^^^^^^^^^^^^^^^^^
172172
- Removed the restriction to literal types in constexpr functions in C++23 mode.
173173

174+
- Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now fully
175+
supported `P2718R0 Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_.
176+
174177
C++20 Feature Support
175178
^^^^^^^^^^^^^^^^^^^^^
176179

clang/include/clang/AST/Attr.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ class InheritableParamAttr : public InheritableAttr {
197197
}
198198
};
199199

200+
class InheritableParamOrStmtAttr : public InheritableParamAttr {
201+
protected:
202+
InheritableParamOrStmtAttr(ASTContext &Context,
203+
const AttributeCommonInfo &CommonInfo,
204+
attr::Kind AK, bool IsLateParsed,
205+
bool InheritEvenIfAlreadyPresent)
206+
: InheritableParamAttr(Context, CommonInfo, AK, IsLateParsed,
207+
InheritEvenIfAlreadyPresent) {}
208+
209+
public:
210+
// Implement isa/cast/dyncast/etc.
211+
static bool classof(const Attr *A) {
212+
return A->getKind() >= attr::FirstInheritableParamOrStmtAttr &&
213+
A->getKind() <= attr::LastInheritableParamOrStmtAttr;
214+
}
215+
};
216+
200217
class HLSLAnnotationAttr : public InheritableAttr {
201218
protected:
202219
HLSLAnnotationAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,

clang/include/clang/Basic/Attr.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ class TargetSpecificAttr<TargetSpec target> {
759759
/// redeclarations, even when it's written on a parameter.
760760
class InheritableParamAttr : InheritableAttr;
761761

762+
/// A attribute that is either a declaration attribute or a statement attribute,
763+
/// and if used as a declaration attribute, is inherited by later
764+
/// redeclarations, even when it's written on a parameter.
765+
class InheritableParamOrStmtAttr : InheritableParamAttr;
766+
762767
/// An attribute which changes the ABI rules for a specific parameter.
763768
class ParameterABIAttr : InheritableParamAttr {
764769
let Subjects = SubjectList<[ParmVar]>;
@@ -928,7 +933,7 @@ def AnalyzerNoReturn : InheritableAttr {
928933
let Documentation = [Undocumented];
929934
}
930935

931-
def Annotate : InheritableParamAttr {
936+
def Annotate : InheritableParamOrStmtAttr {
932937
let Spellings = [Clang<"annotate">];
933938
let Args = [StringArgument<"Annotation">, VariadicExprArgument<"Args">];
934939
// Ensure that the annotate attribute can be used with

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4528,9 +4528,10 @@ class Sema final : public SemaBase {
45284528
/// declaration.
45294529
void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E);
45304530

4531-
/// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D.
4532-
void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI,
4533-
StringRef Annot, MutableArrayRef<Expr *> Args);
4531+
/// CreateAnnotationAttr - Creates an annotation Annot with Args arguments.
4532+
Attr *CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot,
4533+
MutableArrayRef<Expr *> Args);
4534+
Attr *CreateAnnotationAttr(const ParsedAttr &AL);
45344535

45354536
bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range,
45364537
bool BestCase,

clang/lib/Analysis/ProgramPoint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void ProgramPoint::printJson(llvm::raw_ostream &Out, const char *NL) const {
157157
LHS->printJson(Out, nullptr, PP, AddQuotes);
158158
} else {
159159
Out << "null";
160-
}
160+
}
161161

162162
Out << ", \"rhs\": ";
163163
if (const Stmt *RHS = C->getRHS()) {

clang/lib/Basic/Targets/DirectX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo {
6262
PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
6363
resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
6464
"32-f64:64-n8:16:32:64");
65-
TheCXXABI.set(TargetCXXABI::Microsoft);
65+
TheCXXABI.set(TargetCXXABI::GenericItanium);
6666
}
6767
bool useFP16ConversionIntrinsics() const override { return false; }
6868
void getTargetDefines(const LangOptions &Opts,

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18867,9 +18867,21 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1886718867
ArrayRef<Value *>{Op0, Op1}, nullptr, "hlsl.step");
1886818868
}
1886918869
case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
18870-
return EmitRuntimeCall(CGM.CreateRuntimeFunction(
18871-
llvm::FunctionType::get(IntTy, {}, false), "__hlsl_wave_get_lane_index",
18872-
{}, false, true));
18870+
// We don't define a SPIR-V intrinsic, instead it is a SPIR-V built-in
18871+
// defined in SPIRVBuiltins.td. So instead we manually get the matching name
18872+
// for the DirectX intrinsic and the demangled builtin name
18873+
switch (CGM.getTarget().getTriple().getArch()) {
18874+
case llvm::Triple::dxil:
18875+
return EmitRuntimeCall(Intrinsic::getDeclaration(
18876+
&CGM.getModule(), Intrinsic::dx_wave_getlaneindex));
18877+
case llvm::Triple::spirv:
18878+
return EmitRuntimeCall(CGM.CreateRuntimeFunction(
18879+
llvm::FunctionType::get(IntTy, {}, false),
18880+
"__hlsl_wave_get_lane_index", {}, false, true));
18881+
default:
18882+
llvm_unreachable(
18883+
"Intrinsic WaveGetLaneIndex not supported by target architecture");
18884+
}
1887318885
}
1887418886
case Builtin::BI__builtin_hlsl_wave_is_first_lane: {
1887518887
Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,10 @@ void ItaniumCXXABI::registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
29972997
if (D.isNoDestroy(CGM.getContext()))
29982998
return;
29992999

3000+
// HLSL doesn't support atexit.
3001+
if (CGM.getLangOpts().HLSL)
3002+
return CGM.AddCXXDtorEntry(dtor, addr);
3003+
30003004
// OpenMP offloading supports C++ constructors and destructors but we do not
30013005
// always have 'atexit' available. Instead lower these to use the LLVM global
30023006
// destructors which we can handle directly in the runtime. Note that this is

clang/lib/Sema/Sema.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,3 +2777,31 @@ bool Sema::isDeclaratorFunctionLike(Declarator &D) {
27772777
});
27782778
return Result;
27792779
}
2780+
2781+
Attr *Sema::CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot,
2782+
MutableArrayRef<Expr *> Args) {
2783+
2784+
auto *A = AnnotateAttr::Create(Context, Annot, Args.data(), Args.size(), CI);
2785+
if (!ConstantFoldAttrArgs(
2786+
CI, MutableArrayRef<Expr *>(A->args_begin(), A->args_end()))) {
2787+
return nullptr;
2788+
}
2789+
return A;
2790+
}
2791+
2792+
Attr *Sema::CreateAnnotationAttr(const ParsedAttr &AL) {
2793+
// Make sure that there is a string literal as the annotation's first
2794+
// argument.
2795+
StringRef Str;
2796+
if (!checkStringLiteralArgumentAttr(AL, 0, Str))
2797+
return nullptr;
2798+
2799+
llvm::SmallVector<Expr *, 4> Args;
2800+
Args.reserve(AL.getNumArgs() - 1);
2801+
for (unsigned Idx = 1; Idx < AL.getNumArgs(); Idx++) {
2802+
assert(!AL.isArgIdent(Idx));
2803+
Args.push_back(AL.getArgAsExpr(Idx));
2804+
}
2805+
2806+
return CreateAnnotationAttr(AL, Str, Args);
2807+
}

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,30 +3958,11 @@ static void handleTransparentUnionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
39583958
RD->addAttr(::new (S.Context) TransparentUnionAttr(S.Context, AL));
39593959
}
39603960

3961-
void Sema::AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI,
3962-
StringRef Str, MutableArrayRef<Expr *> Args) {
3963-
auto *Attr = AnnotateAttr::Create(Context, Str, Args.data(), Args.size(), CI);
3964-
if (ConstantFoldAttrArgs(
3965-
CI, MutableArrayRef<Expr *>(Attr->args_begin(), Attr->args_end()))) {
3966-
D->addAttr(Attr);
3967-
}
3968-
}
3969-
39703961
static void handleAnnotateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3971-
// Make sure that there is a string literal as the annotation's first
3972-
// argument.
3973-
StringRef Str;
3974-
if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
3975-
return;
3976-
3977-
llvm::SmallVector<Expr *, 4> Args;
3978-
Args.reserve(AL.getNumArgs() - 1);
3979-
for (unsigned Idx = 1; Idx < AL.getNumArgs(); Idx++) {
3980-
assert(!AL.isArgIdent(Idx));
3981-
Args.push_back(AL.getArgAsExpr(Idx));
3962+
auto *Attr = S.CreateAnnotationAttr(AL);
3963+
if (Attr) {
3964+
D->addAttr(Attr);
39823965
}
3983-
3984-
S.AddAnnotationAttr(D, AL, Str, Args);
39853966
}
39863967

39873968
static void handleAlignValueAttr(Sema &S, Decl *D, const ParsedAttr &AL) {

0 commit comments

Comments
 (0)