aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-02-24 01:56:24 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-02-24 01:56:24 +0000
commit5956bcc31ad0b1f570e04f7e19e817112f7274c5 (patch)
tree806cfdbdd482722f7c9a817db5b6ce9457453e62
parentc515978bd3a703aa733f846a0094ffa84d149074 (diff)
PR15338: Don't assert if -fsanitize=bounds sees array indexing on an incomplete
array type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175982 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExpr.cpp4
-rw-r--r--test/CodeGenCXX/catch-undef-behavior.cpp7
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index a688dbfacb..85662069ea 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -677,7 +677,7 @@ llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, const Expr *Base,
const ArrayType *AT = IndexedType->castAsArrayTypeUnsafe();
if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT))
return CGF.Builder.getInt(CAT->getSize());
- else if (const VariableArrayType *VAT = cast<VariableArrayType>(AT))
+ else if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(AT))
return CGF.getVLASize(VAT).first;
}
}
@@ -688,6 +688,8 @@ llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, const Expr *Base,
void CodeGenFunction::EmitBoundsCheck(const Expr *E, const Expr *Base,
llvm::Value *Index, QualType IndexType,
bool Accessed) {
+ assert(SanOpts->Bounds && "should not be called unless adding bounds checks");
+
QualType IndexedType;
llvm::Value *Bound = getArrayIndexingBound(*this, Base, IndexedType);
if (!Bound)
diff --git a/test/CodeGenCXX/catch-undef-behavior.cpp b/test/CodeGenCXX/catch-undef-behavior.cpp
index 044b92be9f..31958a61e3 100644
--- a/test/CodeGenCXX/catch-undef-behavior.cpp
+++ b/test/CodeGenCXX/catch-undef-behavior.cpp
@@ -292,6 +292,13 @@ int flex_array_index(ArrayMembers *p, int n) {
return p->a2[n];
}
+extern int incomplete[];
+// CHECK: @_Z22incomplete_array_index
+int incomplete_array_index(int n) {
+ // CHECK-NOT: call void @__ubsan_handle_out_of_bounds(
+ return incomplete[n];
+}
+
typedef __attribute__((ext_vector_type(4))) int V4I;
// CHECK: @_Z12vector_index
int vector_index(V4I v, int n) {