VTK-m  2.0
Unreachable.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_Unreachable_h
12 #define vtk_m_Unreachable_h
13 
31 #define VTKM_UNREACHABLE(msg) \
32  VTKM_SWALLOW_SEMICOLON_PRE_BLOCK \
33  { \
34  VTKM_UNREACHABLE_IMPL(); \
35  VTKM_UNREACHABLE_PRINT(msg); \
36  VTKM_UNREACHABLE_ABORT(); \
37  } \
38  VTKM_SWALLOW_SEMICOLON_POST_BLOCK
39 
40 // VTKM_UNREACHABLE_IMPL is compiler-specific:
41 #if defined(VTKM_CUDA_DEVICE_PASS)
42 
43 #define VTKM_UNREACHABLE_IMPL() (void)0 /* no-op, no known intrinsic */
44 
45 #if defined(NDEBUG) || defined(VTKM_NO_ASSERT)
46 
47 #define VTKM_UNREACHABLE_PRINT(msg) (void)0 /* no-op */
48 #define VTKM_UNREACHABLE_ABORT() (void)0 /* no-op */
49 
50 #else // NDEBUG || VTKM_NO_ASSERT
51 
52 #define VTKM_UNREACHABLE_PRINT(msg) \
53  printf("Unreachable location reached: %s\nLocation: %s:%d\n", msg, __FILE__, __LINE__)
54 #define VTKM_UNREACHABLE_ABORT() \
55  asm("trap;") /* Triggers kernel exit with CUDA error 73: Illegal inst */
56 
57 #endif // NDEBUG || VTKM_NO_ASSERT
58 
59 #else // !CUDA
60 
61 
62 #if defined(NDEBUG) || defined(VTKM_NO_ASSERT)
63 
64 #define VTKM_UNREACHABLE_PRINT(msg) (void)0 /* no-op */
65 #define VTKM_UNREACHABLE_ABORT() (void)0 /* no-op */
66 
67 #if defined(VTKM_MSVC)
68 #define VTKM_UNREACHABLE_IMPL() __assume(false)
69 #elif defined(VTKM_ICC) && !defined(__GNUC__)
70 #define VTKM_UNREACHABLE_IMPL() __assume(false)
71 #elif (defined(VTKM_GCC) || defined(VTKM_ICC)) && \
72  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
73 // Added in 4.5.0:
74 #define VTKM_UNREACHABLE_IMPL() __builtin_unreachable()
75 #elif defined(VTKM_CLANG)
76 #define VTKM_UNREACHABLE_IMPL() __builtin_unreachable()
77 #else
78 #define VTKM_UNREACHABLE_IMPL() (void)0 /* no-op */
79 #endif
80 
81 #else // NDEBUG || VTKM_NO_ASSERT
82 
83 #define VTKM_UNREACHABLE_IMPL() (void)0
84 #define VTKM_UNREACHABLE_PRINT(msg) \
85  std::cerr << "Unreachable location reached: " << msg << "\n" \
86  << "Location: " << __FILE__ << ":" << __LINE__ << "\n"
87 #define VTKM_UNREACHABLE_ABORT() abort()
88 
89 #endif // NDEBUG && !VTKM_NO_ASSERT
90 
91 #endif // !CUDA
92 
93 #endif //vtk_m_Unreachable_h