summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-06-01 10:04:20 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-06-01 10:04:20 +0000
commit3fbc473e1e76ead199c7333bdbf02dfa1c7dc420 (patch)
tree85f3bae298139295a93877aa1fa841516ee87062 /lib/CodeGen/CGExpr.cpp
parentbc4e29f307f86ddbc2f31d9530da79ad9b0c6b7b (diff)
downloadclang-3fbc473e1e76ead199c7333bdbf02dfa1c7dc420.tar.gz
clang-3fbc473e1e76ead199c7333bdbf02dfa1c7dc420.tar.bz2
clang-3fbc473e1e76ead199c7333bdbf02dfa1c7dc420.tar.xz
PR4289: Make sure "&func" has the right LLVM type when "func" is a
K&R-style definition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72690 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index da3f79e83a..155658e92d 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -711,8 +711,20 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
LV.SetGlobalObjCRef(LV, true);
return LV;
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
- return LValue::MakeAddr(CGM.GetAddrOfFunction(GlobalDecl(FD)),
- E->getType().getCVRQualifiers(),
+ llvm::Value* V = CGM.GetAddrOfFunction(GlobalDecl(FD));
+ if (!FD->hasPrototype()) {
+ if (const FunctionProtoType *Proto =
+ FD->getType()->getAsFunctionProtoType()) {
+ // Ugly case: for a K&R-style definition, the type of the definition
+ // isn't the same as the type of a use. Correct for this with a
+ // bitcast.
+ QualType NoProtoType =
+ getContext().getFunctionNoProtoType(Proto->getResultType());
+ NoProtoType = getContext().getPointerType(NoProtoType);
+ V = Builder.CreateBitCast(V, ConvertType(NoProtoType), "tmp");
+ }
+ }
+ return LValue::MakeAddr(V, E->getType().getCVRQualifiers(),
getContext().getObjCGCAttrKind(E->getType()));
}
else if (const ImplicitParamDecl *IPD =