summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema
diff options
context:
space:
mode:
authorNathan Huckleberry <nhuck@google.com>2019-08-23 18:01:57 +0000
committerNathan Huckleberry <nhuck@google.com>2019-08-23 18:01:57 +0000
commitcc01d6421f4a896820c02da2ea92b82d973b431e (patch)
tree90e9cb68fbceb82f0bc4438cd5654833dcf1aa1f /clang/test/Sema
parent30232770fbe5f5df7d5d01bd418c5ef9cc76b75e (diff)
downloadbcm5719-llvm-cc01d6421f4a896820c02da2ea92b82d973b431e.tar.gz
bcm5719-llvm-cc01d6421f4a896820c02da2ea92b82d973b431e.zip
[Sema] Don't warn on printf('%hd', [char]) (PR41467)
Summary: Link: https://bugs.llvm.org/show_bug.cgi?id=41467 Reviewers: rsmith, nickdesaulniers, aaron.ballman, lebedev.ri Reviewed By: nickdesaulniers, aaron.ballman, lebedev.ri Subscribers: lebedev.ri, nickdesaulniers, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66186 llvm-svn: 369791
Diffstat (limited to 'clang/test/Sema')
-rw-r--r--clang/test/Sema/format-strings-enum-fixed-type.cpp8
-rw-r--r--clang/test/Sema/format-strings-pedantic.c10
-rw-r--r--clang/test/Sema/format-strings.c4
3 files changed, 16 insertions, 6 deletions
diff --git a/clang/test/Sema/format-strings-enum-fixed-type.cpp b/clang/test/Sema/format-strings-enum-fixed-type.cpp
index 0022ccbc66b..de22f093780 100644
--- a/clang/test/Sema/format-strings-enum-fixed-type.cpp
+++ b/clang/test/Sema/format-strings-enum-fixed-type.cpp
@@ -79,10 +79,10 @@ void testChar(CharEnum input) {
printf("%hhd", input); // no-warning
printf("%hhd", CharConstant); // no-warning
- // This is not correct but it is safe. We warn because '%hd' shows intent.
- printf("%hd", input); // expected-warning{{format specifies type 'short' but the argument has underlying type 'char'}}
- printf("%hd", CharConstant); // expected-warning{{format specifies type 'short'}}
-
+ // This is not correct, but it is safe. Only warned in pedantic mode because '%hd' shows intent.
+ printf("%hd", input);
+ printf("%hd", CharConstant);
+
// This is not correct but it matches the promotion rules (and is safe).
printf("%d", input); // no-warning
printf("%d", CharConstant); // no-warning
diff --git a/clang/test/Sema/format-strings-pedantic.c b/clang/test/Sema/format-strings-pedantic.c
new file mode 100644
index 00000000000..8fb298ab799
--- /dev/null
+++ b/clang/test/Sema/format-strings-pedantic.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat -Wformat-pedantic -isystem %S/Inputs %s
+
+int printf(const char *restrict, ...);
+
+typedef unsigned char uint8_t;
+
+void print_char_as_short() {
+ printf("%hu\n", (unsigned char)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'unsigned char'}}
+ printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'uint8_t' (aka 'unsigned char')}}
+}
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c
index 45bf26053a9..11acfcd1b9a 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -277,8 +277,8 @@ typedef unsigned char uint8_t;
void should_understand_small_integers() {
printf("%hhu", (short) 10); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
- printf("%hu\n", (unsigned char) 1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'unsigned char'}}
- printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'uint8_t'}}
+ printf("%hu\n", (unsigned char)1); // warning with -Wformat-pedantic only
+ printf("%hu\n", (uint8_t)1); // warning with -Wformat-pedantic only
}
void test11(void *p, char *s) {
OpenPOWER on IntegriCloud