Skip to content

Commit 8b4a0ac

Browse files
committed
[clang] Don't crash when -Wformat-sgnedness specified
1 parent b716d35 commit 8b4a0ac

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ Bug Fixes in This Version
366366
- Fixed an assertion when an improper use of the ``malloc`` attribute targeting
367367
a function without arguments caused us to try to access a non-existent argument.
368368
(#GH159080)
369+
- Fixed clang crash that caused by missing diagnostic argument. (#GH161072)
369370

370371
Bug Fixes to Compiler Builtins
371372
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -417,6 +418,7 @@ Bug Fixes to C++ Support
417418
``__builtin_addressof``, and related issues with builtin arguments. (#GH154034)
418419
- Fix an assertion failure when taking the address on a non-type template parameter argument of
419420
object type. (#GH151531)
421+
- Fix an assertion failure of format string signedness check when ``-Wformat-signedness`` (#GH161075).
420422

421423
Bug Fixes to AST Handling
422424
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaChecking.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8634,8 +8634,10 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
86348634
case ArgType::Match:
86358635
case ArgType::MatchPromotion:
86368636
case ArgType::NoMatchPromotionTypeConfusion:
8637-
case ArgType::NoMatchSignedness:
86388637
llvm_unreachable("expected non-matching");
8638+
case ArgType::NoMatchSignedness:
8639+
Diag = diag::warn_format_conversion_argument_type_mismatch_signedness;
8640+
break;
86398641
case ArgType::NoMatchPedantic:
86408642
Diag = diag::warn_format_conversion_argument_type_mismatch_pedantic;
86418643
break;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -Wformat -Wformat-signedness %s
2+
// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -verify -Wformat -Wformat-signedness %s
3+
4+
// Verify that -Wformat-signedness alone (without -Wformat) trigger the
5+
// warnings. Note in gcc this will not trigger the signedness warnings as
6+
// -Wformat is default off in gcc.
7+
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -Wformat-signedness %s
8+
// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -verify -Wformat-signedness %s
9+
10+
// Verify that -Wformat-signedness warnings are not reported with only -Wformat
11+
// (gcc compat).
12+
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wformat -verify=okay %s
13+
14+
// Verify that -Wformat-signedness with -Wno-format are not reported (gcc compat).
15+
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wformat-signedness -Wno-format -verify=okay %s
16+
// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wno-format -Wformat-signedness -verify=okay %s
17+
// okay-no-diagnostics
18+
19+
// Ignore 'GCC requires a function with the 'format' attribute to be variadic'.
20+
#pragma GCC diagnostic ignored "-Wgcc-compat"
21+
namespace GH161075 {
22+
template <typename... Args>
23+
void format(const char *fmt, Args &&...args)
24+
__attribute__((format(printf, 1, 2)));
25+
26+
void do_format() {
27+
bool b = false;
28+
format("%hhi %hhu %hi %hu %i %u", b, b, b, b, b, b); // expected-warning {{format specifies type 'unsigned char' but the argument has type 'bool', which differs in signedness}}
29+
}
30+
} // namespace GH161075

0 commit comments

Comments
 (0)