]> granicus.if.org Git - clang/commitdiff
Update for the intrinsic changes in llvm: the object size intrinsic
authorEric Christopher <echristo@apple.com>
Wed, 23 Dec 2009 03:49:37 +0000 (03:49 +0000)
committerEric Christopher <echristo@apple.com>
Wed, 23 Dec 2009 03:49:37 +0000 (03:49 +0000)
only takes a boolean second argument now. Update tests accordingly.
Currently the builtin still accepts the full range for compatibility.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91983 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
lib/CodeGen/CGBuiltin.cpp
lib/Sema/SemaChecking.cpp
test/CodeGen/object-size.c

index 13831dc1f52cdb78d5a1ac8c0107b3fdbf9df631..d91ae6a3e782d198d4925ae76720185fea80d9b8 100644 (file)
@@ -970,8 +970,9 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
           }
         }
 
+    // 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);
     }
index a791fd04f4f6d5f9b5731c48d49dea0707324a63..98dd9ec991066c755c8c593d88e5e846b1449922 100644 (file)
@@ -209,10 +209,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
     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));
index 74ea1cc3cddb6677cec98169e9e854f30f60736a..f10fa07d8607020cc924998dcf505a750566fb4d 100644 (file)
@@ -747,6 +747,7 @@ bool Sema::SemaBuiltinEHReturnDataRegNo(CallExpr *TheCall) {
 /// 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())
index 3f89e4c3d84ebb951c9055b54fb2649395638a72..4947c19a5de808d1440e6834e25d5c2bb10669e6 100644 (file)
@@ -35,7 +35,7 @@ void test4() {
 
 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");
 }