Skip to content

Commit e3fc694

Browse files
Aaron feedback
1 parent fe16bf1 commit e3fc694

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ related warnings within the method body.
407407
example.c:6:17: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
408408
6 | printf(format, 123);
409409
| ~~~~~~ ^~~
410-
<scratch space>:1:4: note: format string resolved to a constant string
410+
<scratch space>:1:4: note: format string computed from non-literal expression
411411
1 | "hello %s"
412412
| ^~
413413
| %d

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9268,7 +9268,7 @@ def err_expected_callable_argument : Error<
92689268
def note_building_builtin_dump_struct_call : Note<
92699269
"in call to printing function with arguments '(%0)' while dumping struct">;
92709270
def err_builtin_verbose_trap_arg : Error<
9271-
"argument to __builtin_verbose_trap must %select{be a pointer to a constant NUL-terminated string|not contain $}0">;
9271+
"argument to '__builtin_verbose_trap' must %select{be a pointer to a constant null-terminated string|not contain $}0">;
92729272

92739273
def err_atomic_load_store_uses_lib : Error<
92749274
"atomic %select{load|store}0 requires runtime support that is not "

clang/test/Sema/format-strings.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1+
// #scratch_space
12
// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s
23
// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s
34
// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-unknown-fuchsia %s
45
// RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-linux-android %s
56

6-
// expected-note@-5{{format string computed from non-literal expression}}
7-
// ^^^ there will be a <scratch space> SourceLocation caused by the
8-
// test_consteval_init_array test, that -verify treats as if it showed up at
9-
// line 1 of this file.
10-
117
#include <stdarg.h>
128
#include <stddef.h>
139
#define __need_wint_t
@@ -913,4 +909,5 @@ void test_consteval_init_array(void) {
913909
const char buf[] = {'%', 55 * 2 + 5, '\n', 0};
914910
printf(buf, "hello"); // no-warning
915911
printf(buf, 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
912+
// expected-note@#scratch_space {{format string computed from non-literal expression}}
916913
}

clang/test/SemaCXX/format-strings.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1+
// #scratch_space
12
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks %s
23
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++98 %s
34
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks -std=c++11 %s
45
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks -std=c++20 %s
5-
6-
#if __cplusplus >= 202000l
7-
// expected-note@-6{{format string computed from non-literal expression}}
8-
// ^^^ there will be a <scratch space> SourceLocation caused by the
9-
// test_constexpr_string test, that -verify treats as if it showed up at
10-
// line 1 of this file.
11-
#endif
6+
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks -std=c++23 %s
127

138
#include <stdarg.h>
149

@@ -310,5 +305,26 @@ constexpr my_string const_string() {
310305
void test_constexpr_string() {
311306
printf(const_string().c_str(), "hello", 123); // no-warning
312307
printf(const_string().c_str(), 123, 456); // expected-warning {{format specifies type 'char *' but the argument has type 'int'}}
308+
// expected-note@#scratch_space {{format string computed from non-literal expression}}
309+
}
310+
#endif
311+
312+
#if __cplusplus >= 202300L
313+
constexpr const char *consteval_str() {
314+
if consteval {
315+
return "%s";
316+
} else {
317+
return "%d"; // expected-note 2{{format string is defined here}}
318+
}
319+
}
320+
321+
constexpr const char *consteval_str_global = consteval_str();
322+
323+
void test_consteval_str() {
324+
printf(consteval_str(), 789); // no-warning
325+
printf(consteval_str(), "hello"); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}}
326+
327+
printf(consteval_str_global, 1234); // no-warning
328+
printf(consteval_str_global, "hello"); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}}
313329
}
314330
#endif

clang/test/SemaCXX/verbose-trap.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ void f(const char * arg) {
2727
__builtin_verbose_trap(); // expected-error {{too few arguments}}
2828
__builtin_verbose_trap(""); // expected-error {{too few arguments}}
2929
__builtin_verbose_trap("", "", ""); // expected-error {{too many arguments}}
30-
__builtin_verbose_trap("", 0); // expected-error {{argument to __builtin_verbose_trap must be a pointer to a constant NUL-terminated string}}
30+
__builtin_verbose_trap("", 0); // expected-error {{argument to '__builtin_verbose_trap' must be a pointer to a constant null-terminated string}}
3131
__builtin_verbose_trap(1, ""); // expected-error {{cannot initialize a parameter of type 'const char *' with an rvalue of type 'int'}}
32-
__builtin_verbose_trap(arg, ""); // expected-error {{argument to __builtin_verbose_trap must be a pointer to a constant NUL-terminated string}}
33-
__builtin_verbose_trap(buf, ""); // expected-error {{argument to __builtin_verbose_trap must be a pointer to a constant NUL-terminated string}}
32+
__builtin_verbose_trap(arg, ""); // expected-error {{argument to '__builtin_verbose_trap' must be a pointer to a constant null-terminated string}}
33+
__builtin_verbose_trap(buf, ""); // expected-error {{argument to '__builtin_verbose_trap' must be a pointer to a constant null-terminated string}}
3434
__builtin_verbose_trap(buf_nt1, "");
3535
__builtin_verbose_trap(buf_nt2, "");
36-
__builtin_verbose_trap("cat$1", "hel$lo"); // expected-error 2 {{argument to __builtin_verbose_trap must not contain $}}
36+
__builtin_verbose_trap("cat$1", "hel$lo"); // expected-error 2 {{argument to '__builtin_verbose_trap' must not contain $}}
3737
__builtin_verbose_trap(category, reason);
3838
__builtin_verbose_trap(u8"cat1", u8"hello");
3939
#if __cplusplus >= 202002L

0 commit comments

Comments
 (0)