[cfe-commits] r67485 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaCXX/enum.cpp

Eli Friedman eli.friedman at gmail.com
Sun Mar 22 15:00:51 PDT 2009


Author: efriedma
Date: Sun Mar 22 17:00:50 2009
New Revision: 67485

URL: http://llvm.org/viewvc/llvm-project?rev=67485&view=rev
Log:
Check that the return/argument types of calls are complete.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/enum.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Sun Mar 22 17:00:50 2009
@@ -1174,6 +1174,10 @@
      "variable is not assignable (missing __block type specifier)")
 DIAG(err_typecheck_call_not_function, ERROR,
      "called object type %0 is not a function or function pointer")
+DIAG(err_call_incomplete_return, ERROR,
+     "return type of called function (%0) is incomplete")
+DIAG(err_call_incomplete_argument, ERROR,
+     "argument type %0 is incomplete")
 DIAG(err_typecheck_call_too_few_args, ERROR,
      "too few arguments to %select{function|block|method}0 call")
 DIAG(err_typecheck_call_too_many_args, ERROR,

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67485&r1=67484&r2=67485&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Mar 22 17:00:50 2009
@@ -1118,6 +1118,10 @@
   "variable is not assignable (missing __block type specifier)">;
 def err_typecheck_call_not_function : Error<
   "called object type %0 is not a function or function pointer">;
+def err_call_incomplete_return : Error<
+  "return type of called function (%0) is incomplete">;
+def err_call_incomplete_argument : Error<
+  "argument type %0 is incomplete">;
 def err_typecheck_call_too_few_args : Error<
   "too few arguments to %select{function|block|method}0 call">;
 def err_typecheck_call_too_many_args : Error<

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Mar 22 17:00:50 2009
@@ -2161,6 +2161,12 @@
     if (i < NumArgs) {
       Arg = Args[i];
 
+      if (RequireCompleteType(Arg->getSourceRange().getBegin(),
+                              ProtoArgType,
+                              diag::err_call_incomplete_argument,
+                              Arg->getSourceRange()))
+        return true;
+
       // Pass the argument.
       if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
         return true;
@@ -2331,6 +2337,14 @@
     return ExprError(Diag(LParenLoc, diag::err_typecheck_call_not_function)
       << Fn->getType() << Fn->getSourceRange());
 
+  // Check for a valid return type
+  if (!FuncT->getResultType()->isVoidType() &&
+      RequireCompleteType(Fn->getSourceRange().getBegin(),
+                          FuncT->getResultType(),
+                          diag::err_call_incomplete_return,
+                          TheCall->getSourceRange()))
+    return ExprError();
+
   // We know the result type of the call, set it.
   TheCall->setType(FuncT->getResultType().getNonReferenceType());
 
@@ -2345,6 +2359,11 @@
     for (unsigned i = 0; i != NumArgs; i++) {
       Expr *Arg = Args[i];
       DefaultArgumentPromotion(Arg);
+      if (RequireCompleteType(Arg->getSourceRange().getBegin(),
+                              Arg->getType(),
+                              diag::err_call_incomplete_argument,
+                              Arg->getSourceRange()))
+        return ExprError();
       TheCall->setArg(i, Arg);
     }
   }

Modified: cfe/trunk/test/SemaCXX/enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=67485&r1=67484&r2=67485&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum.cpp Sun Mar 22 17:00:50 2009
@@ -26,13 +26,13 @@
 
 /// PR3688
 struct s1 {
-  enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
+  enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}} expected-note{{forward declaration of 'enum s1::e1'}}
 };
 
 enum e1 { YES, NO };
 
 static enum e1 badfunc(struct s1 *q) {
-  return q->bar(); // expected-error{{incompatible type returning 'enum s1::e1', expected 'enum e1'}}
+  return q->bar(); // expected-error{{return type of called function ('enum s1::e1') is incomplete}}
 }
 
 enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}





More information about the cfe-commits mailing list