[cfe-commits] r70098 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGen/attr-cleanup.c

Anders Carlsson andersca at mac.com
Sat Apr 25 17:34:20 PDT 2009


Author: andersca
Date: Sat Apr 25 19:34:20 2009
New Revision: 70098

URL: http://llvm.org/viewvc/llvm-project?rev=70098&view=rev
Log:
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>.

Added:
    cfe/trunk/test/CodeGen/attr-cleanup.c
Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Apr 25 19:34:20 2009
@@ -405,11 +405,22 @@
   
     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) {

Added: cfe/trunk/test/CodeGen/attr-cleanup.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-cleanup.c?rev=70098&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/attr-cleanup.c (added)
+++ cfe/trunk/test/CodeGen/attr-cleanup.c Sat Apr 25 19:34:20 2009
@@ -0,0 +1,8 @@
+// RUN: clang-cc -emit-llvm %s -o %t
+
+// <rdar://problem/6827047>
+void f(void* arg);
+void g() {
+	__attribute__((cleanup(f))) void *g;
+}
+





More information about the cfe-commits mailing list