[PATCH] D28231: -Wunreachable-code: Avoid multiple diagnostics that are triggered by the same source range and fix the unary operator fixit source range

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 5 14:41:32 PST 2017


ahatanak added inline comments.


================
Comment at: lib/Analysis/ReachableCode.cpp:229
+      if (SilenceableCondValNotSet && SilenceableCondVal->getBegin().isValid())
+        *SilenceableCondVal = UO->getSourceRange();
+      return UO->getOpcode() == UO_LNot && IsSubExprConfigValue;
----------------
Thanks, that fixed the incorrect fixit. The patch looks good to me, but there are still cases in which the suggestions clang makes are not accurate. Perhaps you can leave a FIXME somewhere so that we don't forget to fix it later?

For example, if we change the condition in the test case to this,

```
if (!(s->p && 0))
```

, clang suggests enclosing the entire expression with a parenthesis (caret points to "!"), but the warning will not go away unless the parenthesis is around "0".

The second example is in function unaryOpFixit in warn-unreachable.c. clang suggests enclosing "-1" with a parenthesis, but it still warns after putting the parenthesis around "-1" or "1".


Repository:
  rL LLVM

https://reviews.llvm.org/D28231





More information about the cfe-commits mailing list