summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-04-26 00:34:20 +0000
committerAnders Carlsson <andersca@mac.com>2009-04-26 00:34:20 +0000
commit6f5c15688de7f35da8ffd86306848115b123e878 (patch)
tree696b532f0f858d896ef64bee26009cdf6ae99019 /clang/lib/CodeGen
parenteda6a89c4ed87fc357c4397a28d18524265b1b83 (diff)
downloadbcm5719-llvm-6f5c15688de7f35da8ffd86306848115b123e878.tar.gz
bcm5719-llvm-6f5c15688de7f35da8ffd86306848115b123e878.zip
When calling the cleanup function specified by __attribute__((cleanup)), make sure to bitcast the argument so it has the same type as the first argument of the cleanup function. Fixes <rdar://problem/6827047>.
llvm-svn: 70098
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGDecl.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 0a1d1d0bd1e..15f1e1d4318 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -405,11 +405,22 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
CleanupScope scope(*this);
+ const CGFunctionInfo &Info = CGM.getTypes().getFunctionInfo(FD);
+
+ // In some cases, the type of the function argument will be different from
+ // the type of the pointer. An example of this is
+ // void f(void* arg);
+ // __attribute__((cleanup(f))) void *g;
+ //
+ // To fix this we insert a bitcast here.
+ QualType ArgTy = Info.arg_begin()->type;
+ DeclPtr = Builder.CreateBitCast(DeclPtr, ConvertType(ArgTy));
+
CallArgList Args;
Args.push_back(std::make_pair(RValue::get(DeclPtr),
getContext().getPointerType(D.getType())));
-
- EmitCall(CGM.getTypes().getFunctionInfo(FD), F, Args);
+
+ EmitCall(Info, F, Args);
}
if (needsDispose && CGM.getLangOptions().getGCMode() != LangOptions::GCOnly) {
OpenPOWER on IntegriCloud