Skip to content

Commit 845030b

Browse files
Sandboxed API Teamcopybara-github
authored andcommitted
Updates LLVM usage to match [cb2f0d0a5f14](llvm/llvm-project@cb2f0d0a5f14) PiperOrigin-RevId: 802610159 Change-Id: I3aaba88e74b0597f1534c1f3f4255d176b1265e5
1 parent 5465cc2 commit 845030b

5 files changed

Lines changed: 69 additions & 22 deletions

File tree

sandboxed_api/tools/clang_generator/emitter_base.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ std::string PrintRecordTemplateArguments(const clang::CXXRecordDecl* record) {
109109
}
110110

111111
// Serializes the given Clang AST declaration back into compilable source code.
112-
std::string PrintDecl(const clang::Decl* decl) {
112+
std::string PrintDecl(const clang::Decl* decl,
113+
bool IncludeTagDefinition = false) {
113114
std::string pretty;
114115
llvm::raw_string_ostream os(pretty);
115-
decl->print(os);
116+
clang::PrintingPolicy policy = decl->getASTContext().getPrintingPolicy();
117+
policy.IncludeTagDefinition = IncludeTagDefinition;
118+
decl->print(os, policy);
116119
return pretty;
117120
}
118121

@@ -181,7 +184,7 @@ std::string GetSpelling(const clang::Decl* decl) {
181184
// - types without no user-defined methods (including constructors)
182185
if (record_decl->hasDefinition() && record_decl->isAggregate() &&
183186
(record_decl->isPOD() || record_decl->methods().empty())) {
184-
return PrintDecl(decl);
187+
return PrintDecl(decl, /*IncludeTagDefinition=*/true);
185188
}
186189

187190
// Remaining declarations that are:

sandboxed_api/tools/clang_generator/generator.cc

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,21 @@ bool GeneratorFactory::runInvocation(
423423
"__builtin_ia32_vec_init_v8qi=[](auto, auto, auto, auto, auto, "
424424
"auto, auto, auto)->long long{return 0;}",
425425
// AVX
426-
"__builtin_ia32_vpopcntb_128=",
427-
"__builtin_ia32_vpopcntb_256=",
428-
"__builtin_ia32_vpopcntb_512=",
429-
"__builtin_ia32_vpopcntd_128=",
430-
"__builtin_ia32_vpopcntd_256=",
431-
"__builtin_ia32_vpopcntd_512=",
432-
"__builtin_ia32_vpopcntq_128=",
433-
"__builtin_ia32_vpopcntq_256=",
434-
"__builtin_ia32_vpopcntq_512=",
435-
"__builtin_ia32_vpopcntw_128=",
436-
"__builtin_ia32_vpopcntw_256=",
437-
"__builtin_ia32_vpopcntw_512=",
426+
"__builtin_ia32_prolvd128=",
427+
"__builtin_ia32_prolvd256=",
428+
"__builtin_ia32_prolvd512=",
429+
"__builtin_ia32_prolvq128=",
430+
"__builtin_ia32_prolvq256=",
431+
"__builtin_ia32_prolvq512=",
432+
"__builtin_ia32_prorvd128=",
433+
"__builtin_ia32_prorvd256=",
434+
"__builtin_ia32_prorvd512=",
435+
"__builtin_ia32_prorvq128=",
436+
"__builtin_ia32_prorvq256=",
437+
"__builtin_ia32_prorvq512=",
438+
"__builtin_ia32_vcvtph2ps=",
439+
"__builtin_ia32_vcvtph2ps256=[](auto) -> __m256{return {0, 0, 0, 0, "
440+
"0, 0, 0, 0};}",
438441
"__builtin_ia32_vcvttpd2dqs256_round_mask=[](auto, auto, auto, "
439442
"auto)->__m128i {return __m128i();}",
440443
"__builtin_ia32_vcvttpd2udqs256_round_mask=[](auto, auto, auto, "
@@ -453,6 +456,40 @@ bool GeneratorFactory::runInvocation(
453456
"auto)->__m256i {return __m256i();}",
454457
"__builtin_ia32_vcvttps2uqqs512_round_mask=[](auto, auto, auto, "
455458
"auto)->__m512i {return __m512i();}",
459+
"__builtin_ia32_vpopcntb_128=",
460+
"__builtin_ia32_vpopcntb_256=",
461+
"__builtin_ia32_vpopcntb_512=",
462+
"__builtin_ia32_vpopcntd_128=",
463+
"__builtin_ia32_vpopcntd_256=",
464+
"__builtin_ia32_vpopcntd_512=",
465+
"__builtin_ia32_vpopcntq_128=",
466+
"__builtin_ia32_vpopcntq_256=",
467+
"__builtin_ia32_vpopcntq_512=",
468+
"__builtin_ia32_vpopcntw_128=",
469+
"__builtin_ia32_vpopcntw_256=",
470+
"__builtin_ia32_vpopcntw_512=",
471+
"__builtin_ia32_vprotd=",
472+
"__builtin_ia32_vprotq=",
473+
"__builtin_ia32_vprotb=",
474+
"__builtin_ia32_vprotw=",
475+
"__builtin_ia32_vpshldvd128=",
476+
"__builtin_ia32_vpshldvd256=",
477+
"__builtin_ia32_vpshldvd512=",
478+
"__builtin_ia32_vpshldvq128=",
479+
"__builtin_ia32_vpshldvq256=",
480+
"__builtin_ia32_vpshldvq512=",
481+
"__builtin_ia32_vpshldvw128=",
482+
"__builtin_ia32_vpshldvw256=",
483+
"__builtin_ia32_vpshldvw512=",
484+
"__builtin_ia32_vpshrdvd128=",
485+
"__builtin_ia32_vpshrdvd256=",
486+
"__builtin_ia32_vpshrdvd512=",
487+
"__builtin_ia32_vpshrdvq128=",
488+
"__builtin_ia32_vpshrdvq256=",
489+
"__builtin_ia32_vpshrdvq512=",
490+
"__builtin_ia32_vpshrdvw128=",
491+
"__builtin_ia32_vpshrdvw256=",
492+
"__builtin_ia32_vpshrdvw512=",
456493

457494
// Trick <prfchwintrin.h> from being included by defining its header
458495
// guard.

sandboxed_api/tools/clang_generator/types.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ 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-
const clang::RecordDecl* decl = record_type->getDecl();
147+
const clang::RecordDecl* decl = record_type->getOriginalDecl();
148148
if (!IsProtoBuf(decl)) {
149149
for (const clang::FieldDecl* field : decl->fields()) {
150150
CollectRelatedTypes(field->getType());
151151
}
152152
}
153153
const clang::RecordDecl* outer = decl->getOuterLexicalRecordContext();
154154
decl = outer ? outer : decl;
155-
collected_.insert(clang::QualType(decl->getTypeForDecl(), /*Quals=*/0));
155+
collected_.insert(decl->getASTContext().getCanonicalTagType(decl));
156156
}
157157

158158
// For TypedefType; Collect the underlying type.
@@ -205,8 +205,10 @@ void TypeCollector::CollectRelatedTypes(clang::QualType qual) {
205205
// For Enumtype, recursively call CollectRelatedTypes to collect the
206206
// underlying integer type of enum classes as well, as it may be a typedef.
207207
if (qual->isEnumeralType()) {
208+
qual = qual.getCanonicalType();
208209
if (const clang::EnumType* enum_type = qual->getAs<clang::EnumType>()) {
209-
if (const clang::EnumDecl* decl = enum_type->getDecl(); decl->isFixed()) {
210+
if (const clang::EnumDecl* decl = enum_type->getOriginalDecl();
211+
decl->isFixed()) {
210212
CollectRelatedTypes(decl->getIntegerType());
211213
}
212214
}
@@ -417,9 +419,10 @@ std::string TypeMapper::MapQualType(clang::QualType qual) const {
417419
break;
418420
}
419421
} else if (const auto* enum_type = qual->getAs<clang::EnumType>()) {
420-
clang::EnumDecl* enum_decl = enum_type->getDecl();
422+
clang::EnumDecl* enum_decl = enum_type->getOriginalDecl();
421423
if (auto* typedef_decl = enum_decl->getTypedefNameForAnonDecl()) {
422-
qual = typedef_decl->getUnderlyingType().getDesugaredType(context_);
424+
qual = context_.getTypedefType(clang::ElaboratedTypeKeyword::None,
425+
/*Qualifier=*/std::nullopt, typedef_decl);
423426
}
424427
return absl::StrCat("::sapi::v::IntBase<",
425428
GetFullyQualifiedName(context_, qual, ns_to_strip_),

sandboxed_api/tools/python_generator/code.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ def get_pointee(self):
251251
# type: () -> Type
252252
return Type(self._tu, self._clang_type.get_pointee())
253253

254+
def get_canonical(self):
255+
# type: () -> Type
256+
return Type(self._tu, self._clang_type.get_canonical())
257+
254258
def _get_declaration(self):
255259
# type: () -> cindex.Cursor
256260
decl = self._clang_type.get_declaration()
@@ -334,7 +338,7 @@ def _get_related_types_of_record(self, result, skip_self=False):
334338
decl = self._get_declaration()
335339
if not decl.is_anonymous() and not skip_self:
336340
self._tu.search_for_macro_name(decl)
337-
result.add(self)
341+
result.add(self.get_canonical())
338342

339343
for f in self._clang_type.get_fields():
340344
self._tu.search_for_macro_name(f)

sandboxed_api/tools/python_generator/code_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def testForwardDeclaration(self):
473473

474474
names = [t._clang_type.spelling for t in generator._get_related_types()]
475475
self.assertEqual(
476-
names, ['struct_6', 'struct_6p', 'function_p3', 'struct_6_def']
476+
names, ['struct_6_def', 'struct_6', 'struct_6p', 'function_p3']
477477
)
478478

479479
# Extra check for generation, in case rendering throws error for this test.

0 commit comments

Comments
 (0)