[cfe-commits] r65130 - in /cfe/trunk: lib/CodeGen/CGCall.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/function-attributes.c

Daniel Dunbar daniel at zuster.org
Fri Feb 20 10:06:48 PST 2009


Author: ddunbar
Date: Fri Feb 20 12:06:48 2009
New Revision: 65130

URL: http://llvm.org/viewvc/llvm-project?rev=65130&view=rev
Log:
Set call attribute for direct calls (i.e. noreturn).
 - Remove an unused variant of EmitCallExpr overload.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGen/function-attributes.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Feb 20 12:06:48 2009
@@ -1676,7 +1676,8 @@
 
 RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
                                  llvm::Value *Callee, 
-                                 const CallArgList &CallArgs) {
+                                 const CallArgList &CallArgs,
+                                 const Decl *TargetDecl) {
   // FIXME: We no longer need the types from CallArgs; lift up and
   // simplify.
   llvm::SmallVector<llvm::Value*, 16> Args;
@@ -1752,9 +1753,8 @@
   
   llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size());
 
-  // FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set.
   CodeGen::AttributeListType AttributeList;
-  CGM.ConstructAttributeList(CallInfo, 0, AttributeList);
+  CGM.ConstructAttributeList(CallInfo, TargetDecl, AttributeList);
   CI->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(), 
                                            AttributeList.size()));  
   

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Feb 20 12:06:48 2009
@@ -966,29 +966,25 @@
 
 
 RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
+  // Builtins never have block type.
+  if (E->getCallee()->getType()->isBlockPointerType())
+    return EmitBlockCallExpr(E);
+
+  const Decl *TargetDecl = 0;
   if (const ImplicitCastExpr *IcExpr = 
-      dyn_cast<const ImplicitCastExpr>(E->getCallee()))
+      dyn_cast<ImplicitCastExpr>(E->getCallee())) {
     if (const DeclRefExpr *DRExpr = 
-        dyn_cast<const DeclRefExpr>(IcExpr->getSubExpr()))
-      if (const FunctionDecl *FDecl = 
-          dyn_cast<const FunctionDecl>(DRExpr->getDecl()))
+        dyn_cast<DeclRefExpr>(IcExpr->getSubExpr())) {
+      TargetDecl = DRExpr->getDecl();
+      if (const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(TargetDecl))
         if (unsigned builtinID = FDecl->getBuiltinID(getContext()))
           return EmitBuiltinExpr(FDecl, builtinID, E);
-
-  if (E->getCallee()->getType()->isBlockPointerType())
-    return EmitBlockCallExpr(E);
+    }
+  }
 
   llvm::Value *Callee = EmitScalarExpr(E->getCallee());
   return EmitCallExpr(Callee, E->getCallee()->getType(),
-                      E->arg_begin(), E->arg_end());
-}
-
-RValue CodeGenFunction::EmitCallExpr(Expr *FnExpr,
-                                     CallExpr::const_arg_iterator ArgBeg,
-                                     CallExpr::const_arg_iterator ArgEnd) {
-
-  llvm::Value *Callee = EmitScalarExpr(FnExpr);
-  return EmitCallExpr(Callee, FnExpr->getType(), ArgBeg, ArgEnd);
+                      E->arg_begin(), E->arg_end(), TargetDecl);
 }
 
 LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
@@ -1108,7 +1104,8 @@
 
 RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType CalleeType, 
                                      CallExpr::const_arg_iterator ArgBeg,
-                                     CallExpr::const_arg_iterator ArgEnd) {
+                                     CallExpr::const_arg_iterator ArgEnd,
+                                     const Decl *TargetDecl) {
   // Get the actual function type. The callee type will always be a
   // pointer to function type or a block pointer type.
   QualType ResultType;
@@ -1127,5 +1124,5 @@
                                   I->getType()));
 
   return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args), 
-                  Callee, Args);
+                  Callee, Args, TargetDecl);
 }

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Feb 20 12:06:48 2009
@@ -618,18 +618,21 @@
   /// EmitCall - Generate a call of the given function, expecting the given
   /// result type, and using the given argument list which specifies both the
   /// LLVM arguments and the types they were derived from.
+  ///
+  /// \param TargetDecl - If given, the decl of the function in a
+  /// direct call; used to set attributes on the call (noreturn,
+  /// etc.).
   RValue EmitCall(const CGFunctionInfo &FnInfo,
                   llvm::Value *Callee,
-                  const CallArgList &Args);
+                  const CallArgList &Args,
+                  const Decl *TargetDecl = 0);
 
   RValue EmitCallExpr(const CallExpr *E);
 
-  RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
-                      CallExpr::const_arg_iterator ArgEnd);
-
   RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
                       CallExpr::const_arg_iterator ArgBeg,
-                      CallExpr::const_arg_iterator ArgEnd);
+                      CallExpr::const_arg_iterator ArgEnd,
+                      const Decl *TargetDecl = 0);
 
   RValue EmitBuiltinExpr(const FunctionDecl *FD, 
                          unsigned BuiltinID, const CallExpr *E);

Modified: cfe/trunk/test/CodeGen/function-attributes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/function-attributes.c?rev=65130&r1=65129&r2=65130&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/function-attributes.c (original)
+++ cfe/trunk/test/CodeGen/function-attributes.c Fri Feb 20 12:06:48 2009
@@ -7,7 +7,7 @@
 // RUN: grep 'define zeroext i16 @f5(i32 %x) nounwind' %t &&
 // RUN: grep 'define void @f6(i16 signext %x) nounwind' %t &&
 // RUN: grep 'define void @f7(i16 zeroext %x) nounwind' %t &&
-// RUN: grep 'define void @f8() nounwind alwaysinline' %t
+// RUN: grep 'define void @f8() nounwind alwaysinline' %t &&
 
 signed char f0(int x) { return x; }
 
@@ -26,3 +26,14 @@
 void f7(unsigned short x) { }
 
 void __attribute__((always_inline)) f8(void) { }
+
+// RUN: grep 'call void @f9_t() noreturn' %t &&
+void __attribute__((noreturn)) f9_t(void);
+void f9(void) { f9_t(); }
+
+// FIXME: We should be setting nounwind on calls.
+// RUN: grep 'call i32 @f10_t() readnone' %t &&
+int __attribute__((const)) f10_t(void);
+int f10(void) { return f10_t(); }
+
+// RUN: true





More information about the cfe-commits mailing list