Suspicious code in WholeProgramDevirt.cpp?

In DevirtModule::tryUniqueRetValOpt, there’s a lambda that starts like this:

// IsOne controls whether we look for a 0 or a 1.
  auto tryUniqueRetValOptFor = [&](bool IsOne) {
    const BitSetInfo *UniqueBitSet = 0;
    for (const VirtualCallTarget &Target : TargetsForSlot) {
      if (Target.RetVal == IsOne ? 1 : 0) {
        if (UniqueBitSet)
          return false;
        UniqueBitSet = Target.BS;
      }
    }

I’m working on a patch to turn up the warning levels that LLVM compiles at, and I got a new warning:

C4805 ‘==’: unsafe mix of type ‘const uint64_t’ and type ‘bool’ in operation

…pointing at this line:

if (Target.RetVal == IsOne ? 1 : 0) {

It looks to me like that, instead of comparing Target.RetVal to 1 or 0, it’s comparing Target.RetVal to IsOne, which I doubt is the intended outcome!

What’s up with that? Is that a bug?

Yes, this should have read:

if (Target.RetVal == (IsOne ? 1 : 0)) {

As it turns out, this evaluates to the same thing.

I’ve committed a fix in r262907.

Peter