Skip to content

Commit bfb686b

Browse files
committed
Thread Safety Analysis: Move opcode comparison to Comparator (NFC)
The switch assumes that both operands have the same opcode, so it's probably cleaner if we do the comparison there. This also deduplicates the comparison.
1 parent 86203b6 commit bfb686b

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

clang/include/clang/Analysis/Analyses/ThreadSafetyTraverse.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ class Comparator {
312312
Self *self() { return reinterpret_cast<Self *>(this); }
313313

314314
public:
315-
bool compareByCase(const SExpr *E1, const SExpr* E2) {
315+
bool compare(const SExpr *E1, const SExpr *E2) {
316+
if (E1->opcode() != E2->opcode())
317+
return false;
316318
switch (E1->opcode()) {
317319
#define TIL_OPCODE_DEF(X) \
318320
case COP_##X: \
@@ -338,12 +340,6 @@ class EqualsComparator : public Comparator<EqualsComparator> {
338340
bool compareStrings (StringRef s, StringRef r) { return s == r; }
339341
bool comparePointers(const void* P, const void* Q) { return P == Q; }
340342

341-
bool compare(const SExpr *E1, const SExpr* E2) {
342-
if (E1->opcode() != E2->opcode())
343-
return false;
344-
return compareByCase(E1, E2);
345-
}
346-
347343
// TODO -- handle alpha-renaming of variables
348344
void enterScope(const Variable *V1, const Variable *V2) {}
349345
void leaveScope() {}
@@ -377,9 +373,7 @@ class MatchComparator : public Comparator<MatchComparator> {
377373
if (E1->opcode() == COP_Wildcard || E2->opcode() == COP_Wildcard)
378374
return true;
379375
// otherwise normal equality.
380-
if (E1->opcode() != E2->opcode())
381-
return false;
382-
return compareByCase(E1, E2);
376+
return Comparator::compare(E1, E2);
383377
}
384378

385379
// TODO -- handle alpha-renaming of variables

0 commit comments

Comments
 (0)