From 28e38a9e569f77a33bb9be9d4728f94e05b2ee32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 12 Feb 2013 15:59:23 +0100 Subject: [PATCH] Fixed #4519 (false positive: (error) Uninitialized variable: eax (inline assembly usage)) --- lib/checkuninitvar.cpp | 3 +++ test/testuninitvar.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 1001e8f71..718dd8f01 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1456,6 +1456,9 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const return true; } } + + if (Token::Match(tok, "asm ( %str% ) ;")) + return true; } if (!suppressErrors && usetok) { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 983e73c7a..7bda66c50 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2693,6 +2693,14 @@ private: void uninitvar2_while() { // for, while + checkUninitVar2("void f() {\n" + " int x;\n" + " while (a) {\n" + " x = x + 1;\n" + " }\n" + "}\n"); + TODO_ASSERT_EQUALS("error", "", errout.str()); + checkUninitVar2("void f() {\n" " int x;\n" " while (a) {\n" @@ -2768,6 +2776,15 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar2("void f(){\n" // #4519 - fp: inline assembler in loop + " int x;\n" + " for (int i = 0; i < 10; i++) {\n" + " asm(\"foo\");\n" + " if (x & 0xf1) { }\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void uninitvar2_4494() {