diff options
author | Martin Nowack <m.nowack@imperial.ac.uk> | 2018-10-18 14:01:51 +0100 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2018-10-23 18:53:46 +0300 |
commit | bcd0cf245e9638a5f39c9340a28313dc6a3814c4 (patch) | |
tree | 0ce2de11fe43dd8bca86b1a59945cc2120e68904 /lib/Expr/ArrayExprRewriter.cpp | |
parent | 8bfd97d583e932973f0d363f8cfd695ecb5e002e (diff) | |
download | klee-bcd0cf245e9638a5f39c9340a28313dc6a3814c4.tar.gz |
Avoid unsafe static downcasts
Diffstat (limited to 'lib/Expr/ArrayExprRewriter.cpp')
-rw-r--r-- | lib/Expr/ArrayExprRewriter.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/Expr/ArrayExprRewriter.cpp b/lib/Expr/ArrayExprRewriter.cpp index 7bbadd61..8306e20a 100644 --- a/lib/Expr/ArrayExprRewriter.cpp +++ b/lib/Expr/ArrayExprRewriter.cpp @@ -48,9 +48,11 @@ ref<Expr> ExprRewriter::rewrite(const ref<Expr> &e, const array2idx_ty &arrays, // skipping all those indexes that are not multiple of such value. // In fact, they will be rejected by the MulExpr interpreter since it // will not find any integer solution - Expr &e = *idxt_v.getMul(); - auto &ce = static_cast<ConstantExpr &>(e); - llvm::APInt val = ce.getAPValue(); + auto e = idxt_v.getMul(); + auto ce = dyn_cast<ConstantExpr>(e); + assert(ce && "Not a constant expression"); + + llvm::APInt val = ce->getAPValue(); uint64_t mulVal = val.getZExtValue(); // So far we try to limit this optimization, but we may try some more // aggressive conditions (i.e. mulVal > width) @@ -76,8 +78,8 @@ ref<Expr> ExprRewriter::rewrite(const ref<Expr> &e, const array2idx_ty &arrays, unsigned set = 0; BitArray ba(arr->size / width); for (auto &vals : opt_indexes) { - auto &ce = static_cast<ConstantExpr &>(*vals); - llvm::APInt v = ce.getAPValue(); + auto ce = dyn_cast<ConstantExpr>(vals); + llvm::APInt v = ce->getAPValue(); ba.set(v.getZExtValue() / width); set++; } |