[all-commits] [llvm/llvm-project] 70471f: [Sema] Fix -Wunreachable-code false negative when ...

M. Zeeshan Siddiqui via All-commits all-commits at lists.llvm.org
Wed Jul 30 18:22:22 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 70471f08ee109cd0472fdd6659c2a1ad236c6835
      https://github.com/llvm/llvm-project/commit/70471f08ee109cd0472fdd6659c2a1ad236c6835
  Author: M. Zeeshan Siddiqui <mzs at microsoft.com>
  Date:   2025-07-31 (Thu, 31 Jul 2025)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/AST/Expr.cpp
    M clang/test/Sema/warn-unreachable_crash.cpp

  Log Message:
  -----------
  [Sema] Fix -Wunreachable-code false negative when operands differ only by implicit casts (#149972)

## Motivation  
`-Wunreachable-code` missed—or in rare cases crashed on—tautological
comparisons such as

```cpp
x != 0 || x != 1.0   // always true
x == 0 && x == 1.0   // always false
```

when the *same* variable appears on both sides but one operand goes
through a floating‑rank promotion that is target‑dependent. On back‑ends
with **native half‑precision** (`_Float16` / `__fp16`) such as
AArch64 `+fullfp16`, no promotion occurs, so the cast stacks between the
two operands differ and the existing heuristic bails out.

## Technical description 
* **Extends `Expr::isSameComparisonOperand()`** – the helper now ignores
parentheses **and value‑preserving implicit casts**
(`CK_LValueToRValue`, floating‑rank `CK_FloatingCast`) before comparing
the underlying operands. This prevents floating‑rank promotions and
lvalue‑to‑rvalue conversions from blocking the unreachable‑code
diagnostic on targets with native FP16.
*No change needed in `CheckIncorrectLogicOperator`; it simply benefits
from the improved helper.*
* **Regression test** – `warn-unreachable_crash.cpp` updated to cover
both the promoted case (x86‑64) and the native‑half case
(AArch64 `+fullfp16`).
* **Docs** – release‑note bullet added under *Bug Fixes in This
Version*.

@ziqingluo-90 @yronglin Could you please review promptly? (feel free to
also merge it on my behalf) Thanks!

Fixes #149967

Co-authored-by: Zeeshan Siddiqui <mzs at ntdev.microsoft.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list