New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 44816 - bugprone-infinite-loop false positive with CATCH2
Summary: bugprone-infinite-loop false positive with CATCH2
Status: RESOLVED FIXED
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: clang-tidy (show other bugs)
Version: unspecified
Hardware: PC All
: P enhancement
Assignee: Nathan James
URL:
Keywords:
Depends on: 44894
Blocks: release-10.0.0
  Show dependency tree
 
Reported: 2020-02-06 12:25 PST by Pavel Kryukov
Modified: 2020-02-17 04:50 PST (History)
8 users (show)

See Also:
Fixed By Commit(s): rGc69ec6476806147e46bf09b693acb24177982dc2


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Kryukov 2020-02-06 12:25:58 PST
bugprone-infinite-loop has a false positive for CATCH2 assertion macro.

Example: https://godbolt.org/z/bzHeuz

> #include <catch.hpp>
> int foo();
> int bar();
>
> TEST_CASE("Hello World")
> {
>     int x = foo();
>     int y = bar();
>     CHECK( x < y);
> }

Output:

> clang-tidy (trunk) #2 with x86-64 gcc 9.2
> -checks='*,-modernize-use-trailing-return-type'
> <source>:10:5: warning: this loop is infinite; none of its condition variables (x, y) are updated in the loop body [bugprone-infinite-loop]
>     CHECK( x < y);
>     ^
> /opt/compiler-explorer/libs/catch2/v2.11.1/include/catch.hpp:217:22: note: expanded from macro 'CHECK'
> #define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
>                     ^
> /opt/compiler-explorer/libs/catch2/v2.11.1/include/internal/catch_capture.hpp:43:5: note: expanded from macro 'INTERNAL_CATCH_TEST'
>    do { \
>    ^
Comment 1 Pavel Kryukov 2020-02-06 12:33:25 PST
The problematic loop is:

>  do {
>  
>  } while( (void)0, false && static_cast<bool>( !!(__VA_ARGS__) ) )
>  // the expression here is never evaluated at runtime but it forces the compiler to give it a look
Comment 2 Nathan James 2020-02-10 07:19:22 PST
minimum reproducible test case
=======================
void fail(bool a) {
  do {
  } while (false && a);
}
======================= 

Should ignore loops with conditions that always eval to false
Comment 4 Pavel Kryukov 2020-02-11 13:30:30 PST
Thanks! Could you please tell if it lands to LLVM 10?
Comment 5 Eugene Zelenko 2020-02-11 13:43:24 PST
(In reply to Pavel Kryukov from comment #4)
> Thanks! Could you please tell if it lands to LLVM 10?

It's necessary to create new merge request and make bug 44555 depended on it.
Comment 6 Pavel Kryukov 2020-02-11 22:52:00 PST
I’ve added the dependency - should I reopen the bug?
Comment 7 Nathan James 2020-02-12 00:06:48 PST
I've done it for you. But if it's not reopened it won't appear to block the release
Comment 8 Hans Wennborg 2020-02-12 04:53:20 PST
(In reply to Nathan James from comment #3)
> Fixed in https://reviews.llvm.org/rGc69ec6476806147e46bf09b693acb24177982dc2

Pushed to 10.x in 7a136d2768e26b30273f208fb3d64eae531c8455.
Comment 9 Volker Reichelt 2020-02-13 06:51:38 PST
This probably caused bug 44894.