diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 50 | ||||
-rw-r--r-- | clang/lib/Sema/SemaHLSL.cpp | 31 |
2 files changed, 44 insertions, 37 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index a8dfa4d..328ccf6 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6361,19 +6361,8 @@ static void handleNoSanitizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { Sanitizers.size())); } -static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D, - const ParsedAttr &AL) { - StringRef AttrName = AL.getAttrName()->getName(); - normalizeName(AttrName); - StringRef SanitizerName = llvm::StringSwitch<StringRef>(AttrName) - .Case("no_address_safety_analysis", "address") - .Case("no_sanitize_address", "address") - .Case("no_sanitize_thread", "thread") - .Case("no_sanitize_memory", "memory"); - if (isGlobalVar(D) && SanitizerName != "address") - S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) - << AL << AL.isRegularKeywordAttribute() << ExpectedFunction; - +static AttributeCommonInfo +getNoSanitizeAttrInfo(const ParsedAttr &NoSanitizeSpecificAttr) { // FIXME: Rather than create a NoSanitizeSpecificAttr, this creates a // NoSanitizeAttr object; but we need to calculate the correct spelling list // index rather than incorrectly assume the index for NoSanitizeSpecificAttr @@ -6383,11 +6372,32 @@ static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D, // getSpelling() or prettyPrint() on the resulting semantic attribute object // without failing assertions. unsigned TranslatedSpellingIndex = 0; - if (AL.isStandardAttributeSyntax()) + if (NoSanitizeSpecificAttr.isStandardAttributeSyntax()) TranslatedSpellingIndex = 1; - AttributeCommonInfo Info = AL; + AttributeCommonInfo Info = NoSanitizeSpecificAttr; Info.setAttributeSpellingListIndex(TranslatedSpellingIndex); + return Info; +} + +static void handleNoSanitizeAddressAttr(Sema &S, Decl *D, + const ParsedAttr &AL) { + StringRef SanitizerName = "address"; + AttributeCommonInfo Info = getNoSanitizeAttrInfo(AL); + D->addAttr(::new (S.Context) + NoSanitizeAttr(S.Context, Info, &SanitizerName, 1)); +} + +static void handleNoSanitizeThreadAttr(Sema &S, Decl *D, const ParsedAttr &AL) { + StringRef SanitizerName = "thread"; + AttributeCommonInfo Info = getNoSanitizeAttrInfo(AL); + D->addAttr(::new (S.Context) + NoSanitizeAttr(S.Context, Info, &SanitizerName, 1)); +} + +static void handleNoSanitizeMemoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) { + StringRef SanitizerName = "memory"; + AttributeCommonInfo Info = getNoSanitizeAttrInfo(AL); D->addAttr(::new (S.Context) NoSanitizeAttr(S.Context, Info, &SanitizerName, 1)); } @@ -7513,8 +7523,14 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_NoSanitize: handleNoSanitizeAttr(S, D, AL); break; - case ParsedAttr::AT_NoSanitizeSpecific: - handleNoSanitizeSpecificAttr(S, D, AL); + case ParsedAttr::AT_NoSanitizeAddress: + handleNoSanitizeAddressAttr(S, D, AL); + break; + case ParsedAttr::AT_NoSanitizeThread: + handleNoSanitizeThreadAttr(S, D, AL); + break; + case ParsedAttr::AT_NoSanitizeMemory: + handleNoSanitizeMemoryAttr(S, D, AL); break; case ParsedAttr::AT_GuardedBy: handleGuardedByAttr(S, D, AL); diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 940d510..129b03c 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -19,6 +19,7 @@ #include "clang/AST/DeclarationName.h" #include "clang/AST/DynamicRecursiveASTVisitor.h" #include "clang/AST/Expr.h" +#include "clang/AST/HLSLResource.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" #include "clang/Basic/Builtins.h" @@ -52,6 +53,7 @@ #include <utility> using namespace clang; +using namespace clang::hlsl; using RegisterType = HLSLResourceBindingAttr::RegisterType; static CXXRecordDecl *createHostLayoutStruct(Sema &S, @@ -3799,19 +3801,8 @@ bool SemaHLSL::initGlobalResourceDecl(VarDecl *VD) { uint64_t UIntTySize = AST.getTypeSize(AST.UnsignedIntTy); uint64_t IntTySize = AST.getTypeSize(AST.IntTy); - // Gather resource binding information from attributes. - HLSLResourceBindingAttr *RBA = VD->getAttr<HLSLResourceBindingAttr>(); - HLSLVkBindingAttr *VkBinding = VD->getAttr<HLSLVkBindingAttr>(); - std::optional<uint32_t> RegisterSlot; - uint32_t SpaceNo = 0; - if (VkBinding) { - RegisterSlot = VkBinding->getBinding(); - SpaceNo = VkBinding->getSet(); - } else if (RBA) { - if (RBA->hasRegisterSlot()) - RegisterSlot = RBA->getSlotNumber(); - SpaceNo = RBA->getSpaceNumber(); - } + // Gather resource binding attributes. + ResourceBindingAttrs Binding(VD); // Find correct initialization method and create its arguments. QualType ResourceTy = VD->getType(); @@ -3819,21 +3810,21 @@ bool SemaHLSL::initGlobalResourceDecl(VarDecl *VD) { CXXMethodDecl *CreateMethod = nullptr; llvm::SmallVector<Expr *> Args; - if (RegisterSlot.has_value()) { + if (Binding.isExplicit()) { // The resource has explicit binding. CreateMethod = lookupMethod(SemaRef, ResourceDecl, "__createFromBinding", VD->getLocation()); - IntegerLiteral *RegSlot = IntegerLiteral::Create( - AST, llvm::APInt(UIntTySize, RegisterSlot.value()), AST.UnsignedIntTy, - SourceLocation()); + IntegerLiteral *RegSlot = + IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, Binding.getSlot()), + AST.UnsignedIntTy, SourceLocation()); Args.push_back(RegSlot); } else { // The resource has implicit binding. CreateMethod = lookupMethod(SemaRef, ResourceDecl, "__createFromImplicitBinding", VD->getLocation()); - uint32_t OrderID = (RBA && RBA->hasImplicitBindingOrderID()) - ? RBA->getImplicitBindingOrderID() + uint32_t OrderID = (Binding.hasImplicitOrderID()) + ? Binding.getImplicitOrderID() : getNextImplicitBindingOrderID(); IntegerLiteral *OrderId = IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, OrderID), @@ -3848,7 +3839,7 @@ bool SemaHLSL::initGlobalResourceDecl(VarDecl *VD) { return false; IntegerLiteral *Space = - IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, SpaceNo), + IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, Binding.getSpace()), AST.UnsignedIntTy, SourceLocation()); Args.push_back(Space); |