Skip to content

Commit a356ccd

Browse files
committed
merge main into amd-staging
2 parents ae68759 + f9386d3 commit a356ccd

File tree

67 files changed

+1320
-184
lines changed

Some content is hidden

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

67 files changed

+1320
-184
lines changed

clang/docs/HardwareAssistedAddressSanitizerDesign.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ implement page aliasing.
291291

292292
Related Work
293293
============
294-
* `SPARC ADI`_ implements a similar tool mostly in hardware.
294+
* `SPARC ADI`_ and `Arm MTE`_ implement a similar tool mostly in hardware.
295295
* `Effective and Efficient Memory Protection Using Dynamic Tainting`_ discusses
296296
similar approaches ("lock & key").
297297
* `Watchdog`_ discussed a heavier, but still somewhat similar
@@ -302,6 +302,7 @@ Related Work
302302
.. _Watchdog: https://www.cis.upenn.edu/acg/papers/isca12_watchdog.pdf
303303
.. _Effective and Efficient Memory Protection Using Dynamic Tainting: https://www.cc.gatech.edu/~orso/papers/clause.doudalis.orso.prvulovic.pdf
304304
.. _SPARC ADI: https://lazytyped.blogspot.com/2017/09/getting-started-with-adi.html
305+
.. _Arm MTE: https://developer.arm.com/documentation/108035/0100/Introduction-to-the-Memory-Tagging-Extension
305306
.. _AddressSanitizer paper: https://www.usenix.org/system/files/conference/atc12/atc12-final39.pdf
306307
.. _Address Tagging: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/ch12s05s01.html
307308
.. _Linear Address Masking: https://software.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ Bug Fixes to Attribute Support
418418

419419
- ``[[nodiscard]]`` is now respected on Objective-C and Objective-C++ methods.
420420
(#GH141504)
421+
- Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with
422+
``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520)
421423

422424
Bug Fixes to C++ Support
423425
^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Design Documents
119119
OffloadingDesign
120120
PCHInternals
121121
ItaniumMangleAbiTags
122+
ControlFlowIntegrityDesign
122123
HardwareAssistedAddressSanitizerDesign.rst
123124
ConstantInterpreter
124125

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4887,6 +4887,14 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
48874887
let Documentation = [HLSLSV_GroupIndexDocs];
48884888
}
48894889

4890+
def HLSLVkBinding : InheritableAttr {
4891+
let Spellings = [CXX11<"vk", "binding">];
4892+
let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
4893+
let Args = [IntArgument<"Binding">, IntArgument<"Set", 1>];
4894+
let LangOpts = [HLSL];
4895+
let Documentation = [HLSLVkBindingDocs];
4896+
}
4897+
48904898
def HLSLResourceBinding: InheritableAttr {
48914899
let Spellings = [HLSLAnnotation<"register">];
48924900
let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8781,6 +8781,32 @@ def ReadOnlyPlacementDocs : Documentation {
87818781
}];
87828782
}
87838783

8784+
def HLSLVkBindingDocs : Documentation {
8785+
let Category = DocCatVariable;
8786+
let Content = [{
8787+
The ``[[vk::binding]]`` attribute allows you to explicitly specify the descriptor
8788+
set and binding for a resource when targeting SPIR-V. This is particularly
8789+
useful when you need different bindings for SPIR-V and DXIL, as the ``register``
8790+
attribute can be used for DXIL-specific bindings.
8791+
8792+
The attribute takes two integer arguments: the binding and the descriptor set.
8793+
The descriptor set is optional and defaults to 0 if not provided.
8794+
8795+
.. code-block:: c++
8796+
8797+
// A structured buffer with binding 23 in descriptor set 102.
8798+
[[vk::binding(23, 102)]] StructuredBuffer<float> Buf;
8799+
8800+
// A structured buffer with binding 14 in descriptor set 0.
8801+
[[vk::binding(14)]] StructuredBuffer<float> Buf2;
8802+
8803+
// A cbuffer with binding 1 in descriptor set 2.
8804+
[[vk::binding(1, 2)]] cbuffer MyCBuffer {
8805+
float4x4 worldViewProj;
8806+
};
8807+
}];
8808+
}
8809+
87848810
def WebAssemblyFuncrefDocs : Documentation {
87858811
let Category = DocCatType;
87868812
let Content = [{

clang/include/clang/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5191,7 +5191,7 @@ class Parser : public CodeCompletionHandler {
51915191
void ParseHLSLAnnotations(ParsedAttributes &Attrs,
51925192
SourceLocation *EndLoc = nullptr,
51935193
bool CouldBeBitField = false);
5194-
Decl *ParseHLSLBuffer(SourceLocation &DeclEnd);
5194+
Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
51955195

51965196
///@}
51975197

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class SemaHLSL : public SemaBase {
161161
void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
162162
void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
163163
void handleVkConstantIdAttr(Decl *D, const ParsedAttr &AL);
164+
void handleVkBindingAttr(Decl *D, const ParsedAttr &AL);
164165
void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
165166
void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL);
166167
void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL);

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,11 @@ namespace {
605605
llvm::Constant *CleanupFn;
606606
const CGFunctionInfo &FnInfo;
607607
const VarDecl &Var;
608+
const CleanupAttr *Attribute;
608609

609610
CallCleanupFunction(llvm::Constant *CleanupFn, const CGFunctionInfo *Info,
610-
const VarDecl *Var)
611-
: CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
611+
const VarDecl *Var, const CleanupAttr *Attr)
612+
: CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var), Attribute(Attr) {}
612613

613614
void Emit(CodeGenFunction &CGF, Flags flags) override {
614615
DeclRefExpr DRE(CGF.getContext(), const_cast<VarDecl *>(&Var), false,
@@ -630,8 +631,11 @@ namespace {
630631
CallArgList Args;
631632
Args.add(RValue::get(Arg),
632633
CGF.getContext().getPointerType(Var.getType()));
633-
auto Callee = CGCallee::forDirect(CleanupFn);
634-
CGF.EmitCall(FnInfo, Callee, ReturnValueSlot(), Args);
634+
GlobalDecl GD = GlobalDecl(Attribute->getFunctionDecl());
635+
auto Callee = CGCallee::forDirect(CleanupFn, CGCalleeInfo(GD));
636+
CGF.EmitCall(FnInfo, Callee, ReturnValueSlot(), Args,
637+
/*callOrInvoke*/ nullptr, /*IsMustTail*/ false,
638+
Attribute->getLoc());
635639
}
636640
};
637641
} // end anonymous namespace
@@ -2250,7 +2254,8 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) {
22502254
assert(F && "Could not find function!");
22512255

22522256
const CGFunctionInfo &Info = CGM.getTypes().arrangeFunctionDeclaration(FD);
2253-
EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info, &D);
2257+
EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info, &D,
2258+
CA);
22542259
}
22552260

