Skip to content

Commit b468a42

Browse files
committed
Emit error for missing format attribute
1 parent 90f85cf commit b468a42

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13017,6 +13017,9 @@ def err_get_vtable_pointer_requires_complete_type
1301713017
: Error<"__builtin_get_vtable_pointer requires an argument with a complete "
1301813018
"type, but %0 is incomplete">;
1301913019

13020+
def err_modular_format_attribute_no_format : Error<
13021+
"'modular_format' attribute requires 'format' attribute">;
13022+
1302013023
// SYCL-specific diagnostics
1302113024
def warn_sycl_kernel_num_of_template_params : Warning<
1302213025
"'sycl_kernel' attribute only applies to a function template with at least"

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7210,6 +7210,11 @@ static void checkLifetimeBoundAttr(Sema &S, NamedDecl &ND) {
72107210
}
72117211
}
72127212

7213+
static void checkModularFormatAttr(Sema &S, NamedDecl &ND) {
7214+
if (ND.hasAttr<ModularFormatAttr>() && !ND.hasAttr<FormatAttr>())
7215+
S.Diag(ND.getLocation(), diag::err_modular_format_attribute_no_format);
7216+
}
7217+
72137218
static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
72147219
// Ensure that an auto decl is deduced otherwise the checks below might cache
72157220
// the wrong linkage.
@@ -7222,6 +7227,7 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
72227227
checkHybridPatchableAttr(S, ND);
72237228
checkInheritableAttr(S, ND);
72247229
checkLifetimeBoundAttr(S, ND);
7230+
checkModularFormatAttr(S, ND);
72257231
}
72267232

72277233
static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
#include <stdarg.h>
4+
5+
int printf(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "float"))); // no-error
6+
int myprintf(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "float"))); // expected-error {{'modular_format' attribute requires 'format' attribute}}
7+

0 commit comments

Comments
 (0)