Skip to content

Commit a79640f

Browse files
cblichmanncopybara-github
authored andcommitted
Clangtool: Fix build breakage on LLVM < 22
Internal rebase to llvmorg-21-init-16856-g696c0f92e0 lead to use of APIs only available in LLVM 22 and later. PiperOrigin-RevId: 803426800 Change-Id: I4d7193ae133c6b378228a7a92a7e1677c1fa1ee0
1 parent 34e4ab3 commit a79640f

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

  • sandboxed_api/tools/clang_generator

sandboxed_api/tools/clang_generator/types.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,23 @@ void TypeCollector::CollectRelatedTypes(clang::QualType qual) {
144144
// - Nested types are skipped and the enclosing type is collected which is
145145
// enough to reconstruct the AST when emitting the SAPI header.
146146
if (const auto* record_type = qual->getAs<clang::RecordType>()) {
147+
#if LLVM_VERSION_MAJOR >= 22
147148
const clang::RecordDecl* decl = record_type->getOriginalDecl();
149+
#else
150+
const clang::RecordDecl* decl = record_type->getDecl();
151+
#endif
148152
if (!IsProtoBuf(decl)) {
149153
for (const clang::FieldDecl* field : decl->fields()) {
150154
CollectRelatedTypes(field->getType());
151155
}
152156
}
153157
const clang::RecordDecl* outer = decl->getOuterLexicalRecordContext();
154158
decl = outer ? outer : decl;
159+
#if LLVM_VERSION_MAJOR >= 22
155160
collected_.insert(decl->getASTContext().getCanonicalTagType(decl));
161+
#else
162+
collected_.insert(clang::QualType(decl->getTypeForDecl(), /*Quals=*/0));
163+
#endif
156164
}
157165

158166
// For TypedefType; Collect the underlying type.
@@ -205,10 +213,16 @@ void TypeCollector::CollectRelatedTypes(clang::QualType qual) {
205213
// For Enumtype, recursively call CollectRelatedTypes to collect the
206214
// underlying integer type of enum classes as well, as it may be a typedef.
207215
if (qual->isEnumeralType()) {
216+
#if LLVM_VERSION_MAJOR >= 22
208217
qual = qual.getCanonicalType();
218+
#endif
209219
if (const clang::EnumType* enum_type = qual->getAs<clang::EnumType>()) {
210-
if (const clang::EnumDecl* decl = enum_type->getOriginalDecl();
211-
decl->isFixed()) {
220+
#if LLVM_VERSION_MAJOR >= 22
221+
const clang::EnumDecl* decl = enum_type->getOriginalDecl();
222+
#else
223+
const clang::EnumDecl* decl = enum_type->getDecl();
224+
#endif
225+
if (decl->isFixed()) {
212226
CollectRelatedTypes(decl->getIntegerType());
213227
}
214228
}
@@ -419,10 +433,18 @@ std::string TypeMapper::MapQualType(clang::QualType qual) const {
419433
break;
420434
}
421435
} else if (const auto* enum_type = qual->getAs<clang::EnumType>()) {
436+
#if LLVM_VERSION_MAJOR >= 22
422437
clang::EnumDecl* enum_decl = enum_type->getOriginalDecl();
438+
#else
439+
clang::EnumDecl* enum_decl = enum_type->getDecl();
440+
#endif
423441
if (auto* typedef_decl = enum_decl->getTypedefNameForAnonDecl()) {
442+
#if LLVM_VERSION_MAJOR >= 22
424443
qual = context_.getTypedefType(clang::ElaboratedTypeKeyword::None,
425444
/*Qualifier=*/std::nullopt, typedef_decl);
445+
#else
446+
qual = typedef_decl->getUnderlyingType().getDesugaredType(context_);
447+
#endif
426448
}
427449
return absl::StrCat("::sapi::v::IntBase<",
428450
GetFullyQualifiedName(context_, qual, ns_to_strip_),

0 commit comments

Comments
 (0)