]> granicus.if.org Git - clang/commitdiff
simplify some code.
authorChris Lattner <sabre@nondot.org>
Thu, 20 Dec 2007 00:05:45 +0000 (00:05 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 20 Dec 2007 00:05:45 +0000 (00:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45235 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaChecking.cpp
Sema/SemaExpr.cpp

index 8bb263e84ee4d56abca11ce007a530d35c5a7456..46afe7fea9b45155f9153c58601cc567ab685ca5 100644 (file)
@@ -125,6 +125,8 @@ bool Sema::CheckBuiltinCFStringArgument(Expr* Arg) {
   return false;
 }
 
+/// SemaBuiltinVAStart - Check the arguments to __builtin_va_start for validity.
+/// Emit an error and return true on failure, return false on success.
 bool Sema::SemaBuiltinVAStart(Expr *Fn, Expr** Args, unsigned NumArgs) {
   if (NumArgs > 2) {
     Diag(Args[2]->getLocStart(), 
@@ -133,14 +135,15 @@ bool Sema::SemaBuiltinVAStart(Expr *Fn, Expr** Args, unsigned NumArgs) {
     return true;
   }
   
-  FunctionTypeProto *Proto;
+  // Determine whether the current function is variadic or not.
+  bool isVariadic;
   if (CurFunctionDecl)
-    Proto = cast<FunctionTypeProto>(CurFunctionDecl->getType());
+    isVariadic =
+      cast<FunctionTypeProto>(CurFunctionDecl->getType())->isVariadic();
   else
-    Proto =
-      cast<FunctionTypeProto>(ObjcGetTypeForMethodDefinition(CurMethodDecl));
+    isVariadic = CurMethodDecl->isVariadic();
   
-  if (!Proto->isVariadic()) {
+  if (!isVariadic) {
     Diag(Fn->getLocStart(), diag::err_va_start_used_in_non_variadic_function);
     return true;
   }
index 8ca2879b005bb4d04ef09d37b8a1b06ccbf70831..9ae52551550d8b70698bb26bd082d3be89fc370a 100644 (file)
@@ -680,8 +680,13 @@ ActOnCallExpr(ExprTy *fn, SourceLocation LParenLoc,
   if (ImplicitCastExpr *IcExpr = dyn_cast<ImplicitCastExpr>(Fn))
     if (DeclRefExpr *DRExpr = dyn_cast<DeclRefExpr>(IcExpr->getSubExpr()))
       if (FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRExpr->getDecl()))
-        if (CheckFunctionCall(Fn, RParenLoc, FDecl, Args, NumArgsInCall))
+        if (CheckFunctionCall(Fn, RParenLoc, FDecl, Args, NumArgsInCall)) {
+          // Function rejected, delete sub-ast's.
+          delete Fn;
+          for (unsigned i = 0; i != NumArgsInCall; ++i)
+            delete Args[i];
           return true;
+        }
 
   return new CallExpr(Fn, Args, NumArgsInCall, resultType, RParenLoc);
 }