Viskores  1.0
Unreachable.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 
19 #ifndef viskores_Unreachable_h
20 #define viskores_Unreachable_h
21 
39 #define VISKORES_UNREACHABLE(msg) \
40  VISKORES_SWALLOW_SEMICOLON_PRE_BLOCK \
41  { \
42  VISKORES_UNREACHABLE_IMPL(); \
43  VISKORES_UNREACHABLE_PRINT(msg); \
44  VISKORES_UNREACHABLE_ABORT(); \
45  } \
46  VISKORES_SWALLOW_SEMICOLON_POST_BLOCK
47 
48 // VISKORES_UNREACHABLE_IMPL is compiler-specific:
49 #if defined(VISKORES_CUDA_DEVICE_PASS)
50 
51 #define VISKORES_UNREACHABLE_IMPL() (void)0 /* no-op, no known intrinsic */
52 
53 #if defined(NDEBUG) || defined(VISKORES_NO_ASSERT)
54 
55 #define VISKORES_UNREACHABLE_PRINT(msg) (void)0 /* no-op */
56 #define VISKORES_UNREACHABLE_ABORT() (void)0 /* no-op */
57 
58 #else // NDEBUG || VISKORES_NO_ASSERT
59 
60 #define VISKORES_UNREACHABLE_PRINT(msg) \
61  printf("Unreachable location reached: %s\nLocation: %s:%d\n", msg, __FILE__, __LINE__)
62 #define VISKORES_UNREACHABLE_ABORT() \
63  asm("trap;") /* Triggers kernel exit with CUDA error 73: Illegal inst */
64 
65 #endif // NDEBUG || VISKORES_NO_ASSERT
66 
67 #else // !CUDA
68 
69 
70 #if defined(NDEBUG) || defined(VISKORES_NO_ASSERT)
71 
72 #define VISKORES_UNREACHABLE_PRINT(msg) (void)0 /* no-op */
73 #define VISKORES_UNREACHABLE_ABORT() (void)0 /* no-op */
74 
75 #if defined(VISKORES_MSVC)
76 #define VISKORES_UNREACHABLE_IMPL() __assume(false)
77 #elif defined(VISKORES_ICC) && !defined(__GNUC__)
78 #define VISKORES_UNREACHABLE_IMPL() __assume(false)
79 #elif (defined(VISKORES_GCC) || defined(VISKORES_ICC)) && \
80  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
81 // Added in 4.5.0:
82 #define VISKORES_UNREACHABLE_IMPL() __builtin_unreachable()
83 #elif defined(VISKORES_CLANG)
84 #define VISKORES_UNREACHABLE_IMPL() __builtin_unreachable()
85 #else
86 #define VISKORES_UNREACHABLE_IMPL() (void)0 /* no-op */
87 #endif
88 
89 #else // NDEBUG || VISKORES_NO_ASSERT
90 
91 #define VISKORES_UNREACHABLE_IMPL() (void)0
92 #define VISKORES_UNREACHABLE_PRINT(msg) \
93  std::cerr << "Unreachable location reached: " << msg << "\n" \
94  << "Location: " << __FILE__ << ":" << __LINE__ << "\n"
95 #define VISKORES_UNREACHABLE_ABORT() abort()
96 
97 #endif // NDEBUG && !VISKORES_NO_ASSERT
98 
99 #endif // !CUDA
100 
101 #endif //viskores_Unreachable_h