You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bf1435a
Browse filesBrowse the repository at this point in the historyBrowse files
Fix missingForLoopIncrement FPs for escaped/volatile/atomic vars
Bail out for volatile or class control variables, and when the
variable's address escapes before the loop and the body has a call.
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: test/testother.cpp
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -14809,6 +14809,36 @@ class TestOther : public TestFixture {
14809
14809
" for (int h = 35; h > 5; k++) {}\n"
14810
14810
"}\n");
14811
14811
ASSERT_EQUALS("[test.cpp:3:3]: (warning) The loop variable 'h' is not updated in this for-loop, so the loop might never terminate. [missingForLoopIncrement]\n", errout_str());
14812
+
14813
+
// Volatile control variable whose address escapes — OK
14814
+
check("void register_flag(volatile int *p);\n"
14815
+
"void f(void) {\n"
14816
+
" volatile int done;\n"
14817
+
" register_flag(&done);\n"
14818
+
" for (done = 0; done == 0;) {}\n"
14819
+
"}\n", dinit(CheckOptions, $.cpp = false));
14820
+
ASSERT_EQUALS("", errout_str());
14821
+
14822
+
// std::atomic control variable — OK
14823
+
check("#include <atomic>\n"
14824
+
"#include <thread>\n"
14825
+
"void f() {\n"
14826
+
" std::atomic<int> i;\n"
14827
+
" std::thread t([&]{ i = 10; });\n"
14828
+
" for (i = 0; i < 10;) {}\n"
14829
+
" t.join();\n"
14830
+
"}\n");
14831
+
ASSERT_EQUALS("", errout_str());
14832
+
14833
+
// Address stored in a global pointer, then changed through a call — OK
0 commit comments