llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.39k stars 12.15k forks source link

False positive in Catch2 2.4.1 #38549

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 39201
Version 7.0
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

See https://github.com/catchorg/Catch2/issues/1230 for more details. Closed by Catch2 maintainer since deemed to be false positive in Clang's analyzer.

There is a report.zip in the GH issue (have not looked at it myself).

Excerpt from my own run when analyzing a file that does #include <catch2/catch.hpp> and uses the REQUIRE macro:

/usr/include/catch2/catch.hpp:13808:24: note: expanded from macro 'REQUIRE'

define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )

                   ^

/usr/include/catch2/catch.hpp:1869:33: note: expanded from macro 'INTERNAL_CATCH_TEST' Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ ^ /usr/include/catch2/catch.hpp:5550:26: note: Calling 'getResultCapture' m_resultCapture( getResultCapture() ) ^ /usr/include/catch2/catch.hpp:9867:29: note: Calling 'getCurrentContext' if (auto capture = getCurrentContext().getResultCapture()) ^ /usr/include/catch2/catch.hpp:5254:16: note: Calling 'getCurrentMutableContext' return getCurrentMutableContext(); ^ /usr/include/catch2/catch.hpp:5247:13: note: Assuming 'currentContext' is null if( !IMutableContext::currentContext ) ^ /usr/include/catch2/catch.hpp:5247:13: note: Assuming pointer value is null /usr/include/catch2/catch.hpp:5247:9: note: Taking true branch if( !IMutableContext::currentContext ) ^ /usr/include/catch2/catch.hpp:5249:9: note: Returning null reference return IMutableContext::currentContext;

llvmbot commented 5 years ago

Concrete repro script -- fetches catch.hpp, creates a minimal .cc triggering the issue, & invokes clang-tidy Concrete repro script attached.

I still see this with latest Catch2 (v2.6.0 2019-01-31 22:25:55.560884) and clang-tidy versions 6.0.1, 7.0.1, and a recent 9.0.0svn built from head.

Output from attached script:

1 warning generated. /tmp/tmp.glj6c32FGO/catch.hpp:5801:9: warning: Returning null reference [clang-analyzer-core.uninitialized.UndefReturn] return *IMutableContext::currentContext; ^ /tmp/tmp.glj6c32FGO/a.cc:7:3: note: Calling constructor for 'AssertionHandler' REQUIRE(three() == 3); ^ /tmp/tmp.glj6c32FGO/catch.hpp:14425:24: note: expanded from macro 'REQUIRE'

define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )

                   ^

/tmp/tmp.glj6c32FGO/catch.hpp:2312:33: note: expanded from macro 'INTERNAL_CATCH_TEST' Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ ^ /tmp/tmp.glj6c32FGO/catch.hpp:6099:26: note: Calling 'getResultCapture' m_resultCapture( getResultCapture() ) ^ /tmp/tmp.glj6c32FGO/catch.hpp:10486:29: note: Calling 'getCurrentContext' if (auto capture = getCurrentContext().getResultCapture()) ^ /tmp/tmp.glj6c32FGO/catch.hpp:5806:16: note: Calling 'getCurrentMutableContext' return getCurrentMutableContext(); ^ /tmp/tmp.glj6c32FGO/catch.hpp:5799:13: note: Assuming 'currentContext' is null if( !IMutableContext::currentContext ) ^ /tmp/tmp.glj6c32FGO/catch.hpp:5799:13: note: Assuming pointer value is null /tmp/tmp.glj6c32FGO/catch.hpp:5799:9: note: Taking true branch if( !IMutableContext::currentContext ) ^ /tmp/tmp.glj6c32FGO/catch.hpp:5801:9: note: Returning null reference return IMutableContext::currentContext; ^

llvmbot commented 6 years ago

assigned to @devincoughlin