]> granicus.if.org Git - clang/commitdiff
various cleanups. Use IgnoreParenCasts instead of inlined versions.
authorChris Lattner <sabre@nondot.org>
Fri, 28 Dec 2007 05:38:24 +0000 (05:38 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 28 Dec 2007 05:38:24 +0000 (05:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45382 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaChecking.cpp
Sema/SemaUtil.h

index d7b8de2f1597a6d6a2e89369433b45a4fa4cca9b..29d4e79814980f3c1e9f1ef1a1c80c4557320687 100644 (file)
@@ -88,15 +88,7 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) {
 /// CheckBuiltinCFStringArgument - Checks that the argument to the builtin
 /// CFString constructor is correct
 bool Sema::CheckBuiltinCFStringArgument(Expr* Arg) {
-  // FIXME: This should go in a helper.
-  while (1) {
-    if (ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
-      Arg = PE->getSubExpr();
-    else if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg))
-      Arg = ICE->getSubExpr();
-    else
-      break;
-  }
+  Arg = IgnoreParenCasts(Arg);
   
   StringLiteral *Literal = dyn_cast<StringLiteral>(Arg);
 
@@ -265,16 +257,7 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
     return;
   }
   
-  Expr *OrigFormatExpr = TheCall->getArg(format_idx);
-  // FIXME: This should go in a helper.
-  while (1) {
-    if (ParenExpr *PE = dyn_cast<ParenExpr>(OrigFormatExpr))
-      OrigFormatExpr = PE->getSubExpr();
-    else if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(OrigFormatExpr))
-      OrigFormatExpr = ICE->getSubExpr();
-    else
-      break;
-  }
+  Expr *OrigFormatExpr = IgnoreParenCasts(TheCall->getArg(format_idx));
   
   // CHECK: format string is not a string literal.
   // 
@@ -284,7 +267,6 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
   // the compiler and thereby (2) can practically remove the source of
   // many format string exploits.
   StringLiteral *FExpr = dyn_cast<StringLiteral>(OrigFormatExpr);
-  
   if (FExpr == NULL) {
     // For vprintf* functions (i.e., HasVAListArg==true), we add a
     // special check to see if the format string is a function parameter
@@ -305,8 +287,8 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
     //    if the argument is a DeclRefExpr that references a parameter.  We'll
     //    add proper support for checking the attribute later.
     if (HasVAListArg)
-      if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(IgnoreParen(OrigFormatExpr)))
-          if (isa<ParmVarDecl>(DR->getDecl()))
+      if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(OrigFormatExpr))
+        if (isa<ParmVarDecl>(DR->getDecl()))
           return;
     
     Diag(TheCall->getArg(format_idx)->getLocStart(), 
@@ -358,7 +340,7 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
   unsigned LastConversionIdx = 0;
   
   for (; StrIdx < StrLen; ++StrIdx) {
-
+    
     // Is the number of detected conversion conversions greater than
     // the number of matching data arguments?  If so, stop.
     if (!HasVAListArg && numConversions > numDataArgs) break;
@@ -367,10 +349,8 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
     if (Str[StrIdx] == '\0') {
       // The string returned by getStrData() is not null-terminated,
       // so the presence of a null character is likely an error.
-      SourceLocation Loc = FExpr->getLocStart();
-      Loc = PP.AdvanceToTokenCharacter(Loc, StrIdx+1);
-    
-      Diag(Loc, diag::warn_printf_format_string_contains_null_char,
+      Diag(PP.AdvanceToTokenCharacter(FExpr->getLocStart(), StrIdx+1),
+           diag::warn_printf_format_string_contains_null_char,
            Fn->getSourceRange());
       return;
     }
@@ -391,7 +371,6 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
       ++numConversions;
       
       if (!HasVAListArg && numConversions > numDataArgs) {
-        
         SourceLocation Loc = FExpr->getLocStart();
         Loc = PP.AdvanceToTokenCharacter(Loc, StrIdx+1);
 
@@ -489,7 +468,6 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
         LastConversionIdx = StrIdx;
         ++numConversions;
       }
-      
       break;
               
     default:
index 2932862e91f68e5c96f4ce425f4bcc51cd39c42c..b167346fb49ee4fb22d5c7f3204abbc2f6bc3f7b 100644 (file)
@@ -38,10 +38,8 @@ static inline Expr* IgnoreParenCasts(Expr* E) {
     else if (ImplicitCastExpr* P = dyn_cast<ImplicitCastExpr>(E))
       E = P->getSubExpr();
     else
-      break;
+      return E;
   }
-  
-  return E;
 }
 
 /// Utility method to determine if a CallExpr is a call to a builtin.