From 6c0c9ba6d3a94089596871ef3fd10ca8dd8ae4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 6 Oct 2019 17:43:30 +0200 Subject: [PATCH] ExprEngine: Handle 'break' and 'while (0);' --- lib/exprengine.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 78f186263..71b074fbd 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -563,6 +563,11 @@ struct ExprData { getExpr(c->values[0].second)); } + if (auto integerTruncation = std::dynamic_pointer_cast(v)) { + return getExpr(integerTruncation->inputValue); + //return getExpr(integerTruncation->inputValue) & ((1 << integerTruncation->bits) - 1); + } + if (v->type == ExprEngine::ValueType::UninitValue) return context.int_val(0); @@ -1036,6 +1041,14 @@ static void execute(const Token *start, const Token *end, Data &data) if (Token::Match(tok, "[;{}]")) data.trackProgramState(tok); + if (Token::simpleMatch(tok, "while ( 0 ) ;")) { + tok = tok->tokAt(4); + continue; + } + + if (tok->str() == "break") + return; + if (Token::Match(tok, "for|while|switch (")) // TODO this is a bailout throw std::runtime_error("Unhandled:" + tok->str());