[clang] [clang] "modular_format" attribute for functions using format strings (PR #147431)

Daniel Thornburgh via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 2 10:21:31 PST 2025


================
@@ -6973,6 +6973,27 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D,
       CustomDiscriminationValue));
 }
 
+static void handleModularFormat(Sema &S, Decl *D, const ParsedAttr &AL) {
+  StringRef ImplName;
+  if (!S.checkStringLiteralArgumentAttr(AL, 1, ImplName))
+    return;
+  SmallVector<StringRef> Aspects;
+  for (unsigned I = 2, E = AL.getNumArgs(); I != E; ++I) {
+    StringRef Aspect;
+    if (!S.checkStringLiteralArgumentAttr(AL, I, Aspect))
+      return;
+    Aspects.push_back(Aspect);
+  }
+
+  // Store aspects sorted and without duplicates.
+  llvm::sort(Aspects);
+  Aspects.erase(llvm::unique(Aspects), Aspects.end());
----------------
mysterymath wrote:

The more I think about it, the less utility there seems to be in allowing these to be constructed piecemeal. Allowing only one per declaration seems reasonable, and it's pretty easy to rig up. I'll do that.

Also, thanks for spending the time on this! I'm learning a lot about the finer points of clang attributes; long overdue.

https://github.com/llvm/llvm-project/pull/147431


More information about the cfe-commits mailing list