[lld] r197732 - [lld] fix unused variable warning in non-debug builds

Nick Kledzik kledzik at apple.com
Fri Dec 20 11:56:31 PST 2013


On Dec 20, 2013, at 11:25 AM, dblaikie at gmail.com wrote:
> Generally we prefer not to use unreachable when an assert is intended. The common fix for "but the variable is only used in debug builds is to add a "(void)var;" on the line before/after/near the assert.
Thanks.  I thought about that, but as a said in the comment, the real fix is that Passes need to be able to return an error.  Then there will be no need for an assert or fatal error.

-Nick


> 
> On Thu Dec 19 2013 at 2:34:38 PM, Nick Kledzik <kledzik at apple.com> wrote:
> Author: kledzik
> Date: Thu Dec 19 16:29:07 2013
> New Revision: 197732
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=197732&view=rev
> Log:
> [lld] fix unused variable warning in non-debug builds
> 
> Modified:
>     lld/trunk/lib/Passes/RoundTripNativePass.cpp
>     lld/trunk/lib/Passes/RoundTripYAMLPass.cpp
> 
> Modified: lld/trunk/lib/Passes/RoundTripNativePass.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/RoundTripNativePass.cpp?rev=197732&r1=197731&r2=197732&view=diff
> ==============================================================================
> --- lld/trunk/lib/Passes/RoundTripNativePass.cpp (original)
> +++ lld/trunk/lib/Passes/RoundTripNativePass.cpp Thu Dec 19 16:29:07 2013
> @@ -41,8 +41,11 @@ void RoundTripNativePass::perform(std::u
> 
>    std::unique_ptr<MemoryBuffer> mb(buff.take());
>    error_code ec = _context.registry().parseFile(mb, _nativeFile);
> -  assert(!ec && "native reader not registered");
> -  File *objFile =  _nativeFile[0].get();
> +  if (ec) {
> +    // Note: we need a way for Passes to report errors.
> +    llvm_unreachable("native reader not registered or read error");
> +  }
> +  File *objFile = _nativeFile[0].get();
>    mergedFile.reset(new FileToMutable(_context, *objFile));
> 
>    llvm::sys::fs::remove(tmpNativeFile.str());
> 
> Modified: lld/trunk/lib/Passes/RoundTripYAMLPass.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/RoundTripYAMLPass.cpp?rev=197732&r1=197731&r2=197732&view=diff
> ==============================================================================
> --- lld/trunk/lib/Passes/RoundTripYAMLPass.cpp (original)
> +++ lld/trunk/lib/Passes/RoundTripYAMLPass.cpp Thu Dec 19 16:29:07 2013
> @@ -46,11 +46,12 @@ void RoundTripYAMLPass::perform(std::uni
>    if (buff->getBufferSize() < MAX_YAML_FILE_SIZE) {
>      std::unique_ptr<MemoryBuffer> mb(buff.take());
>      error_code ec = _context.registry().parseFile(mb, _yamlFile);
> -    assert(!ec && "yaml reader not registered");
> -    File *objFile =  _yamlFile[0].get();
> -    const File *obj = dyn_cast<const File>(objFile);
> -    assert(obj && "yaml generated file is not an relocatable file");
> -    mergedFile.reset(new FileToMutable(_context, *obj));
> +    if (ec) {
> +      // Note: we need a way for Passes to report errors.
> +      llvm_unreachable("yaml reader not registered or read error");
> +    }
> +    File *objFile = _yamlFile[0].get();
> +    mergedFile.reset(new FileToMutable(_context, *objFile));
>    }
> 
>    llvm::sys::fs::remove(tmpYAMLFile.str());
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131220/8d4cb14d/attachment.html>


More information about the llvm-commits mailing list