This is an archive of the discontinued LLVM Phabricator instance.

[clang][sema] Fix collectConjunctionTerms()
ClosedPublic

Authored by tbaeder on Aug 3 2022, 6:23 AM.

Details

Summary

Consider:

A == 5 && A != 5

IfA is 5, the old collectConjunctionTerms() would call itself again for
the LHS (which it ignores), then the RHS (which it also ignores) and
then just return without ever adding anything to the Terms array.

For example, there's a test case in clang/test/SemaCXX/recovery-expr-type.cpp:

namespace test13 {
enum Circular {             // expected-note {{not complete until the closing '}'}}
  Circular_A = Circular(1), // expected-error {{'Circular' is an incomplete type}}
};
// Enumerators can be evaluated (they evaluate as zero, but we don't care).
static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static assertion failed}}
}

which currently prints:

test2.cpp:6:1: error: static assertion failed due to requirement 'Circular_A == 0 && Circular_A != 0':
static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static assertion failed}}
^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

(other diagnostics omitted)

but after this change prints:

test2.cpp:6:1: error: static assertion failed due to requirement 'Circular_A != 0':
static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static assertion failed}}
^                                ~~~~~~~~~~~~~~~
2 errors generated.

The patch depends on https://reviews.llvm.org/D130894 because of the note it adds, but that's not necessary. It's just easier because they are both in my local tree.

I wanted to add Douglas Gregor as reviewer as well but seems like he isn't around anymore.

Diff Detail

Event Timeline

tbaeder created this revision.Aug 3 2022, 6:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 6:23 AM
tbaeder requested review of this revision.Aug 3 2022, 6:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 6:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

It looks like precommit CI caught a relevant issue

That's just because of the note that https://reviews.llvm.org/D130894 adds, which the patch expects.

aaron.ballman accepted this revision.Aug 4 2022, 5:12 AM

Oh shoot, I saw that precommit CI made it past patch application failing (last time) and I thought the precommit CI bug was fixed and so it was testing the whole stack for once. Drat.

LGTM once we finish up with what this builds on.

This revision is now accepted and ready to land.Aug 4 2022, 5:12 AM

FWIW I switched it around so _this_ patch is now good as-is while https://reviews.llvm.org/D130894 now depends on this one.

This revision was landed with ongoing or failed builds.Aug 4 2022, 9:48 PM
This revision was automatically updated to reflect the committed changes.