Skip to content

Commit 051ade3

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3518)
2 parents 5eb48c6 + 676d053 commit 051ade3

File tree

33 files changed

+962
-95
lines changed

33 files changed

+962
-95
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ Bug Fixes to C++ Support
430430
(``[[assume(expr)]]``) creates temporary objects.
431431
- Fix the dynamic_cast to final class optimization to correctly handle
432432
casts that are guaranteed to fail (#GH137518).
433+
- Fix bug rejecting partial specialization of variable templates with auto NTTPs (#GH118190).
433434

434435
Bug Fixes to AST Handling
435436
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static MemberCallInfo commonBuildCXXMemberOrOperatorCall(
7575

7676
RValue CIRGenFunction::emitCXXMemberOrOperatorMemberCallExpr(
7777
const CallExpr *ce, const CXXMethodDecl *md, ReturnValueSlot returnValue,
78-
bool hasQualifier, NestedNameSpecifier *qualifier, bool isArrow,
78+
bool hasQualifier, NestedNameSpecifier qualifier, bool isArrow,
7979
const Expr *base) {
8080
assert(isa<CXXMemberCallExpr>(ce) || isa<CXXOperatorCallExpr>(ce));
8181

@@ -169,7 +169,7 @@ CIRGenFunction::emitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *e,
169169
assert(md->isInstance() &&
170170
"Trying to emit a member call expr on a static method!");
171171
return emitCXXMemberOrOperatorMemberCallExpr(
172-
e, md, returnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
172+
e, md, returnValue, /*HasQualifier=*/false, /*Qualifier=*/std::nullopt,
173173
/*IsArrow=*/false, e->getArg(0));
174174
}
175175

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ CIRGenTypes::arrangeCXXStructorDeclaration(GlobalDecl gd) {
203203
/// when calling a method pointer.
204204
CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd,
205205
const CXXMethodDecl *md) {
206-
QualType recTy;
206+
CanQualType recTy;
207207
if (rd) {
208-
recTy = getASTContext().getTagDeclType(rd)->getCanonicalTypeInternal();
208+
recTy = getASTContext().getCanonicalTagType(rd);
209209
} else {
210210
// This can happen with the MS ABI. It shouldn't need anything more than
211211
// setting recTy to VoidTy here, but we're flagging it for now because we
@@ -215,9 +215,9 @@ CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd,
215215
}
216216

217217
if (md)
218-
recTy = getASTContext().getAddrSpaceQualType(
219-
recTy, md->getMethodQualifiers().getAddressSpace());
220-
return getASTContext().getPointerType(CanQualType::CreateUnsafe(recTy));
218+
recTy = CanQualType::CreateUnsafe(getASTContext().getAddrSpaceQualType(
219+
recTy, md->getMethodQualifiers().getAddressSpace()));
220+
return getASTContext().getPointerType(recTy);
221221
}
222222

223223
/// Arrange the CIR function layout for a value of the given function type, on
@@ -267,7 +267,10 @@ void CIRGenFunction::emitDelegateCallArg(CallArgList &args,
267267
// Deactivate the cleanup for the callee-destructed param that was pushed.
268268
assert(!cir::MissingFeatures::thunks());
269269
if (type->isRecordType() &&
270-
type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee() &&
270+
type->castAs<RecordType>()
271+
->getOriginalDecl()
272+
->getDefinitionOrSelf()
273+
->isParamDestroyedInCallee() &&
271274
param->needsDestruction(getContext())) {
272275
cgm.errorNYI(param->getSourceRange(),
273276
"emitDelegateCallArg: callee-destructed param");
@@ -667,8 +670,10 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const clang::Expr *e,
667670
// In the Microsoft C++ ABI, aggregate arguments are destructed by the callee.
668671
// However, we still have to push an EH-only cleanup in case we unwind before
669672
// we make it to the call.
670-
if (argType->isRecordType() &&
671-
argType->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee()) {
673+
if (argType->isRecordType() && argType->castAs<RecordType>()
674+
->getOriginalDecl()
675+
->getDefinitionOrSelf()
676+
->isParamDestroyedInCallee()) {
672677
assert(!cir::MissingFeatures::msabi());
673678
cgm.errorNYI(e->getSourceRange(), "emitCallArg: msabi is NYI");
674679
}

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void emitMemberInitializer(CIRGenFunction &cgf,
8686
QualType fieldType = field->getType();
8787

8888
mlir::Value thisPtr = cgf.loadCXXThis();
89-
QualType recordTy = cgf.getContext().getTypeDeclType(classDecl);
89+
CanQualType recordTy = cgf.getContext().getCanonicalTagType(classDecl);
9090

9191
// If a base constructor is being emitted, create an LValue that has the
9292
// non-virtual alignment.
@@ -121,7 +121,8 @@ static void emitMemberInitializer(CIRGenFunction &cgf,
121121
static bool isInitializerOfDynamicClass(const CXXCtorInitializer *baseInit) {
122122
const Type *baseType = baseInit->getBaseClass();
123123
const auto *baseClassDecl =
124-
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getDecl());
124+
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getOriginalDecl())
125+
->getDefinitionOrSelf();
125126
return baseClassDecl->isDynamicClass();
126127
}
127128

@@ -161,7 +162,8 @@ void CIRGenFunction::emitBaseInitializer(mlir::Location loc,
161162

162163
const Type *baseType = baseInit->getBaseClass();
163164
const auto *baseClassDecl =
164-
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getDecl());
165+
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getOriginalDecl())
166+
->getDefinitionOrSelf();
165167

166168
bool isBaseVirtual = baseInit->isBaseVirtual();
167169

@@ -377,7 +379,7 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
377379
//
378380
// Note that these are complete objects and so we don't need to
379381
// use the non-virtual size or alignment.
380-
QualType type = getContext().getTypeDeclType(ctor->getParent());
382+
CanQualType type = getContext().getCanonicalTagType(ctor->getParent());
381383
CharUnits eltAlignment = arrayBase.getAlignment().alignmentOfArrayElement(
382384
getContext().getTypeSizeInChars(type));
383385

@@ -484,7 +486,8 @@ void CIRGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &args) {
484486
void CIRGenFunction::destroyCXXObject(CIRGenFunction &cgf, Address addr,
485487
QualType type) {
486488
const RecordType *rtype = type->castAs<RecordType>();
487-
const CXXRecordDecl *record = cast<CXXRecordDecl>(rtype->getDecl());
489+
const CXXRecordDecl *record =
490+
cast<CXXRecordDecl>(rtype->getOriginalDecl())->getDefinitionOrSelf();
488491
const CXXDestructorDecl *dtor = record->getDestructor();
489492
// TODO(cir): Unlike traditional codegen, CIRGen should actually emit trivial
490493
// dtors which shall be removed on later CIR passes. However, only remove this

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,9 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) {
10131013
case CK_DerivedToBase: {
10141014
const auto *derivedClassTy =
10151015
e->getSubExpr()->getType()->castAs<clang::RecordType>();
1016-
auto *derivedClassDecl = cast<CXXRecordDecl>(derivedClassTy->getDecl());
1016+
auto *derivedClassDecl =
1017+
cast<CXXRecordDecl>(derivedClassTy->getOriginalDecl())
1018+
->getDefinitionOrSelf();
10171019

10181020
LValue lv = emitLValue(e->getSubExpr());
10191021
Address thisAddr = lv.getAddress();
@@ -1167,9 +1169,10 @@ static void pushTemporaryCleanup(CIRGenFunction &cgf,
11671169
->getBaseElementTypeUnsafe()
11681170
->getAs<clang::RecordType>()) {
11691171
// Get the destructor for the reference temporary.
1170-
auto *classDecl = cast<CXXRecordDecl>(rt->getDecl());
1172+
auto *classDecl = cast<CXXRecordDecl>(rt->getOriginalDecl());
11711173
if (!classDecl->hasTrivialDestructor())
1172-
referenceTemporaryDtor = classDecl->getDestructor();
1174+
referenceTemporaryDtor =
1175+
classDecl->getDefinitionOrSelf()->getDestructor();
11731176
}
11741177

11751178
if (!referenceTemporaryDtor)
@@ -1831,7 +1834,7 @@ RValue CIRGenFunction::emitCXXMemberCallExpr(const CXXMemberCallExpr *ce,
18311834
}
18321835

18331836
bool hasQualifier = me->hasQualifier();
1834-
NestedNameSpecifier *qualifier = hasQualifier ? me->getQualifier() : nullptr;
1837+
NestedNameSpecifier qualifier = me->getQualifier();
18351838
bool isArrow = me->isArrow();
18361839
const Expr *base = me->getBase();
18371840

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,10 @@ void AggExprEmitter::visitCXXParenListOrInitListExpr(
376376
// the disadvantage is that the generated code is more difficult for
377377
// the optimizer, especially with bitfields.
378378
unsigned numInitElements = args.size();
379-
RecordDecl *record = e->getType()->castAs<RecordType>()->getDecl();
379+
RecordDecl *record = e->getType()
380+
->castAs<RecordType>()
381+
->getOriginalDecl()
382+
->getDefinitionOrSelf();
380383

381384
// We'll need to enter cleanup scopes in case any of the element
382385
// initializers throws an exception.

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &d) {
591591
// be a problem for the near future.
592592
if (cd->isTrivial() && cd->isDefaultConstructor()) {
593593
const auto *cxxrd =
594-
cast<CXXRecordDecl>(ty->getAs<RecordType>()->getDecl());
594+
cast<CXXRecordDecl>(ty->getAs<RecordType>()->getOriginalDecl())
595+
->getDefinitionOrSelf();
595596
if (cxxrd->getNumBases() != 0) {
596597
// There may not be anything additional to do here, but this will
597598
// force us to pause and test this path when it is supported.

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ static bool mayDropFunctionReturn(const ASTContext &astContext,
356356
// destructor or a non-trivially copyable type.
357357
if (const RecordType *recordType =
358358
returnType.getCanonicalType()->getAs<RecordType>()) {
359-
if (const auto *classDecl = dyn_cast<CXXRecordDecl>(recordType->getDecl()))
359+
if (const auto *classDecl =
360+
dyn_cast<CXXRecordDecl>(recordType->getOriginalDecl()))
360361
return classDecl->hasTrivialDestructor();
361362
}
362363
return returnType.isTriviallyCopyableType(astContext);
@@ -827,7 +828,9 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr,
827828
// Ignore empty classes in C++.
828829
if (getLangOpts().CPlusPlus) {
829830
if (const RecordType *rt = ty->getAs<RecordType>()) {
830-
if (cast<CXXRecordDecl>(rt->getDecl())->isEmpty())
831+
if (cast<CXXRecordDecl>(rt->getOriginalDecl())
832+
->getDefinitionOrSelf()
833+
->isEmpty())
831834
return;
832835
}
833836
}
@@ -978,10 +981,6 @@ void CIRGenFunction::emitVariablyModifiedType(QualType type) {
978981
case Type::BitInt:
979982
llvm_unreachable("type class is never variably-modified!");
980983

981-
case Type::Elaborated:
982-
type = cast<clang::ElaboratedType>(ty)->getNamedType();
983-
break;
984-
985984
case Type::Adjusted:
986985
type = cast<clang::AdjustedType>(ty)->getAdjustedType();
987986
break;

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class CIRGenFunction : public CIRGenTypeCache {
10111011
RValue emitCXXMemberOrOperatorMemberCallExpr(
10121012
const clang::CallExpr *ce, const clang::CXXMethodDecl *md,
10131013
ReturnValueSlot returnValue, bool hasQualifier,
1014-
clang::NestedNameSpecifier *qualifier, bool isArrow,
1014+
clang::NestedNameSpecifier qualifier, bool isArrow,
10151015
const clang::Expr *base);
10161016

10171017
mlir::Value emitCXXNewExpr(const CXXNewExpr *e);

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static bool isVarDeclStrongDefinition(const ASTContext &astContext,
997997
return true;
998998

999999
if (const auto *rt = varType->getAs<RecordType>()) {
1000-
const RecordDecl *rd = rt->getDecl();
1000+
const RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf();
10011001
for (const FieldDecl *fd : rd->fields()) {
10021002
if (fd->isBitField())
10031003
continue;
@@ -2066,8 +2066,10 @@ CharUnits CIRGenModule::computeNonVirtualBaseClassOffset(
20662066
// Get the layout.
20672067
const ASTRecordLayout &layout = astContext.getASTRecordLayout(rd);
20682068

2069-
const auto *baseDecl = cast<CXXRecordDecl>(
2070-
base->getType()->castAs<clang::RecordType>()->getDecl());
2069+
const auto *baseDecl =
2070+
cast<CXXRecordDecl>(
2071+
base->getType()->castAs<clang::RecordType>()->getOriginalDecl())
2072+
->getDefinitionOrSelf();
20712073

20722074
// Add the offset.
20732075
offset += layout.getBaseClassOffset(baseDecl);

0 commit comments

Comments
 (0)