[lld] r179590 - Moved llvm_unreachable out of switch blocks to avoid the "control reaches end of non-void function" warning.

Nick Kledzik kledzik at apple.com
Tue Apr 16 11:34:09 PDT 2013


On Apr 16, 2013, at 9:59 AM, Andy Gibbs wrote:

> On Tuesday, April 16, 2013 6:34 PM, Nick Kledzik wrote:
> 
>> What compiler is issuing the warning?  llvm_unreachable() is
>> designed to look like a no-return function, so that compilers
>> will not issue that warning.
>> 
>> -Nick
> 
> gcc produces this warning, since the enum value in the switch statement "may" be any value, not necessarily one of the proper values, and so execution can reach beyond the end of the switch block.  Personally I think clang should also produce a warning in this case.
> 
> (Its covered, rather more elegantly, as a subscript to http://llvm.org/docs/CodingStandards.html#don-t-use-default-labels-in-fully-covered-switches-over-enumerations)

Ah!  In that case, I think you want to distinguish between a known enum value that should not happen and an invalid enum value.  E.g.

  case Flavor::core:
    return CoreDriver::link(args.size(), args.data(), diagnostics);
  case Flavor::win_link:
    llvm_unreachable("Unsupported flavor");
   break;
  case Flavor::invalid:
    return true;
  }
  llvm_unreachable("Invalid enum value");
}





More information about the llvm-commits mailing list