Fix invalid-noreturn warning for __CorHlprThrowOOM in corhlpr.h (dotnet/coreclr#23524)
authorIlia <ki.stfu@gmail.com>
Mon, 4 Nov 2019 10:42:54 +0000 (13:42 +0300)
committerJan Vorlicek <janvorli@microsoft.com>
Mon, 4 Nov 2019 10:42:54 +0000 (11:42 +0100)
* Fix invalid-noreturn warning for __CorHlprThrowOOM in corhlpr.h

Commit migrated from https://github.com/dotnet/coreclr/commit/c30381fbe8779e13bbc08591b86cb3d158953212

src/coreclr/src/inc/check.h
src/coreclr/src/inc/corhlpr.h
src/coreclr/src/inc/gcinfodecoder.h
src/coreclr/src/inc/unreachable.h [new file with mode: 0644]

index c303cdb..ca335bd 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "static_assert.h"
 #include "daccess.h"
+#include "unreachable.h"
 
 #ifdef _DEBUG
 
@@ -557,19 +558,6 @@ CHECK CheckValue(TYPENAME &val)
 
 #endif // __llvm__ else
 
-#if defined(_MSC_VER) || defined(_PREFIX_)
-#if defined(_TARGET_AMD64_)
-// Empty methods that consist of UNREACHABLE() result in a zero-sized declspec(noreturn) method
-// which causes the pdb file to make the next method declspec(noreturn) as well, thus breaking BBT
-// Remove when we get a VC compiler that fixes VSW 449170
-# define __UNREACHABLE() DebugBreak(); __assume(0);
-#else
-# define __UNREACHABLE() __assume(0)
-#endif
-#else
-#define __UNREACHABLE() __builtin_unreachable()
-#endif
-
 #ifdef _DEBUG_IMPL
 
 // Note that the "do { } while (0)" syntax trick here doesn't work, as the compiler
index 369fdcc..06f973d 100644 (file)
@@ -21,6 +21,7 @@
 #include "cor.h"
 #include "corhdr.h"
 #include "corerror.h"
+#include "unreachable.h"
 
 // This header is consumed both within the runtime and externally. In the former
 // case we need to wrap memory allocations, in the latter there is no
@@ -43,6 +44,7 @@ inline void DECLSPEC_NORETURN THROW_OUT_OF_MEMORY()
 static inline void DECLSPEC_NORETURN __CorHlprThrowOOM()
 {
     RaiseException(STATUS_NO_MEMORY, 0, 0, NULL);
+    __UNREACHABLE();
 }
 static inline BYTE *__CorHlprNewThrows(size_t bytes)
 {
index de14eb0..fee5942 100644 (file)
@@ -138,12 +138,6 @@ inline BOOL IS_ALIGNED( void* val, size_t alignment )
 
 #endif
 
-// Stuff from check.h:
-
-#ifndef UNREACHABLE
-#define UNREACHABLE() __assume(0)
-#endif
-
 // Stuff from eetwain.h:
 
 #ifndef _EETWAIN_H
diff --git a/src/coreclr/src/inc/unreachable.h b/src/coreclr/src/inc/unreachable.h
new file mode 100644 (file)
index 0000000..5810f67
--- /dev/null
@@ -0,0 +1,26 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+// ---------------------------------------------------------------------------
+// unreachable.h
+// ---------------------------------------------------------------------------
+
+
+#ifndef __UNREACHABLE_H__
+#define __UNREACHABLE_H__
+
+#if defined(_MSC_VER) || defined(_PREFIX_)
+#if defined(_TARGET_AMD64_)
+// Empty methods that consist of UNREACHABLE() result in a zero-sized declspec(noreturn) method
+// which causes the pdb file to make the next method declspec(noreturn) as well, thus breaking BBT
+// Remove when we get a VC compiler that fixes VSW 449170
+# define __UNREACHABLE() do { DebugBreak(); __assume(0); } while (0)
+#else
+# define __UNREACHABLE() __assume(0)
+#endif
+#else
+#define __UNREACHABLE() __builtin_unreachable()
+#endif
+
+#endif // __UNREACHABLE_H__
+