22562261
// If this is a block variable, call _Block_object_destroy

clang/lib/CodeGen/CGExprCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,8 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(Address ThisAddr,
22922292
bool IsExact = !IsDynamicCastToVoid &&
22932293
CGM.getCodeGenOpts().OptimizationLevel > 0 &&
22942294
DestRecordTy->getAsCXXRecordDecl()->isEffectivelyFinal() &&
2295-
CGM.getCXXABI().shouldEmitExactDynamicCast(DestRecordTy);
2295+
CGM.getCXXABI().shouldEmitExactDynamicCast(DestRecordTy) &&
2296+
!getLangOpts().PointerAuthCalls;
22962297

22972298
// C++ [expr.dynamic.cast]p4:
22982299
// If the value of v is a null pointer value in the pointer case, the result

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,14 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
273273
emitBufferGlobalsAndMetadata(BufDecl, BufGV);
274274

275275
// Initialize cbuffer from binding (implicit or explicit)
276-
HLSLResourceBindingAttr *RBA = BufDecl->getAttr<HLSLResourceBindingAttr>();
277-
assert(RBA &&
278-
"cbuffer/tbuffer should always have resource binding attribute");
279-
initializeBufferFromBinding(BufDecl, BufGV, RBA);
276+
if (HLSLVkBindingAttr *VkBinding = BufDecl->getAttr<HLSLVkBindingAttr>()) {
277+
initializeBufferFromBinding(BufDecl, BufGV, VkBinding);
278+
} else {
279+
HLSLResourceBindingAttr *RBA = BufDecl->getAttr<HLSLResourceBindingAttr>();
280+
assert(RBA &&
281+
"cbuffer/tbuffer should always have resource binding attribute");
282+
initializeBufferFromBinding(BufDecl, BufGV, RBA);
283+
}
280284
}
281285

282286
llvm::TargetExtType *
@@ -593,6 +597,31 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
593597
CGM.AddCXXGlobalInit(InitResFunc);
594598
}
595599

600+
static Value *buildNameForResource(llvm::StringRef BaseName,
601+
CodeGenModule &CGM) {
602+
std::string Str(BaseName);
603+
std::string GlobalName(Str + ".str");
604+
return CGM.GetAddrOfConstantCString(Str, GlobalName.c_str()).getPointer();
605+
}
606+
607+
void CGHLSLRuntime::initializeBufferFromBinding(const HLSLBufferDecl *BufDecl,
608+
llvm::GlobalVariable *GV,
609+
HLSLVkBindingAttr *VkBinding) {
610+
assert(VkBinding && "expect a nonnull binding attribute");
611+
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGM.getLLVMContext());
612+
auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
613+
auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
614+
auto *RangeSize = llvm::ConstantInt::get(CGM.IntTy, 1);
615+
auto *Set = llvm::ConstantInt::get(CGM.IntTy, VkBinding->getSet());
616+
auto *Binding = llvm::ConstantInt::get(CGM.IntTy, VkBinding->getBinding());
617+
Value *Name = buildNameForResource(BufDecl->getName(), CGM);
618+
llvm::Intrinsic::ID IntrinsicID =
619+
CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic();
620+
621+
SmallVector<Value *> Args{Set, Binding, RangeSize, Index, NonUniform, Name};
622+
initializeBuffer(CGM, GV, IntrinsicID, Args);
623+
}
624+
596625
void CGHLSLRuntime::initializeBufferFromBinding(const HLSLBufferDecl *BufDecl,
597626
llvm::GlobalVariable *GV,
598627
HLSLResourceBindingAttr *RBA) {

0 commit comments

Comments
 (0)