On bogus code like this:

int *P2;
  P2(1, 2, 3);

  register short X;
  X();

emit:

ds.c:10:3: error: called object is not a function or function pointer
  P2(1, 2, 3);
  ^~~~~~~~~~~
ds.c:13:3: error: called object is not a function or function pointer
  X();
  ^~~

instead of aborting.

llvm-svn: 39599
This commit is contained in:
Chris Lattner 2007-06-06 05:14:05 +00:00
parent 3343f81a25
commit 3d01e4eacb
2 changed files with 16 additions and 2 deletions

View File

@ -367,10 +367,22 @@ ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
QualType qType = UsualUnaryConversions(funcExpr->getType());
assert(!qType.isNull() && "no type for function call expression");
const PointerType *PT = dyn_cast<PointerType>(qType.getCanonicalType());
// C99 6.5.2.2p1 - "The expression that denotes the called function shall have
// type pointer to function".
const PointerType *PT = dyn_cast<PointerType>(qType);
if (PT == 0) PT = dyn_cast<PointerType>(qType.getCanonicalType());
if (PT == 0)
return Diag(funcExpr->getLocStart(), diag::err_typecheck_call_not_function,
SourceRange(funcExpr->getLocStart(), RParenLoc));
const FunctionType *funcT = dyn_cast<FunctionType>(PT->getPointeeType());
assert(funcT && "ParseCallExpr(): not a function type");
if (funcT == 0)
funcT = dyn_cast<FunctionType>(PT->getPointeeType().getCanonicalType());
if (funcT == 0)
return Diag(funcExpr->getLocStart(), diag::err_typecheck_call_not_function,
SourceRange(funcExpr->getLocStart(), RParenLoc));
// If a prototype isn't declared, the parser implicitly defines a func decl
QualType resultType = funcT->getResultType();

View File

@ -590,6 +590,8 @@ DIAG(err_typecheck_expression_not_modifiable_lvalue, ERROR,
"expression is not assignable")
DIAG(err_typecheck_incomplete_type_not_modifiable_lvalue, ERROR,
"incomplete type '%0' is not assignable")
DIAG(err_typecheck_call_not_function, ERROR,
"called object is not a function or function pointer")
DIAG(err_typecheck_call_too_few_args, ERROR,
"too few arguments to function")
DIAG(err_typecheck_call_too_many_args, ERROR,