[llvm-branch-commits] [clang] release/22.x: [clang] Check that first modular_format argument is an identifier (#178322) (PR #178497)
Cullen Rhodes via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jan 30 00:17:33 PST 2026
https://github.com/c-rhodes updated https://github.com/llvm/llvm-project/pull/178497
>From ce4bf64e447b81746c3b53964282e9e369b1893e Mon Sep 17 00:00:00 2001
From: Daniel Thornburgh <mysterymath at gmail.com>
Date: Wed, 28 Jan 2026 11:20:56 -0800
Subject: [PATCH] [clang] Check that first modular_format argument is an
identifier (#178322)
This fixes an oversight discovered in #147431.
(cherry picked from commit 6f79891cf582aba7998c5caba9d7a03fd7cc61bc)
---
clang/lib/Sema/SemaDeclAttr.cpp | 5 +++++
clang/test/Sema/attr-modular-format.c | 2 ++
2 files changed, 7 insertions(+)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index d762bcd789bf5..3f0ea5c8f3eba 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7035,6 +7035,11 @@ ModularFormatAttr *Sema::mergeModularFormatAttr(
static void handleModularFormat(Sema &S, Decl *D, const ParsedAttr &AL) {
bool Valid = true;
+ if (!AL.isArgIdent(0)) {
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
+ << AL << 1 << AANT_ArgumentIdentifier;
+ Valid = false;
+ }
StringRef ImplName;
if (!S.checkStringLiteralArgumentAttr(AL, 1, ImplName))
Valid = false;
diff --git a/clang/test/Sema/attr-modular-format.c b/clang/test/Sema/attr-modular-format.c
index b7ae519cedbeb..9d7e1ac1b485a 100644
--- a/clang/test/Sema/attr-modular-format.c
+++ b/clang/test/Sema/attr-modular-format.c
@@ -3,6 +3,8 @@
int printf(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "float"))); // no-error
int myprintf(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "float"))); // expected-error {{'modular_format' attribute requires 'format' attribute}}
+int string_impl_fn(const char *fmt, ...) __attribute__((modular_format("__modular_printf", "__printf", "float"), format(printf, 1, 2))); // expected-error {{'modular_format' attribute requires parameter 1 to be an identifier}}
+
int lprintf(const char *fmt, ...) __attribute__((modular_format(__modular_printf, L"__printf", L"float"), format(printf, 1, 2)));
// expected-warning at -1 2{{encoding prefix 'L' on an unevaluated string literal has no effect}}
More information about the llvm-branch-commits
mailing list