Skip to content

[CIR] Make ClangIR compatible with latest nested name specifier AST representation #152846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang/lib/CIR/CodeGen/CIRGenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ CIRGenFunctionInfo::create(CanQualType resultType,
return fi;
}

cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
mlir::Type resultType = convertType(fi.getReturnType());
cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &info) {
mlir::Type resultType = convertType(info.getReturnType());
SmallVector<mlir::Type, 8> argTypes;
argTypes.reserve(fi.getNumRequiredArgs());
argTypes.reserve(info.getNumRequiredArgs());

for (const CanQualType &argType : fi.requiredArguments())
for (const CanQualType &argType : info.requiredArguments())
argTypes.push_back(convertType(argType));

return cir::FuncType::get(argTypes,
(resultType ? resultType : builder.getVoidTy()),
fi.isVariadic());
info.isVariadic());
}

CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,8 @@ static void pushTemporaryCleanup(CIRGenFunction &cgf,
->getBaseElementTypeUnsafe()
->getAs<clang::RecordType>()) {
// Get the destructor for the reference temporary.
auto *classDecl = cast<CXXRecordDecl>(rt->getOriginalDecl());
auto *classDecl =
cast<CXXRecordDecl>(rt->getOriginalDecl()->getDefinitionOrSelf());
if (!classDecl->hasTrivialDestructor())
referenceTemporaryDtor =
classDecl->getDefinitionOrSelf()->getDestructor();
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ static bool mayDropFunctionReturn(const ASTContext &astContext,
// destructor or a non-trivially copyable type.
if (const RecordType *recordType =
returnType.getCanonicalType()->getAs<RecordType>()) {
if (const auto *classDecl =
dyn_cast<CXXRecordDecl>(recordType->getOriginalDecl()))
if (const auto *classDecl = dyn_cast<CXXRecordDecl>(
recordType->getOriginalDecl()->getDefinitionOrSelf()))
return classDecl->hasTrivialDestructor();
}
return returnType.isTriviallyCopyableType(astContext);
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt,
if (!alreadyChecked.insert(rd).second)
return true;

assert(rd->isCompleteDefinition() &&
"Expect RecordDecl to be CompleteDefinition");
const Type *key = cgt.getASTContext().getCanonicalTagType(rd).getTypePtr();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI slightly unrelated, but it might make sense to assert(rd->isCompleteDefinition() since some of the uses here only make sense when applied on the definition, such as the fields iteration down below.


// If this type is already laid out, converting it is a noop.
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CIR/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &context,
if (cxxrd->isDynamicClass())
return false;

for (const auto &I : cxxrd->bases())
if (!isEmptyRecordForLayout(context, I.getType()))
for (const auto &i : cxxrd->bases())
if (!isEmptyRecordForLayout(context, i.getType()))
return false;
}

for (const auto *I : rd->fields())
if (!isEmptyFieldForLayout(context, I))
for (const auto *i : rd->fields())
if (!isEmptyFieldForLayout(context, i))
return false;

return true;
Expand Down