[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal
YingChi Long via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 1 08:28:48 PDT 2022
inclyc added inline comments.
================
Comment at: clang/test/Sema/format-strings-scanf.c:235
scanf(0 ? "%s" : "%d", i); // no warning
- scanf(1 ? "%s" : "%d", i); // expected-warning{{format specifies type 'char *'}}
+ scanf(1 ? "%s" : "%d", i); // expected-warning{{format specifies type 'char *'}} \
+ // expected-note{{format string is defined here}}
----------------
These new notes are FixIt hints, looks much better than before.
================
Comment at: clang/test/Sema/format-strings.c:263
// expected-note at -1{{treat the string as an argument to avoid this}}
- printf(s4); // expected-warning{{not a string literal}}
- // expected-note at -1{{treat the string as an argument to avoid this}}
+ printf(s4);
printf(s5); // expected-warning{{not a string literal}}
----------------
Here, s4 is declared as `char * const` and initialized as `const char`, so warning generates at the declaration of `s4` is sufficient? Since modify characters in string literal causes UB.
```
Initializing 'char *const' with an expression of type 'const char[6]' discards qualifiers
```
Currently the checker in this patch just qualifies `"hello"` as a string literal, and does not report `-Wformat-nonliteral` as before
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130906/new/
https://reviews.llvm.org/D130906
More information about the cfe-commits
mailing list