From efc492fbb6bcba23740a2c10bbf4e0daca956f51 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 14 Mar 2024 16:52:41 +0100 Subject: [PATCH] Add test for #12038 --- test/cli/performance_test.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/cli/performance_test.py b/test/cli/performance_test.py index 1e7cd38f3ee..66b9de70ee3 100644 --- a/test/cli/performance_test.py +++ b/test/cli/performance_test.py @@ -185,3 +185,38 @@ def test_slow_initlist_varchanged(tmpdir): } }""") cppcheck([filename]) # should not take more than ~1 second + + +@pytest.mark.timeout(10) +def test_slow_many_scopes(tmpdir): + # #12038 + filename = os.path.join(tmpdir, 'hang.cpp') + with open(filename, 'wt') as f: + f.write(r""" + #define BLOCK {\ + char buf[sizeof("x") + 5 * 3 + 16];\ + int rc;\ + memset(buf, cmp[0], sizeof buf);\ + rc = sprintf(buf + 5, "x");\ + assert(rc == sizeof("x") - 1);\ + assert(memcmp(buf, cmp, 5) == 0);\ + if ((rc) >= 0) {\ + assert(memcmp(buf + 5, ("x"), (rc)) == 0);\ + assert(buf[5 + (rc)] == '\0');\ + }\ + assert(memcmp(buf + 5 + (rc) + 1, cmp, 5) == 0);\ + } + #define BLOCK2 BLOCK BLOCK + #define BLOCK4 BLOCK2 BLOCK2 + #define BLOCK8 BLOCK4 BLOCK4 + #define BLOCK16 BLOCK8 BLOCK8 + #define BLOCK32 BLOCK16 BLOCK16 + #define BLOCK64 BLOCK32 BLOCK32 + #define BLOCK128 BLOCK64 BLOCK64 + int main() { + char cmp[5]; + memset(cmp, '\376', sizeof cmp); + BLOCK128 + return EXIT_SUCCESS; + }""") + cppcheck([filename]) # should not take more than ~1 second