diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2019-03-14 10:22:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 10:22:44 +0100 |
commit | 6958ede8e835048b9d1ee9843d7587cacf527101 (patch) | |
tree | eb68428efcfd1e69753394f9a438978c5f5f8a08 | |
parent | 674bdcbc2ac824d005b5179cee3c5826b582b9a6 (diff) | |
parent | 78004e9a33422d1c2399339a3ac408f4c654d06b (diff) | |
download | coreclr-6958ede8e835048b9d1ee9843d7587cacf527101.tar.gz coreclr-6958ede8e835048b9d1ee9843d7587cacf527101.tar.bz2 coreclr-6958ede8e835048b9d1ee9843d7587cacf527101.zip |
Merge pull request #23203 from janvorli/fix-no-return-false-positives
Fix no-return false positives in static analyzer build
-rw-r--r-- | src/inc/check.h | 4 | ||||
-rw-r--r-- | src/inc/debugmacros.h | 3 | ||||
-rw-r--r-- | src/inc/palclr.h | 2 | ||||
-rw-r--r-- | src/jit/error.h | 5 | ||||
-rw-r--r-- | src/jit/host.h | 2 | ||||
-rw-r--r-- | src/pal/inc/pal.h | 6 | ||||
-rw-r--r-- | src/pal/src/include/pal/dbgmsg.h | 13 |
7 files changed, 25 insertions, 10 deletions
diff --git a/src/inc/check.h b/src/inc/check.h index b1fdba9211..b401a2590e 100644 --- a/src/inc/check.h +++ b/src/inc/check.h @@ -473,7 +473,7 @@ CHECK CheckValue(TYPENAME &val) // in a free build they are passed through to the compiler to use in optimization. //-------------------------------------------------------------------------------- -#if defined(_PREFAST_) || defined(_PREFIX_) +#if defined(_PREFAST_) || defined(_PREFIX_) || defined(__clang_analyzer__) #define COMPILER_ASSUME_MSG(_condition, _message) if (!(_condition)) __UNREACHABLE(); #define COMPILER_ASSUME_MSGF(_condition, args) if (!(_condition)) __UNREACHABLE(); #else @@ -561,7 +561,7 @@ CHECK CheckValue(TYPENAME &val) # define __UNREACHABLE() __assume(0) #endif #else -#define __UNREACHABLE() do { } while(true) +#define __UNREACHABLE() __builtin_unreachable() #endif #ifdef _DEBUG_IMPL diff --git a/src/inc/debugmacros.h b/src/inc/debugmacros.h index ef809cb69d..540be99c74 100644 --- a/src/inc/debugmacros.h +++ b/src/inc/debugmacros.h @@ -13,6 +13,7 @@ #include "stacktrace.h" #include "debugmacrosext.h" +#include "palclr.h" #undef _ASSERTE #undef VERIFY @@ -29,7 +30,7 @@ bool GetStackTraceAtContext(SString & s, struct _CONTEXT * pContext); void _cdecl DbgWriteEx(LPCTSTR szFmt, ...); bool _DbgBreakCheck(LPCSTR szFile, int iLine, LPCSTR szExpr, BOOL fConstrained = FALSE); -extern VOID DbgAssertDialog(const char *szFile, int iLine, const char *szExpr); +extern VOID ANALYZER_NORETURN DbgAssertDialog(const char *szFile, int iLine, const char *szExpr); #define TRACE_BUFF_SIZE (cchMaxAssertStackLevelStringLen * cfrMaxAssertStackLevels + cchMaxAssertExprLen + 1) extern char g_szExprWithStack[TRACE_BUFF_SIZE]; diff --git a/src/inc/palclr.h b/src/inc/palclr.h index 60b97305eb..3b42ac5dae 100644 --- a/src/inc/palclr.h +++ b/src/inc/palclr.h @@ -53,6 +53,8 @@ #endif // !_MSC_VER #endif // !NOINLINE +#define ANALYZER_NORETURN + // // CPP_ASSERT() can be used within a class definition, to perform a // compile-time assertion involving private names within the class. diff --git a/src/jit/error.h b/src/jit/error.h index 944eaca263..18beb4b151 100644 --- a/src/jit/error.h +++ b/src/jit/error.h @@ -73,12 +73,13 @@ extern void DECLSPEC_NORETURN noWayAssertBody(const char* cond, const char* file // Conditionally invoke the noway assert body. The conditional predicate is evaluated using a method on the tlsCompiler. // If a noway_assert is hit, we ask the Compiler whether to raise an exception (i.e., conditionally raise exception.) // To have backward compatibility between v4.5 and v4.0, in min-opts we take a shot at codegen rather than rethrow. -extern void noWayAssertBodyConditional( +extern void ANALYZER_NORETURN noWayAssertBodyConditional( #ifdef FEATURE_TRACELOGGING const char* file, unsigned line #endif ); -extern void noWayAssertBodyConditional(const char* cond, const char* file, unsigned line); + +extern void ANALYZER_NORETURN noWayAssertBodyConditional(const char* cond, const char* file, unsigned line); // Define MEASURE_NOWAY to 1 to enable code to count and rank individual noway_assert calls by occurrence. // These asserts would be dynamically executed, but not necessarily fail. The provides some insight into diff --git a/src/jit/host.h b/src/jit/host.h index f7cbdcfb00..436c3d1457 100644 --- a/src/jit/host.h +++ b/src/jit/host.h @@ -35,7 +35,7 @@ void gcDump_logf(const char* fmt, ...); void logf(unsigned level, const char* fmt, ...); -extern "C" void __cdecl assertAbort(const char* why, const char* file, unsigned line); +extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const char* file, unsigned line); #undef assert #define assert(p) (void)((p) || (assertAbort(#p, __FILE__, __LINE__), 0)) diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index cdb376068e..26c9e3f6d8 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -168,6 +168,12 @@ typedef PVOID NATIVE_LIBRARY_HANDLE; #define DECLSPEC_NORETURN PAL_NORETURN +#ifdef __clang_analyzer__ +#define ANALYZER_NORETURN __attribute((analyzer_noreturn)) +#else +#define ANALYZER_NORETURN +#endif + #if !defined(_MSC_VER) || defined(SOURCE_FORMATTING) #define __assume(x) (void)0 #define __annotation(x) diff --git a/src/pal/src/include/pal/dbgmsg.h b/src/pal/src/include/pal/dbgmsg.h index 641de90a60..d7219b2bd4 100644 --- a/src/pal/src/include/pal/dbgmsg.h +++ b/src/pal/src/include/pal/dbgmsg.h @@ -355,6 +355,14 @@ bool DBG_ShouldCheckStackAlignment(); #else /* defined(_DEBUG) */ +inline void ANALYZER_NORETURN AssertBreak() +{ + if(g_Dbg_asserts_enabled) + { + DebugBreak(); + } +} + #define ASSERT(...) \ { \ __ASSERT_ENTER(); \ @@ -362,10 +370,7 @@ bool DBG_ShouldCheckStackAlignment(); { \ DBG_printf(defdbgchan,DLI_ASSERT,TRUE,__FUNCTION__,__FILE__,__LINE__,__VA_ARGS__); \ } \ - if(g_Dbg_asserts_enabled) \ - { \ - DebugBreak(); \ - } \ + AssertBreak(); \ } #define _ASSERT(expr) do { if (!(expr)) { ASSERT(""); } } while(0) |