[llvm] r218222 - Use llvm_unreachable instead of assert(!)

David Blaikie dblaikie at gmail.com
Sun Sep 21 18:32:22 PDT 2014


On Sun, Sep 21, 2014 at 10:27 AM, Matt Arsenault <Matthew.Arsenault at amd.com>
wrote:

> Author: arsenm
> Date: Sun Sep 21 12:27:31 2014
> New Revision: 218222
>
> URL: http://llvm.org/viewvc/llvm-project?rev=218222&view=rev
> Log:
> Use llvm_unreachable instead of assert(!)
>
> Modified:
>     llvm/trunk/lib/Target/R600/InstPrinter/AMDGPUInstPrinter.cpp
>
> Modified: llvm/trunk/lib/Target/R600/InstPrinter/AMDGPUInstPrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/InstPrinter/AMDGPUInstPrinter.cpp?rev=218222&r1=218221&r2=218222&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Target/R600/InstPrinter/AMDGPUInstPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/R600/InstPrinter/AMDGPUInstPrinter.cpp Sun Sep
> 21 12:27:31 2014
> @@ -232,7 +232,7 @@ void AMDGPUInstPrinter::printOperand(con
>      const MCExpr *Exp = Op.getExpr();
>      Exp->print(O);
>    } else {
> -    assert(!"unknown operand type in printOperand");
> +    llvm_unreachable("unknown operand type in printOperand");
>

Alternatively you could remove the previous if condition (isExpr) and
replace it with an assertion (actually I assume getExpr already has such an
assertion?) So the compiler doesn't have to work so hard to remove the
isExpr (even though the unreachable proves the isExpr is always true, if it
can't prove the absence of side effects it's still going to keep the call
in the code just in case)


>    }
>  }
>
> @@ -259,7 +259,7 @@ void AMDGPUInstPrinter::printInterpSlot(
>    } else if (Imm == 0) {
>      O << "P10";
>    } else {
> -    assert(!"Invalid interpolation parameter slot");
> +    llvm_unreachable("Invalid interpolation parameter slot");
>

Similarly here.

(not always the better choice, mind you - sometimes keeping the code
structure and just putting unreachable at the end keeps the code more
consistent, etc)


>    }
>  }
>
>
>
> _______________________________________________
> 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/20140921/862fd506/attachment.html>


More information about the llvm-commits mailing list