summaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2019-09-18 19:05:14 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2019-09-18 19:05:14 +0000
commit7a6d9c12018b01e8d97ccb88367f24d7f38351cc (patch)
tree59c3b6a222dfe7452c9ee64fb42c794bb4884fb7 /lib/Sema
parentda7c99cf283cf1773550f372cb50d3320db77e92 (diff)
downloadclang-7a6d9c12018b01e8d97ccb88367f24d7f38351cc.tar.gz
[Sema] Suppress -Wformat diagnostics for bool types when printed using %hhd
Also, add a diagnostic under -Wformat for printing a boolean value as a character. rdar://54579473 Differential revision: https://reviews.llvm.org/D66856 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372247 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/SemaChecking.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index c7639b4a40..af69c231f1 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -8109,6 +8109,22 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
ExprTy = TET->getUnderlyingExpr()->getType();
}
+ // Diagnose attempts to print a boolean value as a character. Unlike other
+ // -Wformat diagnostics, this is fine from a type perspective, but it still
+ // doesn't make sense.
+ if (FS.getConversionSpecifier().getKind() == ConversionSpecifier::cArg &&
+ E->isKnownToHaveBooleanValue()) {
+ const CharSourceRange &CSR =
+ getSpecifierRange(StartSpecifier, SpecifierLen);
+ SmallString<4> FSString;
+ llvm::raw_svector_ostream os(FSString);
+ FS.toString(os);
+ EmitFormatDiagnostic(S.PDiag(diag::warn_format_bool_as_character)
+ << FSString,
+ E->getExprLoc(), false, CSR);
+ return true;
+ }
+
const analyze_printf::ArgType::MatchKind Match =
AT.matchesType(S.Context, ExprTy);
bool Pedantic = Match == analyze_printf::ArgType::NoMatchPedantic;