Skip to content

Commit 4b88967

Browse files
authored
Merge branch 'main' into dev/dajusto/dont-asanize-catch-params-on-windows
2 parents 98217a4 + 024dd56 commit 4b88967

File tree

98 files changed

+55026
-27700
lines changed

Some content is hidden

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

98 files changed

+55026
-27700
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ Non-comprehensive list of changes in this release
271271
allocation functions with a token ID can be enabled via the
272272
``-fsanitize=alloc-token`` flag.
273273

274+
- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an explicit type in C. (#GH163090)
275+
274276
New Compiler Flags
275277
------------------
276278
- New option ``-fno-sanitize-debug-trap-reasons`` added to disable emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``).

clang/include/clang/Basic/Builtins.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4957,6 +4957,18 @@ def HLSLResourceNonUniformIndex : LangBuiltin<"HLSL_LANG"> {
49574957
let Prototype = "uint32_t(uint32_t)";
49584958
}
49594959

4960+
def HLSLResourceGetDimensionsX : LangBuiltin<"HLSL_LANG"> {
4961+
let Spellings = ["__builtin_hlsl_resource_getdimensions_x"];
4962+
let Attributes = [NoThrow];
4963+
let Prototype = "void(...)";
4964+
}
4965+
4966+
def HLSLResourceGetStride : LangBuiltin<"HLSL_LANG"> {
4967+
let Spellings = ["__builtin_hlsl_resource_getstride"];
4968+
let Attributes = [NoThrow];
4969+
let Prototype = "void(...)";
4970+
}
4971+
49604972
def HLSLAll : LangBuiltin<"HLSL_LANG"> {
49614973
let Spellings = ["__builtin_hlsl_all"];
49624974
let Attributes = [NoThrow, Const];

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,12 +4408,12 @@ def CIR_TryOp : CIR_Op<"try",[
44084408
let arguments = (ins
44094409
UnitAttr:$synthetic,
44104410
UnitAttr:$cleanup,
4411-
CIR_TryHandlerArrayAttr:$handler_types
4411+
DefaultValuedAttr<CIR_TryHandlerArrayAttr, "{}">:$handler_types
44124412
);
44134413

44144414
let regions = (region
44154415
AnyRegion:$try_region,
4416-
VariadicRegion<MinSizedRegion<1>>:$handler_regions
4416+
VariadicRegion<AnyRegion>:$handler_regions
44174417
);
44184418

44194419
let assemblyFormat = [{

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,14 +3285,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
32853285
case Builtin::BI__builtin_parityl:
32863286
case Builtin::BI__builtin_parityll:
32873287
return interp__builtin_elementwise_int_unaryop(
3288-
S, OpPC, Call, [](const APSInt &Val) -> APInt {
3288+
S, OpPC, Call, [](const APSInt &Val) {
32893289
return APInt(Val.getBitWidth(), Val.popcount() % 2);
32903290
});
32913291
case Builtin::BI__builtin_clrsb:
32923292
case Builtin::BI__builtin_clrsbl:
32933293
case Builtin::BI__builtin_clrsbll:
32943294
return interp__builtin_elementwise_int_unaryop(
3295-
S, OpPC, Call, [](const APSInt &Val) -> APInt {
3295+
S, OpPC, Call, [](const APSInt &Val) {
32963296
return APInt(Val.getBitWidth(),
32973297
Val.getBitWidth() - Val.getSignificantBits());
32983298
});
@@ -3301,8 +3301,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
33013301
case Builtin::BI__builtin_bitreverse32:
33023302
case Builtin::BI__builtin_bitreverse64:
33033303
return interp__builtin_elementwise_int_unaryop(
3304-
S, OpPC, Call,
3305-
[](const APSInt &Val) -> APInt { return Val.reverseBits(); });
3304+
S, OpPC, Call, [](const APSInt &Val) { return Val.reverseBits(); });
33063305

33073306
case Builtin::BI__builtin_classify_type:
33083307
return interp__builtin_classify_type(S, OpPC, Frame, Call);

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,7 @@ const char *vTableClassNameForType(const CIRGenModule &cgm, const Type *ty) {
950950
break;
951951

952952
case Type::Enum:
953-
cgm.errorNYI("VTableClassNameForType: Enum");
954-
break;
953+
return "_ZTVN10__cxxabiv116__enum_type_infoE";
955954

956955
case Type::Record: {
957956
const auto *rd = cast<CXXRecordDecl>(cast<RecordType>(ty)->getDecl())

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,8 +3011,11 @@ static mlir::ParseResult parseTryHandlerRegions(
30113011
return failure();
30123012
}
30133013

3014-
if (!currRegion.empty() && !(currRegion.back().mightHaveTerminator() &&
3015-
currRegion.back().getTerminator()))
3014+
if (currRegion.empty())
3015+
return parser.emitError(regionLoc, "handler region shall not be empty");
3016+
3017+
if (!(currRegion.back().mightHaveTerminator() &&
3018+
currRegion.back().getTerminator()))
30163019
return parser.emitError(
30173020
regionLoc, "blocks are expected to be explicitly terminated");
30183021

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ static Value *handleHlslSplitdouble(const CallExpr *E, CodeGenFunction *CGF) {
160160
return LastInst;
161161
}
162162

163+
static Value *emitBufferStride(CodeGenFunction *CGF, const Expr *HandleExpr,
164+
LValue &Stride) {
165+
// Figure out the stride of the buffer elements from the handle type.
166+
auto *HandleTy =
167+
cast<HLSLAttributedResourceType>(HandleExpr->getType().getTypePtr());
168+
QualType ElementTy = HandleTy->getContainedType();
169+
Value *StrideValue = CGF->getTypeSize(ElementTy);
170+
return CGF->Builder.CreateStore(StrideValue, Stride.getAddress());
171+
}
172+
163173
// Return dot product intrinsic that corresponds to the QT scalar type
164174
static Intrinsic::ID getDotProductIntrinsic(CGHLSLRuntime &RT, QualType QT) {
165175
if (QT->isFloatingType())
@@ -372,6 +382,19 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
372382
RetTy, CGM.getHLSLRuntime().getNonUniformResourceIndexIntrinsic(),
373383
ArrayRef<Value *>{IndexOp});
374384
}
385+
case Builtin::BI__builtin_hlsl_resource_getdimensions_x: {
386+
Value *Handle = EmitScalarExpr(E->getArg(0));
387+
LValue Dim = EmitLValue(E->getArg(1));
388+
llvm::Type *RetTy = llvm::Type::getInt32Ty(getLLVMContext());
389+
Value *DimValue = Builder.CreateIntrinsic(
390+
RetTy, CGM.getHLSLRuntime().getGetDimensionsXIntrinsic(),
391+
ArrayRef<Value *>{Handle});
392+
return Builder.CreateStore(DimValue, Dim.getAddress());
393+
}
394+
case Builtin::BI__builtin_hlsl_resource_getstride: {
395+
LValue Stride = EmitLValue(E->getArg(1));
396+
return emitBufferStride(this, E->getArg(0), Stride);
397+
}
375398
case Builtin::BI__builtin_hlsl_all: {
376399
Value *Op0 = EmitScalarExpr(E->getArg(0));
377400
return Builder.CreateIntrinsic(

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class CGHLSLRuntime {
135135
GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, resource_updatecounter)
136136
GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync,
137137
group_memory_barrier_with_group_sync)
138+
GENERATE_HLSL_INTRINSIC_FUNCTION(GetDimensionsX, resource_getdimensions_x)
138139

139140
//===----------------------------------------------------------------------===//
140141
// End of reserved area for HLSL intrinsic getters.

clang/lib/Sema/DeclSpec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,8 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
13691369

13701370
if (S.getLangOpts().C23 &&
13711371
getConstexprSpecifier() == ConstexprSpecKind::Constexpr &&
1372-
StorageClassSpec == SCS_extern) {
1372+
getTypeSpecType() != TST_unspecified &&
1373+
(StorageClassSpec == SCS_extern || StorageClassSpec == SCS_auto)) {
13731374
S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
13741375
<< DeclSpec::getSpecifierName(getStorageClassSpec())
13751376
<< SourceRange(getStorageClassSpecLoc());

clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ CXXConstructorDecl *lookupCopyConstructor(QualType ResTy) {
5757
return CD;
5858
return nullptr;
5959
}
60+
61+
ParameterABI
62+
convertParamModifierToParamABI(HLSLParamModifierAttr::Spelling Modifier) {
63+
assert(Modifier != HLSLParamModifierAttr::Spelling::Keyword_in &&
64+
"HLSL 'in' parameters modifier cannot be converted to ParameterABI");
65+
switch (Modifier) {
66+
case HLSLParamModifierAttr::Spelling::Keyword_out:
67+
return ParameterABI::HLSLOut;
68+
case HLSLParamModifierAttr::Spelling::Keyword_inout:
69+
return ParameterABI::HLSLInOut;
70+
default:
71+
llvm_unreachable("Invalid HLSL parameter modifier");
72+
}
73+
}
74+
75+
QualType getInoutParameterType(ASTContext &AST, QualType Ty) {
76+
assert(!Ty->isReferenceType() &&
77+
"Pointer and reference types cannot be inout or out parameters");
78+
Ty = AST.getLValueReferenceType(Ty);
79+
Ty.addRestrict();
80+
return Ty;
81+
}
82+
6083
} // namespace
6184

6285
// Builder for template arguments of builtin types. Used internally
@@ -430,19 +453,36 @@ BuiltinTypeMethodBuilder::addParam(StringRef Name, QualType Ty,
430453
void BuiltinTypeMethodBuilder::createDecl() {
431454
assert(Method == nullptr && "Method or constructor is already created");
432455

433-
// create method or constructor type
456+
// create function prototype
434457
ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
435458
SmallVector<QualType> ParamTypes;
436-
for (Param &MP : Params)
459+
SmallVector<FunctionType::ExtParameterInfo> ParamExtInfos(Params.size());
460+
uint32_t ArgIndex = 0;
461+
462+
// Create function prototype.
463+
bool UseParamExtInfo = false;
464+
for (Param &MP : Params) {
465+
if (MP.Modifier != HLSLParamModifierAttr::Keyword_in) {
466+
UseParamExtInfo = true;
467+
FunctionType::ExtParameterInfo &PI = ParamExtInfos[ArgIndex];
468+
ParamExtInfos[ArgIndex] =
469+
PI.withABI(convertParamModifierToParamABI(MP.Modifier));
470+
if (!MP.Ty->isDependentType())
471+
MP.Ty = getInoutParameterType(AST, MP.Ty);
472+
}
437473
ParamTypes.emplace_back(MP.Ty);
474+
++ArgIndex;
475+
}
438476

439477
FunctionProtoType::ExtProtoInfo ExtInfo;
478+
if (UseParamExtInfo)
479+
ExtInfo.ExtParameterInfos = ParamExtInfos.data();
440480
if (IsConst)
441481
ExtInfo.TypeQuals.addConst();
442482

443483
QualType FuncTy = AST.getFunctionType(ReturnTy, ParamTypes, ExtInfo);
444484

445-
// create method or constructor decl
485+
// Create method or constructor declaration.
446486
auto *TSInfo = AST.getTrivialTypeSourceInfo(FuncTy, SourceLocation());
447487
DeclarationNameInfo NameInfo = DeclarationNameInfo(Name, SourceLocation());
448488
if (IsCtor)
@@ -455,7 +495,7 @@ void BuiltinTypeMethodBuilder::createDecl() {
455495
AST, DeclBuilder.Record, SourceLocation(), NameInfo, FuncTy, TSInfo, SC,
456496
false, false, ConstexprSpecKind::Unspecified, SourceLocation());
457497

458-
// create params & set them to the function prototype
498+
// Create params & set them to the method/constructor and function prototype.
459499
SmallVector<ParmVarDecl *> ParmDecls;
460500
unsigned CurScopeDepth = DeclBuilder.SemaRef.getCurScope()->getDepth();
461501
auto FnProtoLoc =
@@ -1258,5 +1298,37 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addConsumeMethod() {
12581298
.finalize();
12591299
}
12601300

1301+
BuiltinTypeDeclBuilder &
1302+
BuiltinTypeDeclBuilder::addGetDimensionsMethodForBuffer() {
1303+
using PH = BuiltinTypeMethodBuilder::PlaceHolder;
1304+
ASTContext &AST = SemaRef.getASTContext();
1305+
QualType UIntTy = AST.UnsignedIntTy;
1306+
1307+
QualType HandleTy = getResourceHandleField()->getType();
1308+
auto *AttrResTy = cast<HLSLAttributedResourceType>(HandleTy.getTypePtr());
1309+
1310+
// Structured buffers except {RW}ByteAddressBuffer have overload
1311+
// GetDimensions(out uint numStructs, out uint stride).
1312+
if (AttrResTy->getAttrs().RawBuffer &&
1313+
AttrResTy->getContainedType() != AST.Char8Ty) {
1314+
return BuiltinTypeMethodBuilder(*this, "GetDimensions", AST.VoidTy)
1315+
.addParam("numStructs", UIntTy, HLSLParamModifierAttr::Keyword_out)
1316+
.addParam("stride", UIntTy, HLSLParamModifierAttr::Keyword_out)
1317+
.callBuiltin("__builtin_hlsl_resource_getdimensions_x", QualType(),
1318+
PH::Handle, PH::_0)
1319+
.callBuiltin("__builtin_hlsl_resource_getstride", QualType(),
1320+
PH::Handle, PH::_1)
1321+
.finalize();
1322+
}
1323+
1324+
// Typed buffers and {RW}ByteAddressBuffer have overload
1325+
// GetDimensions(out uint dim).
1326+
return BuiltinTypeMethodBuilder(*this, "GetDimensions", AST.VoidTy)
1327+
.addParam("dim", UIntTy, HLSLParamModifierAttr::Keyword_out)
1328+
.callBuiltin("__builtin_hlsl_resource_getdimensions_x", QualType(),
1329+
PH::Handle, PH::_0)
1330+
.finalize();
1331+
}
1332+
12611333
} // namespace hlsl
12621334
} // namespace clang

0 commit comments

Comments
 (0)