r175982 - PR15338: Don't assert if -fsanitize=bounds sees array indexing on an incomplete
Richard Smith
richard-llvm at metafoo.co.uk
Sat Feb 23 17:56:25 PST 2013
Author: rsmith
Date: Sat Feb 23 19:56:24 2013
New Revision: 175982
URL: http://llvm.org/viewvc/llvm-project?rev=175982&view=rev
Log:
PR15338: Don't assert if -fsanitize=bounds sees array indexing on an incomplete
array type.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=175982&r1=175981&r2=175982&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Feb 23 19:56:24 2013
@@ -677,7 +677,7 @@ llvm::Value *getArrayIndexingBound(CodeG
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(CodeG
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)
Modified: cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp?rev=175982&r1=175981&r2=175982&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp Sat Feb 23 19:56:24 2013
@@ -292,6 +292,13 @@ int flex_array_index(ArrayMembers *p, in
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) {
More information about the cfe-commits
mailing list