From 6edb029026d290f12393ed8389a3e1de596c77ec Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 25 Mar 2013 22:28:37 +0000 Subject: [PATCH] For printf checking, handle nested typedefs for darwin-specific checking. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177931 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 6 +++++- test/FixIt/format-darwin.m | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index cfce85eef0..4e11b3aa79 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -2803,7 +2803,9 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS, // casts to primitive types that are known to be large enough. bool ShouldNotPrintDirectly = false; if (S.Context.getTargetInfo().getTriple().isOSDarwin()) { - if (const TypedefType *UserTy = IntendedTy->getAs()) { + // Use a 'while' to peel off layers of typedefs. + QualType TyTy = IntendedTy; + while (const TypedefType *UserTy = TyTy->getAs()) { StringRef Name = UserTy->getDecl()->getName(); QualType CastTy = llvm::StringSwitch(Name) .Case("NSInteger", S.Context.LongTy) @@ -2815,7 +2817,9 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS, if (!CastTy.isNull()) { ShouldNotPrintDirectly = true; IntendedTy = CastTy; + break; } + TyTy = UserTy->desugar(); } } diff --git a/test/FixIt/format-darwin.m b/test/FixIt/format-darwin.m index cfaac29e90..79a3b388e7 100644 --- a/test/FixIt/format-darwin.m +++ b/test/FixIt/format-darwin.m @@ -23,6 +23,8 @@ typedef long SInt32; typedef unsigned long UInt32; #endif +typedef SInt32 OSStatus; + NSInteger getNSInteger(); NSUInteger getNSUInteger(); SInt32 getSInt32(); @@ -210,3 +212,9 @@ void testCapitals() { // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:13-[[@LINE-3]]:14}:"d" // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:14}:"%D" } + +void testLayeredTypedefs(OSStatus i) { + printf("%s", i); // expected-warning {{values of type 'OSStatus' should not be used as format arguments}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"d" +} + -- 2.40.0