[cfe-commits] r61992 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CodeGenFunction.h

Daniel Dunbar daniel at zuster.org
Fri Jan 9 08:50:52 PST 2009


Author: ddunbar
Date: Fri Jan  9 10:50:52 2009
New Revision: 61992

URL: http://llvm.org/viewvc/llvm-project?rev=61992&view=rev
Log:
Give "unsupported" error on calls through block pointers instead of
crashes.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=61992&r1=61991&r2=61992&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Jan  9 10:50:52 2009
@@ -83,6 +83,13 @@
 //                         LValue Expression Emission
 //===----------------------------------------------------------------------===//
 
+RValue CodeGenFunction::EmitUnsupportedRValue(const Expr *E,
+                                              const char *Name) {
+  ErrorUnsupported(E, Name);
+  llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
+  return RValue::get(llvm::UndefValue::get(Ty));
+}
+
 LValue CodeGenFunction::EmitUnsupportedLValue(const Expr *E,
                                               const char *Name) {
   ErrorUnsupported(E, Name);
@@ -903,6 +910,9 @@
         if (unsigned builtinID = FDecl->getIdentifier()->getBuiltinID())
           return EmitBuiltinExpr(builtinID, E);
 
+  if (E->getCallee()->getType()->isBlockPointerType())
+    return EmitUnsupportedRValue(E->getCallee(), "block pointer reference");
+
   llvm::Value *Callee = EmitScalarExpr(E->getCallee());
   return EmitCallExpr(Callee, E->getCallee()->getType(),
                       E->arg_begin(), E->arg_end());
@@ -1034,14 +1044,20 @@
   return EmitUnsupportedLValue(E, "use of super");
 }
 
-RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, 
+RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType CalleeType, 
                                      CallExpr::const_arg_iterator ArgBeg,
                                      CallExpr::const_arg_iterator ArgEnd) {
-  
-  // The callee type will always be a pointer to function type, get the function
-  // type.
-  FnType = FnType->getAsPointerType()->getPointeeType();
-  QualType ResultType = FnType->getAsFunctionType()->getResultType();
+  // Get the actual function type. The callee type will always be a
+  // pointer to function type or a block pointer type.
+  QualType ResultType;
+  if (const BlockPointerType *BPT = dyn_cast<BlockPointerType>(CalleeType)) {
+    ResultType = BPT->getPointeeType()->getAsFunctionType()->getResultType();
+  } else {
+    assert(CalleeType->isFunctionPointerType() && 
+           "Call must have function pointer type!");
+    QualType FnType = CalleeType->getAsPointerType()->getPointeeType();
+    ResultType = FnType->getAsFunctionType()->getResultType();
+  }
 
   CallArgList Args;
   for (CallExpr::const_arg_iterator I = ArgBeg; I != ArgEnd; ++I)

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=61992&r1=61991&r2=61992&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Jan  9 10:50:52 2009
@@ -431,6 +431,12 @@
   //                         LValue Expression Emission
   //===--------------------------------------------------------------------===//
 
+  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
+  /// and issue an ErrorUnsupported style diagnostic (using the
+  /// provided Name).
+  RValue EmitUnsupportedRValue(const Expr *E,
+                               const char *Name);
+
   /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E
   /// and issue an ErrorUnsupported style diagnostic (using the
   /// provided Name).





More information about the cfe-commits mailing list