summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Analysis/FormatString.cpp25
-rw-r--r--clang/lib/Analysis/PrintfFormatString.cpp33
-rw-r--r--clang/lib/Sema/SemaChecking.cpp2
3 files changed, 19 insertions, 41 deletions
diff --git a/clang/lib/Analysis/FormatString.cpp b/clang/lib/Analysis/FormatString.cpp
index 0171bb7aec3..6498ded4e37 100644
--- a/clang/lib/Analysis/FormatString.cpp
+++ b/clang/lib/Analysis/FormatString.cpp
@@ -230,8 +230,7 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const {
case SpecificTy: {
argTy = C.getCanonicalType(argTy).getUnqualifiedType();
- QualType U = C.getCanonicalType(T);
- if (U == argTy)
+ if (T == argTy)
return true;
// Check for "compatible types".
if (const BuiltinType *BT = argTy->getAs<BuiltinType>())
@@ -240,26 +239,26 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const {
break;
case BuiltinType::Char_S:
case BuiltinType::SChar:
- return U == C.UnsignedCharTy;
+ return T == C.UnsignedCharTy;
case BuiltinType::Char_U:
case BuiltinType::UChar:
- return U == C.SignedCharTy;
+ return T == C.SignedCharTy;
case BuiltinType::Short:
- return U == C.UnsignedShortTy;
+ return T == C.UnsignedShortTy;
case BuiltinType::UShort:
- return U == C.ShortTy;
+ return T == C.ShortTy;
case BuiltinType::Int:
- return U == C.UnsignedIntTy;
+ return T == C.UnsignedIntTy;
case BuiltinType::UInt:
- return U == C.IntTy;
+ return T == C.IntTy;
case BuiltinType::Long:
- return U == C.UnsignedLongTy;
+ return T == C.UnsignedLongTy;
case BuiltinType::ULong:
- return U == C.LongTy;
+ return T == C.LongTy;
case BuiltinType::LongLong:
- return U == C.UnsignedLongLongTy;
+ return T == C.UnsignedLongLongTy;
case BuiltinType::ULongLong:
- return U == C.LongLongTy;
+ return T == C.LongLongTy;
}
return false;
}
@@ -486,3 +485,5 @@ bool FormatSpecifier::hasValidLengthModifier() const {
}
return false;
}
+
+
diff --git a/clang/lib/Analysis/PrintfFormatString.cpp b/clang/lib/Analysis/PrintfFormatString.cpp
index e3d76507cd9..70dbfd30cee 100644
--- a/clang/lib/Analysis/PrintfFormatString.cpp
+++ b/clang/lib/Analysis/PrintfFormatString.cpp
@@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//
#include "clang/Analysis/Analyses/FormatString.h"
-#include "clang/Sema/Sema.h"
#include "FormatStringParsing.h"
using clang::analyze_format_string::ArgTypeResult;
@@ -279,27 +278,8 @@ const char *ConversionSpecifier::toString() const {
// Methods on PrintfSpecifier.
//===----------------------------------------------------------------------===//
-/// \brief Try to find and return a typedef type named Name whose actual type
-/// is Underlying. Return Underlying if such a typedef cannot be found.
-static QualType FindTypedef(Sema &S, const char *Name, QualType Underlying) {
- ASTContext &Ctx = S.getASTContext();
- IdentifierInfo &II = Ctx.Idents.get(Name);
-
- NamedDecl *D = S.LookupSingleName(S.getCurScope(), DeclarationName(&II),
- SourceLocation(), Sema::LookupOrdinaryName);
-
- if (TypedefDecl *TD = dyn_cast_or_null<TypedefDecl>(D)) {
- QualType TypedefType = Ctx.getTypedefType(TD, QualType());
- if (Ctx.getCanonicalType(TypedefType) == Underlying)
- return TypedefType;
- }
-
- return Underlying;
-}
-
-ArgTypeResult PrintfSpecifier::getArgType(Sema &S) const {
+ArgTypeResult PrintfSpecifier::getArgType(ASTContext &Ctx) const {
const PrintfConversionSpecifier &CS = getConversionSpecifier();
- ASTContext &Ctx = S.getASTContext();
if (!CS.consumesDataArgument())
return ArgTypeResult::Invalid();
@@ -321,13 +301,11 @@ ArgTypeResult PrintfSpecifier::getArgType(Sema &S) const {
case LengthModifier::AsShort: return Ctx.ShortTy;
case LengthModifier::AsLong: return Ctx.LongTy;
case LengthModifier::AsLongLong: return Ctx.LongLongTy;
- case LengthModifier::AsIntMax:
- return FindTypedef(S, "intmax_t", Ctx.getIntMaxType());
+ case LengthModifier::AsIntMax: return Ctx.getIntMaxType();
case LengthModifier::AsSizeT:
// FIXME: How to get the corresponding signed version of size_t?
return ArgTypeResult();
- case LengthModifier::AsPtrDiff:
- return FindTypedef(S, "ptrdiff_t", Ctx.getPointerDiffType());
+ case LengthModifier::AsPtrDiff: return Ctx.getPointerDiffType();
}
if (CS.isUIntArg())
@@ -339,10 +317,9 @@ ArgTypeResult PrintfSpecifier::getArgType(Sema &S) const {
case LengthModifier::AsShort: return Ctx.UnsignedShortTy;
case LengthModifier::AsLong: return Ctx.UnsignedLongTy;
case LengthModifier::AsLongLong: return Ctx.UnsignedLongLongTy;
- case LengthModifier::AsIntMax:
- return FindTypedef(S, "uintmax_t", Ctx.getUIntMaxType());
+ case LengthModifier::AsIntMax: return Ctx.getUIntMaxType();
case LengthModifier::AsSizeT:
- return FindTypedef(S, "size_t", Ctx.getSizeType());
+ return Ctx.getSizeType();
case LengthModifier::AsPtrDiff:
// FIXME: How to get the corresponding unsigned
// version of ptrdiff_t?
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c0d6702b589..0d640a8c123 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2206,7 +2206,7 @@ CheckPrintfHandler::HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier
// Now type check the data expression that matches the
// format specifier.
const Expr *Ex = getDataArg(argIndex);
- const analyze_printf::ArgTypeResult &ATR = FS.getArgType(S);
+ const analyze_printf::ArgTypeResult &ATR = FS.getArgType(S.Context);
if (ATR.isValid() && !ATR.matchesType(S.Context, Ex->getType())) {
// Check if we didn't match because of an implicit cast from a 'char'
// or 'short' to an 'int'. This is done because printf is a varargs
OpenPOWER on IntegriCloud