aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp3
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp50
-rw-r--r--clang/lib/Sema/SemaExpr.cpp5
-rw-r--r--clang/lib/Sema/SemaHLSL.cpp31
-rw-r--r--clang/lib/Sema/SemaTypeTraits.cpp16
5 files changed, 55 insertions, 50 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9ef7a26..0069b08 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18909,8 +18909,7 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
// 'bool'.
if (BitfieldIsOverwide && !FieldTy->isBooleanType() && FieldName) {
Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
- << FieldName << toString(Value, 10)
- << (unsigned)TypeWidth;
+ << FieldName << Value << (unsigned)TypeWidth;
}
}
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/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3302bfc..06b2529 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16791,12 +16791,11 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
Expr *OrigExpr = E;
bool IsMS = false;
- // CUDA device code does not support varargs.
+ // CUDA device global function does not support varargs.
if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) {
if (const FunctionDecl *F = dyn_cast<FunctionDecl>(CurContext)) {
CUDAFunctionTarget T = CUDA().IdentifyTarget(F);
- if (T == CUDAFunctionTarget::Global || T == CUDAFunctionTarget::Device ||
- T == CUDAFunctionTarget::HostDevice)
+ if (T == CUDAFunctionTarget::Global)
return ExprError(Diag(E->getBeginLoc(), diag::err_va_arg_in_device));
}
}
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);
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp
index 6c798d6..3e34675 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -1830,10 +1830,10 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT,
return Self.HLSL().IsScalarizedLayoutCompatible(LhsT, RhsT);
}
- case BTT_LtSynthesisesFromSpaceship:
- case BTT_LeSynthesisesFromSpaceship:
- case BTT_GtSynthesisesFromSpaceship:
- case BTT_GeSynthesisesFromSpaceship: {
+ case BTT_LtSynthesizesFromSpaceship:
+ case BTT_LeSynthesizesFromSpaceship:
+ case BTT_GtSynthesizesFromSpaceship:
+ case BTT_GeSynthesizesFromSpaceship: {
EnterExpressionEvaluationContext UnevaluatedContext(
Self, Sema::ExpressionEvaluationContext::Unevaluated);
Sema::SFINAETrap SFINAE(Self, /*ForValidityCheck=*/true);
@@ -1852,13 +1852,13 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT,
auto OpKind = [&] {
switch (BTT) {
- case BTT_LtSynthesisesFromSpaceship:
+ case BTT_LtSynthesizesFromSpaceship:
return BinaryOperatorKind::BO_LT;
- case BTT_LeSynthesisesFromSpaceship:
+ case BTT_LeSynthesizesFromSpaceship:
return BinaryOperatorKind::BO_LE;
- case BTT_GtSynthesisesFromSpaceship:
+ case BTT_GtSynthesizesFromSpaceship:
return BinaryOperatorKind::BO_GT;
- case BTT_GeSynthesisesFromSpaceship:
+ case BTT_GeSynthesizesFromSpaceship:
return BinaryOperatorKind::BO_GE;
default:
llvm_unreachable("Trying to Synthesize non-comparison operator?");