From 97fa9e9d1b1ad8e70388da3ad771cb6c0dc05e4a Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 23 Mar 2017 20:01:16 +0100 Subject: [PATCH] ValueFlow: Stop on inline assembly --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d0ed48c08..70f2546ca 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1327,7 +1327,7 @@ static bool valueFlowForward(Token * const startToken, continue; } - else if (var->isGlobal() && Token::Match(tok2, "%name% (") && Token::Match(tok2->linkAt(1), ") !!{")) { + else if ((var->isGlobal() || tok2->str() == "asm") && Token::Match(tok2, "%name% (") && Token::Match(tok2->linkAt(1), ") !!{")) { return false; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 35b1903df..6312f490e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -82,6 +82,8 @@ private: TEST_CASE(valueFlowSizeofForwardDeclaredEnum); TEST_CASE(valueFlowGlobalVar); + + TEST_CASE(valueFlowInlineAssembly); } bool testValueOfX(const char code[], unsigned int linenr, int value) { @@ -2355,6 +2357,15 @@ private: "}"; ASSERT_EQUALS(false, testValueOfX(code, 5U, 42)); } + + void valueFlowInlineAssembly() { + const char* code = "void f() {\n" + " int x = 42;\n" + " asm(\"\");\n" + " a = x;\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 5U, 42)); + } }; REGISTER_TEST(TestValueFlow)