diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-08-24 22:24:51 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-08-24 22:24:51 +0000 |
commit | 5f0c066062af99e6d147cafa99acdf016ea3afa4 (patch) | |
tree | f240becce2be7121e2167113cfcf06a12739bb2b /clang/lib/Analysis/FormatString.cpp | |
parent | e0fd5a9299d96568023d0685e1232cc8c03b325f (diff) | |
download | bcm5719-llvm-5f0c066062af99e6d147cafa99acdf016ea3afa4.tar.gz bcm5719-llvm-5f0c066062af99e6d147cafa99acdf016ea3afa4.zip |
Fix printf format string checking for '%lc' (which expects a wint_t or compatible argument). Fixes PR 7981.
llvm-svn: 111978
Diffstat (limited to 'clang/lib/Analysis/FormatString.cpp')
-rw-r--r-- | clang/lib/Analysis/FormatString.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/Analysis/FormatString.cpp b/clang/lib/Analysis/FormatString.cpp index a6cfba228e9..388b9d34a23 100644 --- a/clang/lib/Analysis/FormatString.cpp +++ b/clang/lib/Analysis/FormatString.cpp @@ -277,6 +277,23 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const { C.getCanonicalType(PT->getPointeeType()).getUnqualifiedType(); return pointeeTy == C.getWCharType(); } + + case WIntTy: { + // Instead of doing a lookup for the definition of 'wint_t' (which + // is defined by the system headers) instead see if wchar_t and + // the argument type promote to the same type. + QualType PromoWChar = + C.getWCharType()->isPromotableIntegerType() + ? C.getPromotedIntegerType(C.getWCharType()) : C.getWCharType(); + QualType PromoArg = + argTy->isPromotableIntegerType() + ? C.getPromotedIntegerType(argTy) : argTy; + + PromoWChar = C.getCanonicalType(PromoWChar).getUnqualifiedType(); + PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType(); + + return PromoWChar == PromoArg; + } case CPointerTy: return argTy->getAs<PointerType>() != NULL || @@ -308,6 +325,10 @@ QualType ArgTypeResult::getRepresentativeType(ASTContext &C) const { return C.ObjCBuiltinIdTy; case CPointerTy: return C.VoidPtrTy; + case WIntTy: { + QualType WC = C.getWCharType(); + return WC->isPromotableIntegerType() ? C.getPromotedIntegerType(WC) : WC; + } } // FIXME: Should be unreachable, but Clang is currently emitting |