| 1 |
/// @file |
| 2 |
/// @ingroup cgraph_utils |
| 3 |
#pragma once |
| 4 |
|
| 5 |
#include <assert.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
/** Marker for a point in code which execution can never reach. |
| 10 |
* |
| 11 |
* As a C11 function, this could be thought of as: |
| 12 |
* |
| 13 |
* _Noreturn void UNREACHABLE(void); |
| 14 |
* |
| 15 |
* This can be used to explain that a switch is exhaustive: |
| 16 |
* |
| 17 |
* switch (…) { |
| 18 |
* default: UNREACHABLE(); |
| 19 |
* …remaining cases that cover all possibilities… |
| 20 |
* } |
| 21 |
* |
| 22 |
* or that a function coda can be omitted: |
| 23 |
* |
| 24 |
* int foo(void) { |
| 25 |
* while (always_true()) { |
| 26 |
* } |
| 27 |
* UNREACHABLE(); |
| 28 |
* } |
| 29 |
*/ |
| 30 |
#define UNREACHABLE() \ |
| 31 |
do { \ |
| 32 |
fprintf(stderr, "%s:%d: claimed unreachable code was reached\n", __FILE__, \ |
| 33 |
__LINE__); \ |
| 34 |
abort(); \ |
| 35 |
} while (0) |