[llvm-commits] [llvm-gcc-4.2] r85466 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Eric Christopher echristo at apple.com
Wed Oct 28 18:43:48 PDT 2009


Author: echristo
Date: Wed Oct 28 20:43:46 2009
New Revision: 85466

URL: http://llvm.org/viewvc/llvm-project?rev=85466&view=rev
Log:
Try #2 of this. Coerce all of the types to what they should be.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=85466&r1=85465&r2=85466&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Oct 28 20:43:46 2009
@@ -4966,12 +4966,12 @@
     return EmitBuiltinUnwindInit(exp, Result);
 
   case BUILT_IN_OBJECT_SIZE: {
-    tree ArgList = TREE_OPERAND (exp, 1);
-    if (!validate_arglist(ArgList, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE)) {
+    tree arglist = TREE_OPERAND (exp, 1);
+    if (!validate_arglist(arglist, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE)) {
       error("Invalid builtin_object_size argument types");
       return false;
     }
-    tree ObjSizeTree = TREE_VALUE (TREE_CHAIN (ArgList));
+    tree ObjSizeTree = TREE_VALUE (TREE_CHAIN (arglist));
     STRIP_NOPS (ObjSizeTree);
     if (TREE_CODE (ObjSizeTree) != INTEGER_CST
         || tree_int_cst_sgn (ObjSizeTree) < 0
@@ -4980,12 +4980,29 @@
       return false;
     }
 
-    // This treats everything as unknown, and is minimally defensible as
-    // correct, although completely useless.
-    if (tree_low_cst (ObjSizeTree, 0) < 2)
-      Result = Constant::getAllOnesValue(TD.getIntPtrType(Context));
-    else
-      Result = ConstantInt::get(TD.getIntPtrType(Context), 0);
+    tree Object = TREE_VALUE(arglist);
+    tree ObjTy = TREE_VALUE(TREE_CHAIN(arglist));
+
+    Value* Args[] = {
+      Emit(Object, 0),
+      Emit(ObjTy, 0)
+    };
+
+    // Grab the current types.
+    const Type* Ty[3];
+    Ty[0] = ConvertType(TREE_TYPE(exp));
+    Ty[1] = Type::getInt8PtrTy(Context);
+    Ty[2] = ConvertType(TREE_TYPE(ObjTy));
+
+    // Manually coerce the args to the current types.
+    Args[0] = Builder.CreateBitCast(Args[0], Ty[1]);
+    Args[1] = Builder.CreateIntCast(Args[1], Ty[2], "");
+
+    Result = Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
+							  Intrinsic::objectsize,
+							  Ty,
+							  2),
+				Args, Args + 2);
     return true;
   }
   // Unary bit counting intrinsics.





More information about the llvm-commits mailing list