[cfe-commits] r156474 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CGExpr.cpp test/CodeGen/bounds-checking.c test/CodeGen/object-size.c

Nuno Lopes nunoplopes at sapo.pt
Wed May 9 08:53:34 PDT 2012


Author: nlopes
Date: Wed May  9 10:53:34 2012
New Revision: 156474

URL: http://llvm.org/viewvc/llvm-project?rev=156474&view=rev
Log:
update calls to objectsize intrinsic to match LLVM r156473
add a test for -fbounds-checking code generation

Added:
    cfe/trunk/test/CodeGen/bounds-checking.c
Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGen/object-size.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=156474&r1=156473&r2=156474&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed May  9 10:53:34 2012
@@ -346,11 +346,12 @@
     assert(CI);
     uint64_t val = CI->getZExtValue();
     CI = ConstantInt::get(Builder.getInt1Ty(), (val & 0x2) >> 1);    
+    Value *Runtime = Builder.getInt32(0);  // FIXME: use BoundsChecking here?
     
     Value *F = CGM.getIntrinsic(Intrinsic::objectsize, ResType);
-    return RValue::get(Builder.CreateCall2(F,
+    return RValue::get(Builder.CreateCall3(F,
                                            EmitScalarExpr(E->getArg(0)),
-                                           CI));
+                                           CI, Runtime));
   }
   case Builtin::BI__builtin_prefetch: {
     Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=156474&r1=156473&r2=156474&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed May  9 10:53:34 2012
@@ -525,8 +525,9 @@
 
   llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::objectsize, IntPtrTy);
 
-  llvm::Value *Arg = Builder.getFalse();
-  llvm::Value *C = Builder.CreateCall2(F, Address, Arg);
+  llvm::Value *Min = Builder.getFalse();
+  llvm::Value *Runtime = Builder.getInt32(BoundsChecking);
+  llvm::Value *C = Builder.CreateCall3(F, Address, Min, Runtime);
   llvm::BasicBlock *Cont = createBasicBlock();
   Builder.CreateCondBr(Builder.CreateICmpUGE(C,
                                         llvm::ConstantInt::get(IntPtrTy, Size)),

Added: cfe/trunk/test/CodeGen/bounds-checking.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bounds-checking.c?rev=156474&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/bounds-checking.c (added)
+++ cfe/trunk/test/CodeGen/bounds-checking.c Wed May  9 10:53:34 2012
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fbounds-checking=4 -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s
+
+// CHECK: @f
+double f(int b, int i) {
+  double a[b];
+  return a[i];
+  // CHECK: objectsize.i64({{.*}}, i1 false, i32 4)
+  // CHECK: icmp uge i64 {{.*}}, 8
+}
+
+// CHECK: @f2
+void f2() {
+  int a[2];
+  // CHECK: objectsize.i64({{.*}}, i1 false, i32 4)
+  // CHECK: icmp uge i64 {{.*}}, 4
+  a[1] = 42;
+  
+  short *b = malloc(64);
+  // CHECK: objectsize.i64({{.*}}, i1 false, i32 4)
+  // CHECK: icmp uge i64 {{.*}}, 4
+  // CHECK: getelementptr {{.*}}, i64 5
+  // CHECK: objectsize.i64({{.*}}, i1 false, i32 4)
+  // CHECK: icmp uge i64 {{.*}}, 2
+  b[5] = a[1]+2;
+}

Modified: cfe/trunk/test/CodeGen/object-size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/object-size.c?rev=156474&r1=156473&r2=156474&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/object-size.c (original)
+++ cfe/trunk/test/CodeGen/object-size.c Wed May  9 10:53:34 2012
@@ -40,7 +40,7 @@
 // CHECK: define void @test5
 void test5() {
   // CHECK:     = load i8** @gp
-  // CHECK-NEXT:= call i64 @llvm.objectsize.i64(i8* %{{.*}}, i1 false)
+  // CHECK-NEXT:= call i64 @llvm.objectsize.i64(i8* %{{.*}}, i1 false, i32 0)
   strcpy(gp, "Hi there");
 }
 
@@ -55,7 +55,7 @@
 // CHECK: define void @test7
 void test7() {
   int i;
-  // CHECK:     = call i64 @llvm.objectsize.i64(i8* {{.*}}@gbuf{{.*}}, i1 false)
+  // CHECK:     = call i64 @llvm.objectsize.i64(i8* {{.*}}@gbuf{{.*}}, i1 false, i32 0)
   strcpy((++i, gbuf), "Hi there");
 }
 





More information about the cfe-commits mailing list