[cfe-commits] r95399 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/stdcall-fastcall.c

Charles Davis cdavis at mines.edu
Fri Feb 5 10:13:10 PST 2010


Author: cdavis
Date: Fri Feb  5 12:13:10 2010
New Revision: 95399

URL: http://llvm.org/viewvc/llvm-project?rev=95399&view=rev
Log:
Now that we store calling conventions in the types, use them instead of
getting the calling convention from the target function, which may or may not
exist. Fixes PR5280.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGen/stdcall-fastcall.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Feb  5 12:13:10 2010
@@ -1864,6 +1864,14 @@
   return LValue::MakeAddr(RV.getAggregateAddr(), MakeQualifiers(E->getType()));
 }
 
+static unsigned ClangCallConvToLLVMCallConv(CallingConv CC) {
+  switch (CC) {
+  default: return llvm::CallingConv::C;
+  case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
+  case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  }
+}
+
 RValue CodeGenFunction::EmitCall(QualType CalleeType, llvm::Value *Callee,
                                  ReturnValueSlot ReturnValue,
                                  CallExpr::const_arg_iterator ArgBeg,
@@ -1882,12 +1890,8 @@
   CallArgList Args;
   EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), ArgBeg, ArgEnd);
 
-  // FIXME: We should not need to do this, it should be part of the function
-  // type.
-  unsigned CallingConvention = 0;
-  if (const llvm::Function *F =
-      dyn_cast<llvm::Function>(Callee->stripPointerCasts()))
-    CallingConvention = F->getCallingConv();
+  unsigned CallingConvention =
+    ClangCallConvToLLVMCallConv(FnType->getAs<FunctionType>()->getCallConv());
   return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args,
                                                  CallingConvention),
                   Callee, ReturnValue, Args, TargetDecl);

Modified: cfe/trunk/test/CodeGen/stdcall-fastcall.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/stdcall-fastcall.c?rev=95399&r1=95398&r2=95399&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/stdcall-fastcall.c (original)
+++ cfe/trunk/test/CodeGen/stdcall-fastcall.c Fri Feb  5 12:13:10 2010
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -emit-llvm < %s | grep 'fastcallcc' | count 4
-// RUN: %clang_cc1 -emit-llvm < %s | grep 'stdcallcc' | count 4
+// RUN: %clang_cc1 -emit-llvm < %s | grep 'fastcallcc' | count 6
+// RUN: %clang_cc1 -emit-llvm < %s | grep 'stdcallcc' | count 6
 
 void __attribute__((fastcall)) f1(void);
 void __attribute__((stdcall)) f2(void);
@@ -10,8 +10,15 @@
   f2();
 }
 
+// PR5280
+void (__attribute__((fastcall)) *pf1)(void) = f1;
+void (__attribute__((stdcall)) *pf2)(void) = f2;
+void (__attribute__((fastcall)) *pf3)(void) = f3;
+void (__attribute__((stdcall)) *pf4)(void) = f4;
+
 int main(void) {
     f3(); f4();
+    pf1(); pf2(); pf3(); pf4();
     return 0;
 }
 





More information about the cfe-commits mailing list