@@ -3848,9 +3848,9 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
38483848 // If there are none or one spelling to check, resort to the default
38493849 // behavior of returning index as 0.
38503850 if (Spellings.size () <= 1 ) {
3851- OS << " return 0;\n " ;
3852- OS << " break;\n " ;
3853- OS << " }\n " ;
3851+ OS << " return 0;\n "
3852+ << " break;\n "
3853+ << " }\n " ;
38543854 continue ;
38553855 }
38563856
@@ -3869,22 +3869,26 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
38693869 // syntax and scope.
38703870 if (HasSingleUniqueSpellingName) {
38713871 for (const auto &[Idx, S] : enumerate(SpellingMap[FirstName])) {
3872- OS << " if (getSyntax() == AttributeCommonInfo::AS_" << S->variety ();
3872+ OS << " if (getSyntax() == AttributeCommonInfo::AS_" << S->variety ()
3873+ << " && ComputedScope == " ;
38733874
3874- std::string ScopeStr = " AttributeCommonInfo::SC_" ;
38753875 if (S->nameSpace () == " " )
3876- ScopeStr += " NONE " ;
3876+ OS << " AttributeCommonInfo::SC_NONE " ;
38773877 else
3878- ScopeStr += S->nameSpace ().upper ();
3878+ OS << " AttributeCommonInfo::SC_ " + S->nameSpace ().upper ();
38793879
3880- OS << " && ComputedScope == " << ScopeStr << " )\n "
3880+ OS << " )\n "
38813881 << " return " << Idx << " ;\n " ;
38823882 }
38833883 } else {
38843884 size_t Idx = 0 ;
3885- for (const auto &MapEntry : SpellingMap) {
3886- StringRef Name = MapEntry.first ();
3887- const std::vector<const FlattenedSpelling *> &Cases = SpellingMap[Name];
3885+ StringMap<bool > Completed;
3886+ for (const auto &Spell : Spellings) {
3887+ if (Completed.contains (Spell.name ()))
3888+ continue ;
3889+
3890+ const std::vector<const FlattenedSpelling *> &Cases =
3891+ SpellingMap[Spell.name ()];
38883892
38893893 if (Cases.size () > 1 ) {
38903894 // For names with multiple possible cases, emit an enclosing if such
@@ -3896,17 +3900,17 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
38963900 // return 0;
38973901 // ...
38983902 // }
3899- OS << " if (Name == \" " << Name << " \" ) {\n " ;
3900- for (const auto &S : SpellingMap[Name ]) {
3903+ OS << " if (Name == \" " << Spell. name () << " \" ) {\n " ;
3904+ for (const auto &S : SpellingMap[Spell. name () ]) {
39013905 OS << " if (getSyntax() == AttributeCommonInfo::AS_"
3902- << S->variety ();
3903- std::string ScopeStr = " AttributeCommonInfo::SC_ " ;
3906+ << S->variety () << " && ComputedScope == " ;
3907+
39043908 if (S->nameSpace () == " " )
3905- ScopeStr += " NONE " ;
3909+ OS << " AttributeCommonInfo::SC_NONE " ;
39063910 else
3907- ScopeStr += S->nameSpace ().upper ();
3911+ OS << " AttributeCommonInfo::SC_ " + S->nameSpace ().upper ();
39083912
3909- OS << " && ComputedScope == " << ScopeStr << " )\n "
3913+ OS << " )\n "
39103914 << " return " << Idx << " ;\n " ;
39113915 Idx++;
39123916 }
@@ -3920,27 +3924,30 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
39203924 // && ComputedScope == AttributeCommonInfo::SC_NONE)
39213925 // return 5;
39223926 const FlattenedSpelling *S = Cases.front ();
3923- OS << " if (Name == \" " << Name << " \" " ;
3924- OS << " && getSyntax() == AttributeCommonInfo::AS_" << S->variety ();
3927+ OS << " if (Name == \" " << Spell.name () << " \" "
3928+ << " && getSyntax() == AttributeCommonInfo::AS_" << S->variety ()
3929+ << " && ComputedScope == " ;
3930+
39253931 std::string ScopeStr = " AttributeCommonInfo::SC_" ;
39263932 if (S->nameSpace () == " " )
3927- ScopeStr += " NONE " ;
3933+ OS << " AttributeCommonInfo::SC_NONE " ;
39283934 else
3929- ScopeStr += S->nameSpace ().upper ();
3935+ OS << " AttributeCommonInfo::SC_ " + S->nameSpace ().upper ();
39303936
3931- OS << " && ComputedScope == " << ScopeStr << " )\n "
3937+ OS << " )\n "
39323938 << " return " << Idx << " ;\n " ;
39333939 Idx++;
39343940 }
3941+ Completed[Spell.name ()] = true ;
39353942 }
39363943 }
39373944
3938- OS << " break;\n " ;
3939- OS << " }\n " ;
3945+ OS << " break;\n "
3946+ << " }\n " ;
39403947 }
39413948
3942- OS << " }\n " ;
3943- OS << " return 0;\n " ;
3949+ OS << " }\n "
3950+ << " return 0;\n " ;
39443951}
39453952
39463953// Emits code used by RecursiveASTVisitor to visit attributes
0 commit comments