From 5956bcc31ad0b1f570e04f7e19e817112f7274c5 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sun, 24 Feb 2013 01:56:24 +0000 Subject: 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 --- lib/CodeGen/CGExpr.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/CGExpr.cpp') 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(AT)) return CGF.Builder.getInt(CAT->getSize()); - else if (const VariableArrayType *VAT = cast(AT)) + else if (const VariableArrayType *VAT = dyn_cast(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) -- cgit v1.2.3-18-g5258