diff options
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 5 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 5 | ||||
-rw-r--r-- | clang/test/CodeGen/bounds-checking.c | 25 | ||||
-rw-r--r-- | clang/test/CodeGen/object-size.c | 4 |
4 files changed, 33 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index bf180f64b383..f995614fd56c 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -346,11 +346,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, 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)); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 19ee42824f5a..979454bdc872 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -525,8 +525,9 @@ void CodeGenFunction::EmitCheck(llvm::Value *Address, unsigned Size) { 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)), diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c new file mode 100644 index 000000000000..ce7f24fde937 --- /dev/null +++ b/clang/test/CodeGen/bounds-checking.c @@ -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; +} diff --git a/clang/test/CodeGen/object-size.c b/clang/test/CodeGen/object-size.c index 1f16d02d7d64..966d59f11df4 100644 --- a/clang/test/CodeGen/object-size.c +++ b/clang/test/CodeGen/object-size.c @@ -40,7 +40,7 @@ void test4() { // 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 @@ void test6() { // 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"); } |