summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/PrintfFormatString.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-10-21 04:00:58 +0000
committerTed Kremenek <kremenek@apple.com>2010-10-21 04:00:58 +0000
commit12a37de0039f79649a2758f7c9d67e925ca8f4a3 (patch)
tree724c11b18e821ba2deb11dac323c52edd471d5ba /clang/lib/Analysis/PrintfFormatString.cpp
parent6377965efbaabdb2188aa58b2a444531538c871f (diff)
downloadbcm5719-llvm-12a37de0039f79649a2758f7c9d67e925ca8f4a3.tar.gz
bcm5719-llvm-12a37de0039f79649a2758f7c9d67e925ca8f4a3.zip
Previously, the printf warnings would say your arguments type was 'int' when it was really a 'char'
or a 'short'. This fixes that and allows the hints to suggest 'h' modifiers for small ints. Patch by Justin Bogner! llvm-svn: 116996
Diffstat (limited to 'clang/lib/Analysis/PrintfFormatString.cpp')
-rw-r--r--clang/lib/Analysis/PrintfFormatString.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Analysis/PrintfFormatString.cpp b/clang/lib/Analysis/PrintfFormatString.cpp
index b8c327cdeba..57399d8efef 100644
--- a/clang/lib/Analysis/PrintfFormatString.cpp
+++ b/clang/lib/Analysis/PrintfFormatString.cpp
@@ -382,6 +382,18 @@ bool PrintfSpecifier::fixType(QualType QT) {
LM.setKind(LengthModifier::None);
break;
+ case BuiltinType::Char_U:
+ case BuiltinType::UChar:
+ case BuiltinType::Char_S:
+ case BuiltinType::SChar:
+ LM.setKind(LengthModifier::AsChar);
+ break;
+
+ case BuiltinType::Short:
+ case BuiltinType::UShort:
+ LM.setKind(LengthModifier::AsShort);
+ break;
+
case BuiltinType::WChar:
case BuiltinType::Long:
case BuiltinType::ULong:
@@ -399,8 +411,10 @@ bool PrintfSpecifier::fixType(QualType QT) {
}
// Set conversion specifier and disable any flags which do not apply to it.
- if (QT->isAnyCharacterType()) {
+ // Let typedefs to char fall through to int, as %c is silly for uint8_t.
+ if (isa<TypedefType>(QT) && QT->isAnyCharacterType()) {
CS.setKind(ConversionSpecifier::cArg);
+ LM.setKind(LengthModifier::None);
Precision.setHowSpecified(OptionalAmount::NotSpecified);
HasAlternativeForm = 0;
HasLeadingZeroes = 0;
OpenPOWER on IntegriCloud