forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sema] Implement support for -Wformat-signedness (llvm#74440)
In gcc there exist a modifier option -Wformat-signedness that turns on additional signedness warnings in the already existing -Wformat warning. This patch implements that support in clang. This is done by adding a dummy warning diag::warn_format_conversion_argument_type_mismatch_signedness that is never emitted and only used as an option to toggle the signedness warning in -Wformat. This will ensure gcc compatibility.
- Loading branch information
Showing
8 changed files
with
379 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// RUN: cp %s %t | ||
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wformat -Wformat-signedness -fixit %t | ||
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wformat -Wformat-signedness -Werror %t | ||
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -E -o - %t | FileCheck %s | ||
|
||
#include <limits.h> | ||
|
||
int printf(const char *restrict format, ...); | ||
|
||
void test_printf_int(int x) | ||
{ | ||
printf("%u", x); | ||
} | ||
|
||
void test_printf_unsigned(unsigned x) | ||
{ | ||
printf("%d", x); | ||
} | ||
|
||
void test_printf_long(long x) | ||
{ | ||
printf("%lu", x); | ||
} | ||
|
||
void test_printf_unsigned_long(unsigned long x) | ||
{ | ||
printf("%ld", x); | ||
} | ||
|
||
void test_printf_long_long(long long x) | ||
{ | ||
printf("%llu", x); | ||
} | ||
|
||
void test_printf_unsigned_long_long(unsigned long long x) | ||
{ | ||
printf("%lld", x); | ||
} | ||
|
||
enum enum_int { | ||
minus_1 = -1 | ||
}; | ||
|
||
void test_printf_enum_int(enum enum_int x) | ||
{ | ||
printf("%u", x); | ||
} | ||
|
||
enum enum_unsigned { | ||
zero = 0 | ||
}; | ||
|
||
void test_printf_enum_unsigned(enum enum_unsigned x) | ||
{ | ||
printf("%d", x); | ||
} | ||
|
||
enum enum_long { | ||
minus_one = -1, | ||
int_val = INT_MAX, | ||
unsigned_val = (unsigned)INT_MIN | ||
}; | ||
|
||
void test_printf_enum_long(enum enum_long x) | ||
{ | ||
printf("%lu", x); | ||
} | ||
|
||
enum enum_unsigned_long { | ||
uint_max_plus = (unsigned long)UINT_MAX+1, | ||
}; | ||
|
||
void test_printf_enum_unsigned_long(enum enum_unsigned_long x) | ||
{ | ||
printf("%ld", x); | ||
} | ||
|
||
// Validate the fixes. | ||
// CHECK: void test_printf_int(int x) | ||
// CHECK: printf("%d", x); | ||
// CHECK: void test_printf_unsigned(unsigned x) | ||
// CHECK: printf("%u", x); | ||
// CHECK: void test_printf_long(long x) | ||
// CHECK: printf("%ld", x); | ||
// CHECK: void test_printf_unsigned_long(unsigned long x) | ||
// CHECK: printf("%lu", x); | ||
// CHECK: void test_printf_long_long(long long x) | ||
// CHECK: printf("%lld", x); | ||
// CHECK: void test_printf_unsigned_long_long(unsigned long long x) | ||
// CHECK: printf("%llu", x); | ||
// CHECK: void test_printf_enum_int(enum enum_int x) | ||
// CHECK: printf("%d", x); | ||
// CHECK: void test_printf_enum_unsigned(enum enum_unsigned x) | ||
// CHECK: printf("%u", x); | ||
// CHECK: void test_printf_enum_long(enum enum_long x) | ||
// CHECK: printf("%ld", x); | ||
// CHECK: void test_printf_enum_unsigned_long(enum enum_unsigned_long x) | ||
// CHECK: printf("%lu", x); |
Oops, something went wrong.