llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.34k stars 11.7k forks source link

Boolean equality of two undefined bools incorrectly interpreted as "true" #82802

Open ymand opened 7 months ago

ymand commented 7 months ago

The built-in interpretation of boolean equality forgets to check for nullness before checking for pointer equality:

  Value *LHSValue = Env.getValue(LHS);
  Value *RHSValue = Env.getValue(RHS);

  if (LHSValue == RHSValue)
    return Env.getBoolLiteralValue(true);

https://github.com/llvm/llvm-project/blob/dfa1d9b027e677cf1379dffee0059261a34f3481/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L58-L59

Therefore, when both are null, the equality will be interpreted as true.

11happy commented 7 months ago

Hello @ymand the fix seems pretty easy , If you are not currently working on this may I open a PR?