aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/FormatString.cpp11
-rw-r--r--lib/Analysis/PrintfFormatString.cpp11
-rw-r--r--lib/Sema/SemaChecking.cpp6
3 files changed, 19 insertions, 9 deletions
diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp
index 6498ded4e3..0853164df7 100644
--- a/lib/Analysis/FormatString.cpp
+++ b/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/lib/Analysis/PrintfFormatString.cpp b/lib/Analysis/PrintfFormatString.cpp
index 70dbfd30ce..e14c952292 100644
--- a/lib/Analysis/PrintfFormatString.cpp
+++ b/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?
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 869922faf4..f635afcc30 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -2014,7 +2014,7 @@ bool CheckPrintfHandler::HandleAmount(
if (!ATR.matchesType(S.Context, T)) {
EmitFormatDiagnostic(S.PDiag(diag::warn_printf_asterisk_wrong_type)
- << k << ATR.getRepresentativeType(S.Context)
+ << k << ATR.getRepresentativeTypeName(S.Context)
<< T << Arg->getSourceRange(),
getLocationOfByte(Amt.getStart()),
/*IsStringLocation*/true,
@@ -2234,7 +2234,7 @@ CheckPrintfHandler::HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier
// type is 'wint_t' (which is defined in the system headers).
EmitFormatDiagnostic(
S.PDiag(diag::warn_printf_conversion_argument_type_mismatch)
- << ATR.getRepresentativeType(S.Context) << Ex->getType()
+ << ATR.getRepresentativeTypeName(S.Context) << Ex->getType()
<< Ex->getSourceRange(),
getLocationOfByte(CS.getStart()),
/*IsStringLocation*/true,
@@ -2246,7 +2246,7 @@ CheckPrintfHandler::HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier
else {
S.Diag(getLocationOfByte(CS.getStart()),
diag::warn_printf_conversion_argument_type_mismatch)
- << ATR.getRepresentativeType(S.Context) << Ex->getType()
+ << ATR.getRepresentativeTypeName(S.Context) << Ex->getType()
<< getSpecifierRange(startSpecifier, specifierLen)
<< Ex->getSourceRange();
}