Skip to content

Commit 4cace7e

Browse files
authored
merge main into amd-staging (llvm#4135)
2 parents d14a2ca + 0c0640f commit 4cace7e

File tree

192 files changed

+6989
-2827
lines changed

Some content is hidden

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

192 files changed

+6989
-2827
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ Improvements to Clang's diagnostics
519519
Moved the warning for a missing (though implied) attribute on a redeclaration into this group.
520520
Added a new warning in this group for the case where the attribute is missing/implicit on
521521
an override of a virtual method.
522+
- Implemented diagnostics when retrieving the tuple size for types where its specialization of `std::tuple_size`
523+
produces an invalid size (either negative or greater than the implementation limit). (#GH159563)
522524
- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right
523525
parenthesis when diagnosing malformed fold expressions. (#GH151787)
524526
- Added fix-it hint for when scoped enumerations require explicit conversions for binary operations. (#GH24265)
@@ -604,8 +606,8 @@ Bug Fixes in This Version
604606
and vector of 4 ``float`` values. (#GH155405)
605607
- Fixed inconsistent shadow warnings for lambda capture of structured bindings.
606608
Previously, ``[val = val]`` (regular parameter) produced no warnings with ``-Wshadow``
607-
while ``[a = a]`` (where ``a`` is from ``auto [a, b] = std::make_pair(1, 2)``)
608-
incorrectly produced warnings. Both cases now consistently show no warnings with
609+
while ``[a = a]`` (where ``a`` is from ``auto [a, b] = std::make_pair(1, 2)``)
610+
incorrectly produced warnings. Both cases now consistently show no warnings with
609611
``-Wshadow`` and show uncaptured-local warnings with ``-Wshadow-all``. (#GH68605)
610612
- Fixed a failed assertion with a negative limit parameter value inside of
611613
``__has_embed``. (#GH157842)

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ def err_decomp_decl_std_tuple_element_not_specialized : Error<
638638
def err_decomp_decl_std_tuple_size_not_constant : Error<
639639
"cannot decompose this type; 'std::tuple_size<%0>::value' "
640640
"is not a valid integral constant expression">;
641+
def err_decomp_decl_std_tuple_size_invalid
642+
: Error<"cannot decompose this type; 'std::tuple_size<%0>::value' "
643+
"is not a valid size: %1">;
641644
def note_in_binding_decl_init : Note<
642645
"in implicit initialization of binding declaration %0">;
643646
def err_arg_is_not_destructurable : Error<

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,6 +4131,45 @@ def CIR_ThrowOp : CIR_Op<"throw"> {
41314131
// Atomic operations
41324132
//===----------------------------------------------------------------------===//
41334133

4134+
def CIR_AtomicXchg : CIR_Op<"atomic.xchg", [
4135+
AllTypesMatch<["result", "val"]>,
4136+
TypesMatchWith<"type of 'val' must match the pointee type of 'ptr'",
4137+
"ptr", "val", "mlir::cast<cir::PointerType>($_self).getPointee()">
4138+
]> {
4139+
let summary = "Atomic exchange";
4140+
let description = [{
4141+
C/C++ atomic exchange operation. This operation implements the C/C++
4142+
builtin function `__atomic_exchange`, `__atomic_exchange_n`, and
4143+
`__c11_atomic_exchange`.
4144+
4145+
This operation takes two arguments: a pointer `ptr` and a value `val`. The
4146+
operation atomically replaces the value of the object pointed-to by `ptr`
4147+
with `val`, and returns the original value of the object.
4148+
4149+
Example:
4150+
4151+
```mlir
4152+
%res = cir.atomic.xchg(%ptr : !cir.ptr<!u64i>,
4153+
%val : !u64i,
4154+
seq_cst) : !u64i
4155+
```
4156+
}];
4157+
4158+
let results = (outs CIR_AnyType:$result);
4159+
let arguments = (ins
4160+
Arg<CIR_PointerType, "", [MemRead, MemWrite]>:$ptr,
4161+
CIR_AnyType:$val,
4162+
Arg<CIR_MemOrder, "memory order">:$mem_order,
4163+
UnitAttr:$is_volatile
4164+
);
4165+
4166+
let assemblyFormat = [{
4167+
$mem_order (`volatile` $is_volatile^)?
4168+
$ptr `,` $val
4169+
`:` qualified(type($ptr)) `->` type($result) attr-dict
4170+
}];
4171+
}
4172+
41344173
def CIR_AtomicCmpXchg : CIR_Op<"atomic.cmpxchg", [
41354174
AllTypesMatch<["old", "expected", "desired"]>
41364175
]> {

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,9 @@ ASTContext::findPointerAuthContent(QualType T) const {
17121712
assert(isPointerAuthenticationAvailable());
17131713

17141714
T = T.getCanonicalType();
1715+
if (T->isDependentType())
1716+
return PointerAuthContent::None;
1717+
17151718
if (T.hasAddressDiscriminatedPointerAuth())
17161719
return PointerAuthContent::AddressDiscriminatedData;
17171720
const RecordDecl *RD = T->getAsRecordDecl();

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest,
341341
}
342342

343343
assert(!cir::MissingFeatures::atomicSyncScopeID());
344+
llvm::StringRef opName;
344345

345346
CIRGenBuilderTy &builder = cgf.getBuilder();
346347
mlir::Location loc = cgf.getLoc(expr->getSourceRange());
@@ -400,6 +401,12 @@ static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest,
400401
return;
401402
}
402403

404+
case AtomicExpr::AO__c11_atomic_exchange:
405+
case AtomicExpr::AO__atomic_exchange_n:
406+
case AtomicExpr::AO__atomic_exchange:
407+
opName = cir::AtomicXchg::getOperationName();
408+
break;
409+
403410
case AtomicExpr::AO__opencl_atomic_init:
404411

405412
case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
@@ -421,11 +428,8 @@ static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest,
421428
case AtomicExpr::AO__scoped_atomic_store:
422429
case AtomicExpr::AO__scoped_atomic_store_n:
423430

424-
case AtomicExpr::AO__c11_atomic_exchange:
425431
case AtomicExpr::AO__hip_atomic_exchange:
426432
case AtomicExpr::AO__opencl_atomic_exchange:
427-
case AtomicExpr::AO__atomic_exchange_n:
428-
case AtomicExpr::AO__atomic_exchange:
429433
case AtomicExpr::AO__scoped_atomic_exchange_n:
430434
case AtomicExpr::AO__scoped_atomic_exchange:
431435

@@ -503,8 +507,23 @@ static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest,
503507

504508
case AtomicExpr::AO__atomic_clear:
505509
cgf.cgm.errorNYI(expr->getSourceRange(), "emitAtomicOp: expr op NYI");
506-
break;
510+
return;
507511
}
512+
513+
assert(!opName.empty() && "expected operation name to build");
514+
mlir::Value loadVal1 = builder.createLoad(loc, val1);
515+
516+
SmallVector<mlir::Value> atomicOperands = {ptr.getPointer(), loadVal1};
517+
SmallVector<mlir::Type> atomicResTys = {loadVal1.getType()};
518+
mlir::Operation *rmwOp = builder.create(loc, builder.getStringAttr(opName),
519+
atomicOperands, atomicResTys);
520+
521+
rmwOp->setAttr("mem_order", orderAttr);
522+
if (expr->isVolatile())
523+
rmwOp->setAttr("is_volatile", builder.getUnitAttr());
524+
525+
mlir::Value result = rmwOp->getResult(0);
526+
builder.createStore(loc, result, dest);
508527
}
509528

510529
static bool isMemOrderValid(uint64_t order, bool isStore, bool isLoad) {
@@ -572,6 +591,11 @@ RValue CIRGenFunction::emitAtomicExpr(AtomicExpr *e) {
572591
val1 = emitPointerWithAlignment(e->getVal1());
573592
break;
574593

594+
case AtomicExpr::AO__atomic_exchange:
595+
val1 = emitPointerWithAlignment(e->getVal1());
596+
dest = emitPointerWithAlignment(e->getVal2());
597+
break;
598+
575599
case AtomicExpr::AO__atomic_compare_exchange:
576600
case AtomicExpr::AO__atomic_compare_exchange_n:
577601
case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
@@ -590,7 +614,9 @@ RValue CIRGenFunction::emitAtomicExpr(AtomicExpr *e) {
590614
isWeakExpr = e->getWeak();
591615
break;
592616

617+
case AtomicExpr::AO__atomic_exchange_n:
593618
case AtomicExpr::AO__atomic_store_n:
619+
case AtomicExpr::AO__c11_atomic_exchange:
594620
case AtomicExpr::AO__c11_atomic_store:
595621
val1 = emitValToTemp(*this, e->getVal1());
596622
break;

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,22 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
639639
// are probably legitimate places where we could assume that this
640640
// doesn't happen, but it's not clear that it's worth it.
641641

642+
auto arrayTy = mlir::cast<cir::ArrayType>(arrayBase.getElementType());
643+
mlir::Type elementType = arrayTy.getElementType();
644+
645+
// This might be a multi-dimensional array. Find the innermost element type.
646+
while (auto maybeArrayTy = mlir::dyn_cast<cir::ArrayType>(elementType))
647+
elementType = maybeArrayTy.getElementType();
648+
cir::PointerType ptrToElmType = builder.getPointerTo(elementType);
649+
642650
// Optimize for a constant count.
643651
if (auto constantCount = numElements.getDefiningOp<cir::ConstantOp>()) {
644652
if (auto constIntAttr = constantCount.getValueAttr<cir::IntAttr>()) {
645653
// Just skip out if the constant count is zero.
646654
if (constIntAttr.getUInt() == 0)
647655
return;
656+
657+
arrayTy = cir::ArrayType::get(elementType, constIntAttr.getUInt());
648658
// Otherwise, emit the check.
649659
}
650660

@@ -655,10 +665,6 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
655665
cgm.errorNYI(e->getSourceRange(), "dynamic-length array expression");
656666
}
657667

658-
auto arrayTy = mlir::cast<cir::ArrayType>(arrayBase.getElementType());
659-
mlir::Type elementType = arrayTy.getElementType();
660-
cir::PointerType ptrToElmType = builder.getPointerTo(elementType);
661-
662668
// Tradional LLVM codegen emits a loop here. CIR lowers to a loop as part of
663669
// LoweringPrepare.
664670

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ void CIRGenFunction::emitDecl(const Decl &d, bool evaluateConditionDecl) {
618618
case Decl::MSGuid: // __declspec(uuid("..."))
619619
case Decl::TemplateParamObject:
620620
case Decl::OMPThreadPrivate:
621+
case Decl::OMPGroupPrivate:
621622
case Decl::OMPAllocate:
622623
case Decl::OMPCapturedExpr:
623624
case Decl::OMPRequires:
@@ -667,7 +668,6 @@ void CIRGenFunction::emitDecl(const Decl &d, bool evaluateConditionDecl) {
667668
case Decl::UsingPack:
668669
case Decl::OMPDeclareMapper:
669670
case Decl::OMPDeclareReduction:
670-
case Decl::OMPGroupPrivate:
671671
cgm.errorNYI(d.getSourceRange(),
672672
std::string("emitDecl: unhandled decl type: ") +
673673
d.getDeclKindName());
@@ -713,10 +713,11 @@ void CIRGenFunction::pushDestroy(CleanupKind cleanupKind, Address addr,
713713
/// The array cannot be zero-length.
714714
///
715715
/// \param begin - a type* denoting the first element of the array
716-
/// \param end - a type* denoting one past the end of the array
716+
/// \param numElements - the number of elements in the array
717717
/// \param elementType - the element type of the array
718718
/// \param destroyer - the function to call to destroy elements
719-
void CIRGenFunction::emitArrayDestroy(mlir::Value begin, mlir::Value end,
719+
void CIRGenFunction::emitArrayDestroy(mlir::Value begin,
720+
mlir::Value numElements,
720721
QualType elementType,
721722
CharUnits elementAlign,
722723
Destroyer *destroyer) {
@@ -727,9 +728,24 @@ void CIRGenFunction::emitArrayDestroy(mlir::Value begin, mlir::Value end,
727728
mlir::Type cirElementType = convertTypeForMem(elementType);
728729
cir::PointerType ptrToElmType = builder.getPointerTo(cirElementType);
729730

731+
uint64_t size = 0;
732+
733+
// Optimize for a constant array size.
734+
if (auto constantCount = numElements.getDefiningOp<cir::ConstantOp>()) {
735+
if (auto constIntAttr = constantCount.getValueAttr<cir::IntAttr>())
736+
size = constIntAttr.getUInt();
737+
} else {
738+
cgm.errorNYI(begin.getDefiningOp()->getLoc(),
739+
"dynamic-length array expression");
740+
}
741+
742+
auto arrayTy = cir::ArrayType::get(cirElementType, size);
743+
mlir::Value arrayOp = builder.createPtrBitcast(begin, arrayTy);
744+
730745
// Emit the dtor call that will execute for every array element.
731746
cir::ArrayDtor::create(
732-
builder, *currSrcLoc, begin, [&](mlir::OpBuilder &b, mlir::Location loc) {
747+
builder, *currSrcLoc, arrayOp,
748+
[&](mlir::OpBuilder &b, mlir::Location loc) {
733749
auto arg = b.getInsertionBlock()->addArgument(ptrToElmType, loc);
734750
Address curAddr = Address(arg, cirElementType, elementAlign);
735751
assert(!cir::MissingFeatures::dtorCleanups());
@@ -772,8 +788,7 @@ void CIRGenFunction::emitDestroy(Address addr, QualType type,
772788
return;
773789

774790
mlir::Value begin = addr.getPointer();
775-
mlir::Value end; // This will be used for future non-constant counts.
776-
emitArrayDestroy(begin, end, type, elementAlign, destroyer);
791+
emitArrayDestroy(begin, length, type, elementAlign, destroyer);
777792

778793
// If the array destroy didn't use the length op, we can erase it.
779794
if (constantCount.use_empty())

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,9 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
878878
}
879879

880880
if (ty.UseExcessPrecision(cgf.getContext())) {
881-
if (ty->getAs<VectorType>()) {
882-
assert(!cir::MissingFeatures::vectorType());
883-
cgf.cgm.errorNYI("getPromotionType: promotion to vector type");
884-
return QualType();
881+
if (auto *vt = ty->getAs<VectorType>()) {
882+
unsigned numElements = vt->getNumElements();
883+
return ctx.getVectorType(ctx.FloatTy, numElements, vt->getVectorKind());
885884
}
886885
return cgf.getContext().FloatTy;
887886
}
@@ -1063,8 +1062,20 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
10631062

10641063
mlir::Value VisitBinLAnd(const clang::BinaryOperator *e) {
10651064
if (e->getType()->isVectorType()) {
1066-
assert(!cir::MissingFeatures::vectorType());
1067-
return {};
1065+
mlir::Location loc = cgf.getLoc(e->getExprLoc());
1066+
auto vecTy = mlir::cast<cir::VectorType>(cgf.convertType(e->getType()));
1067+
mlir::Value zeroValue = builder.getNullValue(vecTy.getElementType(), loc);
1068+
SmallVector<mlir::Value, 16> elements(vecTy.getSize(), zeroValue);
1069+
auto zeroVec = cir::VecCreateOp::create(builder, loc, vecTy, elements);
1070+
1071+
mlir::Value lhs = Visit(e->getLHS());
1072+
mlir::Value rhs = Visit(e->getRHS());
1073+
1074+
auto cmpOpKind = cir::CmpOpKind::ne;
1075+
lhs = cir::VecCmpOp::create(builder, loc, vecTy, cmpOpKind, lhs, zeroVec);
1076+
rhs = cir::VecCmpOp::create(builder, loc, vecTy, cmpOpKind, rhs, zeroVec);
1077+
mlir::Value vecOr = builder.createAnd(loc, lhs, rhs);
1078+
return builder.createIntCast(vecOr, vecTy);
10681079
}
10691080

10701081
assert(!cir::MissingFeatures::instrumentation());
@@ -2344,4 +2355,4 @@ mlir::Value CIRGenFunction::emitScalarPrePostIncDec(const UnaryOperator *e,
23442355
bool isPre) {
23452356
return ScalarExprEmitter(*this, builder)
23462357
.emitScalarPrePostIncDec(e, lv, kind, isPre);
2347-
}
2358+
}

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ class CIRGenFunction : public CIRGenTypeCache {
10641064
/// even if no aggregate location is provided.
10651065
RValue emitAnyExprToTemp(const clang::Expr *e);
10661066

1067-
void emitArrayDestroy(mlir::Value begin, mlir::Value end,
1067+
void emitArrayDestroy(mlir::Value begin, mlir::Value numElements,
10681068
QualType elementType, CharUnits elementAlign,
10691069
Destroyer *destroyer);
10701070

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,17 @@ mlir::LogicalResult CIRToLLVMAtomicCmpXchgLowering::matchAndRewrite(
717717
return mlir::success();
718718
}
719719

720+
mlir::LogicalResult CIRToLLVMAtomicXchgLowering::matchAndRewrite(
721+
cir::AtomicXchg op, OpAdaptor adaptor,
722+
mlir::ConversionPatternRewriter &rewriter) const {
723+
assert(!cir::MissingFeatures::atomicSyncScopeID());
724+
mlir::LLVM::AtomicOrdering llvmOrder = getLLVMMemOrder(adaptor.getMemOrder());
725+
rewriter.replaceOpWithNewOp<mlir::LLVM::AtomicRMWOp>(
726+
op, mlir::LLVM::AtomicBinOp::xchg, adaptor.getPtr(), adaptor.getVal(),
727+
llvmOrder);
728+
return mlir::success();
729+
}
730+
720731
mlir::LogicalResult CIRToLLVMBitClrsbOpLowering::matchAndRewrite(
721732
cir::BitClrsbOp op, OpAdaptor adaptor,
722733
mlir::ConversionPatternRewriter &rewriter) const {

0 commit comments

Comments
 (0)