[llvm-commits] [PATCH] Error cannot be reached

Cameron McInally mcinally at cray.com
Thu May 12 22:10:46 PDT 2011


Hey Chris,

The code in trunk looks like this:

if (R->getName() == "node" && !OpName.empty()) { //Let's call this (1)
  if (OpName.empty()) //Let's call this (2)
    error("'node' argument requires a name to match with operand list");
  Args.push_back(OpName);
}

Unless the expression OpName.empty() has side-effects, which I am fairly confident that it does not, the call cannot evaluate to false at (1) and true at (2). I'm assuming that '==' has a higher precedence than '&&' in C++, but maybe I'm mistaken. Is that not correct?

Essentially, this code sequence is:

bool b = true;
if(b) {
  if(!b) {
    printf("unreachable\n");
  }
}

Cameron

________________________________________
From: Chris Lattner [clattner at apple.com]
Sent: Thursday, May 12, 2011 11:18 PM
To: Cameron McInally
Cc: llvm-commits at cs.uiuc.edu
Subject: Re: [llvm-commits] [PATCH] Error cannot be reached

On May 12, 2011, at 2:47 PM, Cameron McInally wrote:

> A silly little patch for unreachable code. It's self-explanatory:

How is that unreachable?  OpName != R->getName()

-Chris

>
> mcinally/llvm> svn diff
> Index: utils/TableGen/CodeGenDAGPatterns.cpp
> ===================================================================
> --- utils/TableGen/CodeGenDAGPatterns.cpp    (revision 131245)
> +++ utils/TableGen/CodeGenDAGPatterns.cpp    (working copy)
> @@ -1732,7 +1732,7 @@
>
>     // Input argument?
>     TreePatternNode *Res = new TreePatternNode(DI, 1);
> -    if (R->getName() == "node" && !OpName.empty()) {
> +    if (R->getName() == "node") {
>       if (OpName.empty())
>         error("'node' argument requires a name to match with operand
> list");
>       Args.push_back(OpName);
>
> mcinally/llvm> svn info
> Path: .
> URL: http://llvm.org/svn/llvm-project/llvm/trunk
> Repository Root: http://llvm.org/svn/llvm-project
> Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8
> Revision: 131241
> Node Kind: directory
> Schedule: normal
> Last Changed Author: evancheng
> Last Changed Rev: 131241
> Last Changed Date: 2011-05-12 15:30:01 -0500 (Thu, 12 May 2011)
>
> Thanks,
> Cameron
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list