[cfe-commits] r91983 - in /cfe/trunk: lib/AST/ExprConstant.cpp lib/CodeGen/CGBuiltin.cpp lib/Sema/SemaChecking.cpp test/CodeGen/object-size.c

Eric Christopher echristo at apple.com
Tue Dec 22 19:49:37 PST 2009


Author: echristo
Date: Tue Dec 22 21:49:37 2009
New Revision: 91983

URL: http://llvm.org/viewvc/llvm-project?rev=91983&view=rev
Log:
Update for the intrinsic changes in llvm: the object size intrinsic
only takes a boolean second argument now. Update tests accordingly.
Currently the builtin still accepts the full range for compatibility.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/CodeGen/object-size.c

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=91983&r1=91982&r2=91983&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Dec 22 21:49:37 2009
@@ -970,8 +970,9 @@
           }
         }
 
+    // TODO: Perhaps we should let LLVM lower this?
     if (E->getArg(0)->HasSideEffects(Info.Ctx)) {
-      if (E->getArg(1)->EvaluateAsInt(Info.Ctx).getZExtValue() < 2)
+      if (E->getArg(1)->EvaluateAsInt(Info.Ctx).getZExtValue() == 0)
         return Success(-1ULL, E);
       return Success(0, E);
     }

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Dec 22 21:49:37 2009
@@ -209,10 +209,19 @@
     const llvm::Type *ResType[] = {
       ConvertType(E->getType())
     };
+    
+    // LLVM only supports 0 and 2, make sure that we pass along that
+    // as a boolean.
+    Value *Ty = EmitScalarExpr(E->getArg(1));
+    ConstantInt *CI = dyn_cast<ConstantInt>(Ty);
+    assert(CI);
+    uint64_t val = CI->getZExtValue();
+    CI = ConstantInt::get(llvm::Type::getInt1Ty(VMContext), (val & 0x2) >> 1);    
+    
     Value *F = CGM.getIntrinsic(Intrinsic::objectsize, ResType, 1);
     return RValue::get(Builder.CreateCall2(F,
                                            EmitScalarExpr(E->getArg(0)),
-                                           EmitScalarExpr(E->getArg(1))));
+                                           CI));
   }
   case Builtin::BI__builtin_prefetch: {
     Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=91983&r1=91982&r2=91983&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 22 21:49:37 2009
@@ -747,6 +747,7 @@
 /// SemaBuiltinObjectSize - Handle __builtin_object_size(void *ptr,
 /// int type). This simply type checks that type is one of the defined
 /// constants (0-3).
+// For compatability check 0-3, llvm only handles 0 and 2.
 bool Sema::SemaBuiltinObjectSize(CallExpr *TheCall) {
   Expr *Arg = TheCall->getArg(1);
   if (Arg->isTypeDependent())

Modified: cfe/trunk/test/CodeGen/object-size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/object-size.c?rev=91983&r1=91982&r2=91983&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/object-size.c (original)
+++ cfe/trunk/test/CodeGen/object-size.c Tue Dec 22 21:49:37 2009
@@ -35,7 +35,7 @@
 
 void test5() {
   // CHECK:     %tmp = load i8** @gp
-  // CHECK-NEXT:%0 = call i64 @llvm.objectsize.i64(i8* %tmp, i32 0)
+  // CHECK-NEXT:%0 = call i64 @llvm.objectsize.i64(i8* %tmp, i1 false)
   // CHECK-NEXT:%cmp = icmp ne i64 %0, -1
   strcpy(gp, "Hi there");
 }





More information about the cfe-commits mailing list