llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

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

Open ymand opened this issue 2 years ago • 2 comments

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.

ymand avatar Feb 23 '24 17:02 ymand

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

11happy avatar Mar 02 '24 15:03 11happy

Looks like this is fixed in https://github.com/llvm/llvm-project/pull/131575

(there was some subtlety with nullptr literals that required thorough testing to surface)

jvoung avatar Mar 03 '26 15:03 jvoung