================
@@ -6973,6 +6973,65 @@ static void handleVTablePointerAuthentication(Sema &S,
Decl *D,
CustomDiscriminationValue));
}
+static bool modularFormatIsSame(const ModularFormatAttr *Existing,
+ IdentifierInfo *ModularImplFn,
+ StringRef ImplName,
+ ArrayRef<StringRef> Aspects) {
+ if (Existing->getModularImplFn() != ModularImplFn)
+ return false;
+ if (Existing->getImplName() != ImplName)
+ return false;
+ if (Existing->aspects_size() != Aspects.size())
+ return false;
+ unsigned I = 0;
+ for (const auto &ExistingAspect : Existing->aspects()) {
+ if (ExistingAspect != Aspects[I++])
+ return false;
+ }
+ return true;
+}
+
+static void handleModularFormat(Sema &S, Decl *D, const ParsedAttr &AL) {
+ StringRef ImplName;
+ if (!S.checkStringLiteralArgumentAttr(AL, 1, ImplName))
+ return;
+ SmallVector<StringRef> Aspects;
+ llvm::DenseSet<StringRef> SeenAspects;
+ bool HasDuplicate = false;
+ for (unsigned I = 2, E = AL.getNumArgs(); I != E; ++I) {
+ StringRef Aspect;
+ if (!S.checkStringLiteralArgumentAttr(AL, I, Aspect))
+ return;
+ if (!SeenAspects.insert(Aspect).second) {
+ S.Diag(AL.getArgAsExpr(I)->getExprLoc(),
+ diag::err_modular_format_duplicate_aspect)
+ << Aspect;
+ HasDuplicate = true;
+ continue;
+ }
+ Aspects.push_back(Aspect);
+ }
+
+ // Store aspects sorted.
+ llvm::sort(Aspects);
+
+ IdentifierInfo *ModularImplFn = AL.getArgAsIdent(0)->getIdentifierInfo();
+
+ if (const auto *Existing = D->getAttr<ModularFormatAttr>()) {
+ if (!modularFormatIsSame(Existing, ModularImplFn, ImplName, Aspects)) {
+ S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
+ S.Diag(Existing->getLocation(), diag::note_conflicting_attribute);
+ }
+ D->dropAttr<ModularFormatAttr>();
----------------
mysterymath wrote:
Yep, that's better. Done.
https://github.com/llvm/llvm-project/pull/147431
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits