From 392da48160bd92ceb486792780467cbfdb2d0e8c Mon Sep 17 00:00:00 2001 From: James Molloy Date: Fri, 4 May 2012 10:55:22 +0000 Subject: Fix handling of wint_t - we can't assume wint_t is purely an integer promotion of wchar_t - they may differ in signedness. Teach ASTContext about WIntType, and have it taken from TargetInfo like WCharType. Should fix test/Sema/format-strings.c for ARM, with the exception of one subtest which will fail if wint_t and wchar_t are the same size and wint_t is signed, wchar_t is unsigned. There'll be a followup commit to fix that. Reviewed by Chandler and Hans at http://llvm.org/reviews/r/8 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156165 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/FormatString.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/Analysis/FormatString.cpp') diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp index ba45865af8..ab69c06911 100644 --- a/lib/Analysis/FormatString.cpp +++ b/lib/Analysis/FormatString.cpp @@ -319,20 +319,21 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const { } 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(); + QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType(); PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType(); - return PromoWChar == PromoArg; + // If the promoted argument is the corresponding signed type of the + // wint_t type, then it should match. + if (PromoArg->hasSignedIntegerRepresentation() && + C.getCorrespondingUnsignedType(PromoArg) == WInt) + return true; + + return WInt == PromoArg; } case CPointerTy: @@ -380,8 +381,7 @@ QualType ArgTypeResult::getRepresentativeType(ASTContext &C) const { case CPointerTy: return C.VoidPtrTy; case WIntTy: { - QualType WC = C.getWCharType(); - return WC->isPromotableIntegerType() ? C.getPromotedIntegerType(WC) : WC; + return C.getWIntType(); } } -- cgit v1.2.3