[PATCH] D152093: [clang][Analysis] Handle && and || against variable and its negation as tautology

Takuya Shimizu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 4 03:03:34 PDT 2023


hazohelet created this revision.
hazohelet added reviewers: aaron.ballman, tbaeder, erichkeane.
Herald added a reviewer: NoQ.
Herald added a project: All.
hazohelet requested review of this revision.
Herald added a project: clang.

This patch introduces a new warning flag `-Wtautological-negation-compare` grouped in `-Wtautological-compare` that warns on the use of `&&` or `||` operators against a variable and its negation.
e.g. `x || !x` and `!x && x`
This also makes the `-Winfinite-recursion` diagnose more cases.

Fixes https://github.com/llvm/llvm-project/issues/56035


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152093

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Analysis/CFG.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/CFG.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Analysis/temp-obj-dtors-cfg-output.cpp
  clang/test/Misc/warning-wall.c
  clang/test/SemaCXX/tautological-negation-compare.cpp
  clang/test/SemaCXX/warn-infinite-recursion.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152093.528193.patch
Type: text/x-patch
Size: 10831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230604/dc030e54/attachment.bin>


More information about the cfe-commits mailing list