diff options
author | Hans Wennborg <hans@hanshq.net> | 2011-12-07 10:33:11 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2011-12-07 10:33:11 +0000 |
commit | 772e9270f666afef722292b6aaf3791feb8fcc1f (patch) | |
tree | e457b5a164801eb7e81c3a5d014b11f463126556 /clang/lib/Analysis | |
parent | 1d578e8835282f5aac1d2fef3801e38c7a8fc870 (diff) | |
download | bcm5719-llvm-772e9270f666afef722292b6aaf3791feb8fcc1f.tar.gz bcm5719-llvm-772e9270f666afef722292b6aaf3791feb8fcc1f.zip |
Make printf warnings refer to intmax_t et al. by name
in addition to underlying type.
For example, the warning for printf("%zu", 42.0);
changes from "conversion specifies type 'unsigned long'" to "conversion
specifies type 'size_t' (aka 'unsigned long')"
(This is a second attempt after r145697, which got reverted.)
llvm-svn: 146032
Diffstat (limited to 'clang/lib/Analysis')
-rw-r--r-- | clang/lib/Analysis/FormatString.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Analysis/PrintfFormatString.cpp | 11 |
2 files changed, 16 insertions, 6 deletions
diff --git a/clang/lib/Analysis/FormatString.cpp b/clang/lib/Analysis/FormatString.cpp index 6498ded4e37..0853164df75 100644 --- a/clang/lib/Analysis/FormatString.cpp +++ b/clang/lib/Analysis/FormatString.cpp @@ -228,6 +228,7 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const { return false; } + case TypedefTy: case SpecificTy: { argTy = C.getCanonicalType(argTy).getUnqualifiedType(); if (T == argTy) @@ -331,6 +332,7 @@ QualType ArgTypeResult::getRepresentativeType(ASTContext &C) const { case AnyCharTy: return C.CharTy; case SpecificTy: + case TypedefTy: return T; case CStrTy: return C.getPointerType(C.CharTy); @@ -351,6 +353,13 @@ QualType ArgTypeResult::getRepresentativeType(ASTContext &C) const { return QualType(); } +std::string ArgTypeResult::getRepresentativeTypeName(ASTContext &C) const { + if (K != TypedefTy) + return std::string("'") + getRepresentativeType(C).getAsString() + "'"; + return std::string("'") + Name + "' (aka '" + T.getAsString() + "')"; +} + + //===----------------------------------------------------------------------===// // Methods on OptionalAmount. //===----------------------------------------------------------------------===// @@ -485,5 +494,3 @@ bool FormatSpecifier::hasValidLengthModifier() const { } return false; } - - diff --git a/clang/lib/Analysis/PrintfFormatString.cpp b/clang/lib/Analysis/PrintfFormatString.cpp index 70dbfd30cee..e14c9522925 100644 --- a/clang/lib/Analysis/PrintfFormatString.cpp +++ b/clang/lib/Analysis/PrintfFormatString.cpp @@ -301,11 +301,13 @@ ArgTypeResult PrintfSpecifier::getArgType(ASTContext &Ctx) const { case LengthModifier::AsShort: return Ctx.ShortTy; case LengthModifier::AsLong: return Ctx.LongTy; case LengthModifier::AsLongLong: return Ctx.LongLongTy; - case LengthModifier::AsIntMax: return Ctx.getIntMaxType(); + case LengthModifier::AsIntMax: + return ArgTypeResult(Ctx.getIntMaxType(), "intmax_t"); case LengthModifier::AsSizeT: // FIXME: How to get the corresponding signed version of size_t? return ArgTypeResult(); - case LengthModifier::AsPtrDiff: return Ctx.getPointerDiffType(); + case LengthModifier::AsPtrDiff: + return ArgTypeResult(Ctx.getPointerDiffType(), "ptrdiff_t"); } if (CS.isUIntArg()) @@ -317,9 +319,10 @@ ArgTypeResult PrintfSpecifier::getArgType(ASTContext &Ctx) const { case LengthModifier::AsShort: return Ctx.UnsignedShortTy; case LengthModifier::AsLong: return Ctx.UnsignedLongTy; case LengthModifier::AsLongLong: return Ctx.UnsignedLongLongTy; - case LengthModifier::AsIntMax: return Ctx.getUIntMaxType(); + case LengthModifier::AsIntMax: + return ArgTypeResult(Ctx.getUIntMaxType(), "uintmax_t"); case LengthModifier::AsSizeT: - return Ctx.getSizeType(); + return ArgTypeResult(Ctx.getSizeType(), "size_t"); case LengthModifier::AsPtrDiff: // FIXME: How to get the corresponding unsigned // version of ptrdiff_t? |