r307296 - [Objective-C] Fix non-determinism in clang
Mandeep Singh Grang via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 6 11:49:57 PDT 2017
Author: mgrang
Date: Thu Jul 6 11:49:57 2017
New Revision: 307296
URL: http://llvm.org/viewvc/llvm-project?rev=307296&view=rev
Log:
[Objective-C] Fix non-determinism in clang
Summary: Iteration of the unordered Ivars causes objc-modern-metadata-visibility.mm (uncovered by reverse iterating SmallPtrSet).
Reviewers: dblaikie, davide, rsmith
Reviewed By: dblaikie
Subscribers: cfe-commits, llvm-commits
Differential Revision: https://reviews.llvm.org/D34860
Added:
cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
Modified:
cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp?rev=307296&r1=307295&r2=307296&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp Thu Jul 6 11:49:57 2017
@@ -146,7 +146,7 @@ namespace {
llvm::DenseMap<BlockExpr *, std::string> RewrittenBlockExprs;
llvm::DenseMap<ObjCInterfaceDecl *,
- llvm::SmallPtrSet<ObjCIvarDecl *, 8> > ReferencedIvars;
+ llvm::SmallSetVector<ObjCIvarDecl *, 8> > ReferencedIvars;
// ivar bitfield grouping containers
llvm::DenseSet<const ObjCInterfaceDecl *> ObjCInterefaceHasBitfieldGroups;
@@ -1013,7 +1013,7 @@ void RewriteModernObjC::RewritePropertyI
Setr = "\nextern \"C\" __declspec(dllimport) "
"void objc_setProperty (id, SEL, long, id, bool, bool);\n";
}
-
+
RewriteObjCMethodDecl(OID->getContainingInterface(),
PD->getSetterMethodDecl(), Setr);
Setr += "{ ";
@@ -3965,10 +3965,11 @@ void RewriteModernObjC::RewriteIvarOffse
std::string &Result) {
// write out ivar offset symbols which have been referenced in an ivar
// access expression.
- llvm::SmallPtrSet<ObjCIvarDecl *, 8> Ivars = ReferencedIvars[CDecl];
+ llvm::SmallSetVector<ObjCIvarDecl *, 8> Ivars = ReferencedIvars[CDecl];
+
if (Ivars.empty())
return;
-
+
llvm::DenseSet<std::pair<const ObjCInterfaceDecl*, unsigned> > GroupSymbolOutput;
for (ObjCIvarDecl *IvarDecl : Ivars) {
const ObjCInterfaceDecl *IDecl = IvarDecl->getContainingInterface();
Added: cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm?rev=307296&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm (added)
+++ cfe/trunk/test/Rewriter/objc-modern-metadata-visibility2.mm Thu Jul 6 11:49:57 2017
@@ -0,0 +1,45 @@
+// REQUIRES: abi-breaking-checks
+// NOTE: This test has been split from objc-modern-metadata-visibility.mm in
+// order to test with -reverse-iterate as this flag is only present with
+// ABI_BREAKING_CHECKS.
+
+// RUN: %clang_cc1 -E %s -o %t.mm -mllvm -reverse-iterate
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -mllvm -reverse-iterate -o - | FileCheck %s
+// rdar://11144048
+
+ at class NSString;
+
+ at interface NSObject {
+ Class isa;
+}
+ at end
+
+ at interface Sub : NSObject {
+ int subIvar;
+ NSString *nsstring;
+ at private
+ id PrivateIvar;
+}
+ at end
+
+ at implementation Sub
+- (id) MyNSString { return subIvar ? PrivateIvar : nsstring; }
+ at end
+
+ at interface NSString @end
+ at implementation NSString @end
+
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$subIvar;
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long OBJC_IVAR_$_Sub$PrivateIvar;
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$nsstring;
+// CHECK: #pragma warning(disable:4273)
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$subIvar
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$nsstring
+// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long int OBJC_IVAR_$_Sub$PrivateIvar
+// CHECK: extern "C" __declspec(dllimport) struct _class_t OBJC_METACLASS_$_NSObject;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_METACLASS_$_Sub
+// CHECK: extern "C" __declspec(dllimport) struct _class_t OBJC_CLASS_$_NSObject;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_Sub
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_NSString;
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_METACLASS_$_NSString
+// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_NSString
More information about the cfe-commits
mailing list