================ @@ -3843,19 +3844,60 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records, const Record &R = *I.second; std::vector<FlattenedSpelling> Spellings = GetFlattenedSpellings(R); OS << " case AT_" << I.first << ": {\n"; - for (unsigned I = 0; I < Spellings.size(); ++ I) { - OS << " if (Name == \"" << Spellings[I].name() << "\" && " - << "getSyntax() == AttributeCommonInfo::AS_" << Spellings[I].variety() - << " && Scope == \"" << Spellings[I].nameSpace() << "\")\n" - << " return " << I << ";\n"; + + // If there are none or one spelling to check, resort to the default + // behavior of returning index as 0. + if (Spellings.size() <= 1) { + OS << " return 0;\n" + << " break;\n" + << " }\n"; + continue; } - OS << " break;\n"; - OS << " }\n"; + std::vector<StringRef> Names; + llvm::transform(Spellings, std::back_inserter(Names), + [](const FlattenedSpelling &FS) { return FS.name(); }); + llvm::sort(Names); + Names.erase(llvm::unique(Names), Names.end()); + + for (const auto &[Idx, FS] : enumerate(Spellings)) { + if (Names.size() == 1) { + OS << " if ("; ---------------- erichkeane wrote:
As a nit, I'd suggest printing this unconditionally above this 'if', then inverting it for the 'else' condition (since 3873 and 3879 are both printing this too). https://github.com/llvm/llvm-project/pull/114899 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits