[cfe-commits] r39438 - in /cfe/cfe/trunk: AST/SemaExpr.cpp Sema/SemaExpr.cpp
Steve Naroff
snaroff at apple.com
Wed Jul 11 09:44:24 PDT 2007
Author: snaroff
Date: Wed Jul 11 11:44:24 2007
New Revision: 39438
URL: http://llvm.org/viewvc/llvm-project?rev=39438&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Fix a couple bugs in ParseCallExpr().
- check isVariadic().
- make sure an AST isn't created if the number of args don't match but the
types do!
- rename "n" to something more descriptive:-)
Modified:
cfe/cfe/trunk/AST/SemaExpr.cpp
cfe/cfe/trunk/Sema/SemaExpr.cpp
Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39438&r1=39437&r2=39438&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:44:24 2007
@@ -296,7 +296,7 @@
/// locations.
Action::ExprResult Sema::
ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
- ExprTy **Args, unsigned NumArgs,
+ ExprTy **Args, unsigned NumArgsInCall,
SourceLocation *CommaLocs, SourceLocation RParenLoc) {
QualType qType = ((Expr *)Fn)->getType();
@@ -305,7 +305,7 @@
const FunctionType *funcT = dyn_cast<FunctionType>(qType.getCanonicalType());
assert(funcT && "ParseCallExpr(): not a function type");
-
+
// If a prototype isn't declared, the parser implicitly defines a func decl
QualType resultType = funcT->getResultType();
@@ -314,16 +314,17 @@
// assignment, to the types of the corresponding parameter, ...
unsigned NumArgsInProto = proto->getNumArgs();
- unsigned n = NumArgs;
+ unsigned NumArgsToCheck = NumArgsInCall;
- if (NumArgs < NumArgsInProto)
+ if (NumArgsInCall < NumArgsInProto)
Diag(LParenLoc, diag::ext_typecheck_call_too_few_args);
- else if (NumArgs > NumArgsInProto) { // FIXME: check isVariadic()...
- Diag(LParenLoc, diag::ext_typecheck_call_too_many_args);
- n = NumArgsInProto;
+ else if (NumArgsInCall > NumArgsInProto) {
+ if (!proto->isVariadic())
+ Diag(LParenLoc, diag::ext_typecheck_call_too_many_args);
+ NumArgsToCheck = NumArgsInProto;
}
// Continue to check argument types (even if we have too few/many args).
- for (unsigned i = 0; i < n; i++) {
+ for (unsigned i = 0; i < NumArgsToCheck; i++) {
QualType lhsType = proto->getArgType(i);
QualType rhsType = ((Expr **)Args)[i]->getType();
@@ -356,8 +357,11 @@
return Diag(l, diag::err_typecheck_passing_incompatible, utostr(i+1));
}
}
+ // Even if the types checked, bail if we had the wrong number of arguments.
+ if ((NumArgsInCall != NumArgsInProto) && !proto->isVariadic())
+ return true;
}
- return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgs, resultType);
+ return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgsInCall, resultType);
}
Action::ExprResult Sema::
Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39438&r1=39437&r2=39438&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:44:24 2007
@@ -296,7 +296,7 @@
/// locations.
Action::ExprResult Sema::
ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
- ExprTy **Args, unsigned NumArgs,
+ ExprTy **Args, unsigned NumArgsInCall,
SourceLocation *CommaLocs, SourceLocation RParenLoc) {
QualType qType = ((Expr *)Fn)->getType();
@@ -305,7 +305,7 @@
const FunctionType *funcT = dyn_cast<FunctionType>(qType.getCanonicalType());
assert(funcT && "ParseCallExpr(): not a function type");
-
+
// If a prototype isn't declared, the parser implicitly defines a func decl
QualType resultType = funcT->getResultType();
@@ -314,16 +314,17 @@
// assignment, to the types of the corresponding parameter, ...
unsigned NumArgsInProto = proto->getNumArgs();
- unsigned n = NumArgs;
+ unsigned NumArgsToCheck = NumArgsInCall;
- if (NumArgs < NumArgsInProto)
+ if (NumArgsInCall < NumArgsInProto)
Diag(LParenLoc, diag::ext_typecheck_call_too_few_args);
- else if (NumArgs > NumArgsInProto) { // FIXME: check isVariadic()...
- Diag(LParenLoc, diag::ext_typecheck_call_too_many_args);
- n = NumArgsInProto;
+ else if (NumArgsInCall > NumArgsInProto) {
+ if (!proto->isVariadic())
+ Diag(LParenLoc, diag::ext_typecheck_call_too_many_args);
+ NumArgsToCheck = NumArgsInProto;
}
// Continue to check argument types (even if we have too few/many args).
- for (unsigned i = 0; i < n; i++) {
+ for (unsigned i = 0; i < NumArgsToCheck; i++) {
QualType lhsType = proto->getArgType(i);
QualType rhsType = ((Expr **)Args)[i]->getType();
@@ -356,8 +357,11 @@
return Diag(l, diag::err_typecheck_passing_incompatible, utostr(i+1));
}
}
+ // Even if the types checked, bail if we had the wrong number of arguments.
+ if ((NumArgsInCall != NumArgsInProto) && !proto->isVariadic())
+ return true;
}
- return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgs, resultType);
+ return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgsInCall, resultType);
}
Action::ExprResult Sema::
More information about the cfe-commits
mailing list