Fix uninitialized warnings from late switch lowering.
Corrects `is_use_guarded` logic to prevent false positives in uninitialized variable warnings after switch lowering.
This commit addresses false positives in the -Wuninitialized warning pass by fixing the uninit_analysis::is_use_guarded function. The issue stemmed from pass_lower_switch being moved after late jump threading, which exposed a defect where an empty use predicate (PHI defined and used in the same block) was incorrectly treated as unguarded. The fix ensures this condition is properly evaluated based on the definition predicate.
In Details
This patch targets gcc/tree-ssa/uninit.cc and gcc/tree-ssa/cfg.cc, specifically uninit_analysis::is_use_guarded and predicate::simplify_2. The defect arose because is_use_guarded incorrectly returns false for empty use predicates (where a PHI is defined and used in the same basic block). This commit corrects this by ensuring the definition predicate is checked. Additionally, it refactors how predicate::simplify_2 handles tautological disjunctions (simplifying to TRUE) and normalizes predicates to correctly identify guarded uses, resolving false positives from PR107919 and PR44…
- PHI node
- A special node in Static Single Assignment (SSA) form that represents the value of a variable which might have different definitions depending on the control flow path taken to reach it.
- GIMPLE
- GNU Intermediate Representation Language. A low-level, three-address code representation used by GCC after initial parsing and before machine code generation.
- SSA form
- Static Single Assignment form. An intermediate representation where every variable is assigned a value exactly once, simplifying many compiler optimizations.
- predicate
- In this context, a logical expression representing a condition, often used to determine if a variable is initialized or if a use is guarded.
- uninitialized warning
- A compiler warning (e.g.,
-Wuninitialized) that alerts the programmer to potential uses of variables before they have been assigned a defined value. - jump threading
- An optimization technique that identifies sequences of conditional branches and replaces them with direct branches to the ultimate target, simplifying control flow.