[cfe-commits] r67475 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/functions.c
Chris Lattner
sabre at nondot.org
Sun Mar 22 12:35:37 PDT 2009
Author: lattner
Date: Sun Mar 22 14:35:37 2009
New Revision: 67475
URL: http://llvm.org/viewvc/llvm-project?rev=67475&view=rev
Log:
fix a fixme: non-proto struct returning function definitions should be compiled
to something like:
define void @bar(%struct.foo* noalias sret %agg.result) nounwind {
instead of:
define void @bar(%struct.foo* noalias sret %agg.result, ...) nounwind {
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/functions.c
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=67475&r1=67474&r2=67475&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Mar 22 14:35:37 2009
@@ -859,10 +859,13 @@
// As a special case, make sure that definitions of K&R function
// "type foo()" aren't declared as varargs (which forces the backend
// to do unnecessary work).
- // FIXME: what about stret() functions, this doesn't handle them!?
- if (Ty->isVarArg() && Ty->getNumParams() == 0)
- Ty = llvm::FunctionType::get(Ty->getReturnType(),
- std::vector<const llvm::Type*>(), false);
+ if (D->getType()->isFunctionNoProtoType()) {
+ assert(Ty->isVarArg() && "Didn't lower type as expected");
+ // Due to stret, the lowered function could have arguments. Just create the
+ // same type as was lowered by ConvertType but strip off the varargs bit.
+ std::vector<const llvm::Type*> Args(Ty->param_begin(), Ty->param_end());
+ Ty = llvm::FunctionType::get(Ty->getReturnType(), Args, false);
+ }
// Get or create the prototype for teh function.
llvm::Constant *Entry = GetAddrOfFunction(D, Ty);
Modified: cfe/trunk/test/CodeGen/functions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/functions.c?rev=67475&r1=67474&r2=67475&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/functions.c (original)
+++ cfe/trunk/test/CodeGen/functions.c Sun Mar 22 14:35:37 2009
@@ -27,5 +27,9 @@
void f2(void) {
f1(1, 2, 3);
}
-// RUN: grep 'define void @f1()' %t
+// RUN: grep 'define void @f1()' %t &&
void f1() {}
+
+// RUN: grep 'define .* @f3' %t | not grep -F '...'
+struct foo { int X, Y, Z; } f3() {
+}
More information about the cfe-commits
mailing list