Skip to content
Snippets Groups Projects
  • Simon Tatham's avatar
    0112936e
    Replace assert(false) with an unreachable() macro. · 0112936e
    Simon Tatham authored
    Taking a leaf out of the LLVM code base: this macro still includes an
    assert(false) so that the message will show up in a typical build, but
    it follows it up with a call to a function explicitly marked as no-
    return.
    
    So this ought to do a better job of convincing compilers that once a
    code path hits this function it _really doesn't_ have to still faff
    about with making up a bogus return value or filling in a variable
    that 'might be used uninitialised' in the following code that won't be
    reached anyway.
    
    I've gone through the existing code looking for the assert(false) /
    assert(0) idiom and replaced all the ones I found with the new macro,
    which also meant I could remove a few pointless return statements and
    variable initialisations that I'd already had to put in to placate
    compiler front ends.
    0112936e
    History
    Replace assert(false) with an unreachable() macro.
    Simon Tatham authored
    Taking a leaf out of the LLVM code base: this macro still includes an
    assert(false) so that the message will show up in a typical build, but
    it follows it up with a call to a function explicitly marked as no-
    return.
    
    So this ought to do a better job of convincing compilers that once a
    code path hits this function it _really doesn't_ have to still faff
    about with making up a bogus return value or filling in a variable
    that 'might be used uninitialised' in the following code that won't be
    reached anyway.
    
    I've gone through the existing code looking for the assert(false) /
    assert(0) idiom and replaced all the ones I found with the new macro,
    which also meant I could remove a few pointless return statements and
    variable initialisations that I'd already had to put in to placate
    compiler front ends.