From 5b8679eae47a8f9b40692a7ceda1f480f9780efe Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Thu, 17 Nov 2016 18:41:18 +0000 Subject: [PATCH] ObjC Module: try to make objc module deterministic. Make sure that comparing selectors in DeclarationName does its job. rdar://problem/28988750 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287244 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclarationName.cpp | 10 ++++++++-- test/Modules/stress-objc.m | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/Modules/stress-objc.m diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index fea887e173..52791e51d2 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -95,12 +95,18 @@ int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) { case DeclarationName::ObjCMultiArgSelector: { Selector LHSSelector = LHS.getObjCSelector(); Selector RHSSelector = RHS.getObjCSelector(); + // getNumArgs for ZeroArgSelector returns 0, but we still need to compare. + if (LHS.getNameKind() == DeclarationName::ObjCZeroArgSelector && + RHS.getNameKind() == DeclarationName::ObjCZeroArgSelector) { + return LHSSelector.getAsIdentifierInfo()->getName().compare( + RHSSelector.getAsIdentifierInfo()->getName()); + } unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs(); for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) { switch (LHSSelector.getNameForSlot(I).compare( RHSSelector.getNameForSlot(I))) { - case -1: return true; - case 1: return false; + case -1: return -1; + case 1: return 1; default: break; } } diff --git a/test/Modules/stress-objc.m b/test/Modules/stress-objc.m new file mode 100644 index 0000000000..edbebd3576 --- /dev/null +++ b/test/Modules/stress-objc.m @@ -0,0 +1,22 @@ +// RUN: cd %S + +// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00.pch -fno-pch-timestamp +// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_1.pch -fno-pch-timestamp +// RUN: diff %t_c00.pch %t_c00_1.pch + +// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_2.pch -fno-pch-timestamp +// RUN: diff %t_c00.pch %t_c00_2.pch + +// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_3.pch -fno-pch-timestamp +// RUN: diff %t_c00.pch %t_c00_3.pch + +// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_4.pch -fno-pch-timestamp +// RUN: diff %t_c00.pch %t_c00_4.pch + +// RUN: %clang_cc1 -emit-pch -x objective-c-header %s -o %t_c00_5.pch -fno-pch-timestamp +// RUN: diff %t_c00.pch %t_c00_5.pch + +@protocol NSObject +- (void)doesNotRecognizeSelector:(SEL)aSelector; +- (id)forwardingTargetForSelector:(SEL)aSelector; +@end -- 2.40.0