From 67f591a9ce60651da41afc499bd9a22e25314e35 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 3 Aug 2013 21:34:17 +0200 Subject: gcc.h: add macro gcc_unreachable() --- src/DecoderControl.cxx | 2 +- src/OutputInit.cxx | 2 +- src/ReplayGainConfig.cxx | 3 +-- src/audio_format.c | 2 +- src/audio_format.h | 2 +- src/decoder/FlacPcm.cxx | 2 +- src/filter/ChainFilterPlugin.cxx | 1 + src/gcc.h | 6 ++++++ src/output/AlsaOutputPlugin.cxx | 2 +- src/output/JackOutputPlugin.cxx | 1 + src/pcm/PcmMix.cxx | 6 ++---- src/pcm/PcmVolume.cxx | 3 +-- 12 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/DecoderControl.cxx b/src/DecoderControl.cxx index a8f41f564..6721bd55a 100644 --- a/src/DecoderControl.cxx +++ b/src/DecoderControl.cxx @@ -99,7 +99,7 @@ decoder_control::IsCurrentSong(const Song *_song) const } assert(false); - return false; + gcc_unreachable(); } void diff --git a/src/OutputInit.cxx b/src/OutputInit.cxx index da243b54a..6dd40cd67 100644 --- a/src/OutputInit.cxx +++ b/src/OutputInit.cxx @@ -123,7 +123,7 @@ audio_output_load_mixer(struct audio_output *ao, } assert(false); - return NULL; + gcc_unreachable(); } bool diff --git a/src/ReplayGainConfig.cxx b/src/ReplayGainConfig.cxx index d86c70053..ea5054bae 100644 --- a/src/ReplayGainConfig.cxx +++ b/src/ReplayGainConfig.cxx @@ -55,9 +55,8 @@ replay_gain_get_mode_string(void) return "album"; } - /* unreachable */ assert(false); - return "off"; + gcc_unreachable(); } bool diff --git a/src/audio_format.c b/src/audio_format.c index 45d94a853..cfe3a4cae 100644 --- a/src/audio_format.c +++ b/src/audio_format.c @@ -69,7 +69,7 @@ sample_format_to_string(enum sample_format format) /* unreachable */ assert(false); - return "?"; + gcc_unreachable(); } const char * diff --git a/src/audio_format.h b/src/audio_format.h index f9b176bc1..642eaa52a 100644 --- a/src/audio_format.h +++ b/src/audio_format.h @@ -253,7 +253,7 @@ sample_format_size(enum sample_format format) } assert(false); - return 0; + gcc_unreachable(); } /** diff --git a/src/decoder/FlacPcm.cxx b/src/decoder/FlacPcm.cxx index 82896bd24..17a13edda 100644 --- a/src/decoder/FlacPcm.cxx +++ b/src/decoder/FlacPcm.cxx @@ -104,7 +104,7 @@ flac_convert(void *dest, case SAMPLE_FORMAT_FLOAT: case SAMPLE_FORMAT_DSD: case SAMPLE_FORMAT_UNDEFINED: - /* unreachable */ assert(false); + gcc_unreachable(); } } diff --git a/src/filter/ChainFilterPlugin.cxx b/src/filter/ChainFilterPlugin.cxx index c8666615f..ac0f10980 100644 --- a/src/filter/ChainFilterPlugin.cxx +++ b/src/filter/ChainFilterPlugin.cxx @@ -93,6 +93,7 @@ ChainFilter::CloseUntil(const Filter *until) /* this assertion fails if #until does not exist (anymore) */ assert(false); + gcc_unreachable(); } static const struct audio_format * diff --git a/src/gcc.h b/src/gcc.h index 2282ff5e6..1bd770597 100644 --- a/src/gcc.h +++ b/src/gcc.h @@ -79,6 +79,12 @@ #endif +#if defined(__GNUC__) || defined(__clang__) +#define gcc_unreachable() __builtin_unreachable() +#else +#define gcc_unreachable() +#endif + #ifdef __cplusplus #ifdef __GNUC__ diff --git a/src/output/AlsaOutputPlugin.cxx b/src/output/AlsaOutputPlugin.cxx index 17fc91d1a..7d0e9e09c 100644 --- a/src/output/AlsaOutputPlugin.cxx +++ b/src/output/AlsaOutputPlugin.cxx @@ -257,7 +257,7 @@ get_bitformat(enum sample_format sample_format) } assert(false); - return SND_PCM_FORMAT_UNKNOWN; + gcc_unreachable(); } static snd_pcm_format_t diff --git a/src/output/JackOutputPlugin.cxx b/src/output/JackOutputPlugin.cxx index 3bc9cee8f..4f21b36f8 100644 --- a/src/output/JackOutputPlugin.cxx +++ b/src/output/JackOutputPlugin.cxx @@ -696,6 +696,7 @@ mpd_jack_write_samples(JackOutput *jd, const void *src, default: assert(false); + gcc_unreachable(); } } diff --git a/src/pcm/PcmMix.cxx b/src/pcm/PcmMix.cxx index 8435c0c2a..b92258a83 100644 --- a/src/pcm/PcmMix.cxx +++ b/src/pcm/PcmMix.cxx @@ -110,9 +110,8 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size, return true; } - /* unreachable */ assert(false); - return false; + gcc_unreachable(); } template @@ -184,9 +183,8 @@ pcm_add(void *buffer1, const void *buffer2, size_t size, return true; } - /* unreachable */ assert(false); - return false; + gcc_unreachable(); } bool diff --git a/src/pcm/PcmVolume.cxx b/src/pcm/PcmVolume.cxx index 556ab9925..c22017ddd 100644 --- a/src/pcm/PcmVolume.cxx +++ b/src/pcm/PcmVolume.cxx @@ -188,7 +188,6 @@ pcm_volume(void *buffer, size_t length, return true; } - /* unreachable */ assert(false); - return false; + gcc_unreachable(); } -- cgit v1.2.3