Add __builtin_object_size support.
 - Currently CodeGen always returns a conservative value for this (-1
   or 0 depending on the context).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55735 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index e89997a..177e68e 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -199,6 +199,16 @@
     Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1);
     return RValue::get(Builder.CreateCall(F, ArgValue, "tmp"));
   }    
+  case Builtin::BI__builtin_object_size: {
+    // FIXME: Implement. For now we just always fail and pretend we
+    // don't know the object size.
+    llvm::APSInt TypeArg = 
+      E->getArg(1)->getIntegerConstantExprValue(CGM.getContext());
+    const llvm::Type *ResType = ConvertType(E->getType());
+    //    bool UseSubObject = TypeArg.getZExtValue() & 1;
+    bool UseMinimum = TypeArg.getZExtValue() & 2;
+    return RValue::get(ConstantInt::get(ResType, UseMinimum ? 0 : -1LL));
+  }
   case Builtin::BI__builtin_prefetch: {
     Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));
     // FIXME: Technically these constants should of type 'int', yes?