[cfe-commits] r45235 - in /cfe/trunk/Sema: SemaChecking.cpp SemaExpr.cpp

Chris Lattner sabre at nondot.org
Wed Dec 19 16:05:46 PST 2007


Author: lattner
Date: Wed Dec 19 18:05:45 2007
New Revision: 45235

URL: http://llvm.org/viewvc/llvm-project?rev=45235&view=rev
Log:
simplify some code.

Modified:
    cfe/trunk/Sema/SemaChecking.cpp
    cfe/trunk/Sema/SemaExpr.cpp

Modified: cfe/trunk/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaChecking.cpp?rev=45235&r1=45234&r2=45235&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/Sema/SemaChecking.cpp Wed Dec 19 18:05:45 2007
@@ -125,6 +125,8 @@
   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 @@
     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;
   }

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=45235&r1=45234&r2=45235&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Dec 19 18:05:45 2007
@@ -680,8 +680,13 @@
   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);
 }





More information about the cfe-commits mailing list