[cfe-commits] r39599 - in /cfe/cfe/trunk: Sema/SemaExpr.cpp include/clang/Basic/DiagnosticKinds.def

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:46:06 PDT 2007


Author: clattner
Date: Wed Jul 11 11:46:06 2007
New Revision: 39599

URL: http://llvm.org/viewvc/llvm-project?rev=39599&view=rev
Log:
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.

Modified:
    cfe/cfe/trunk/Sema/SemaExpr.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:46:06 2007
@@ -367,10 +367,22 @@
   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();

Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39599&r1=39598&r2=39599&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:46:06 2007
@@ -590,6 +590,8 @@
      "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,





More information about the cfe-commits mailing list