[cfe-commits] r156004 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/rewrite-modern-struct-ivar-1.mm
Fariborz Jahanian
fjahanian at apple.com
Wed May 2 10:34:59 PDT 2012
Author: fjahanian
Date: Wed May 2 12:34:59 2012
New Revision: 156004
URL: http://llvm.org/viewvc/llvm-project?rev=156004&view=rev
Log:
Modern objective-c translation: Fixing couple of bugs
related to laying out ivar structs and accessing non-fragile-ivar
in more compilated cases. // rdar://11323187
Added:
cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar-1.mm
Modified:
cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=156004&r1=156003&r2=156004&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Wed May 2 12:34:59 2012
@@ -3523,6 +3523,11 @@
/// It handles elaborated types, as well as enum types in the process.
bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type,
std::string &Result) {
+ if (isa<TypedefType>(Type)) {
+ Result += "\t";
+ return false;
+ }
+
if (Type->isArrayType()) {
QualType ElemTy = Context->getBaseElementType(Type);
return RewriteObjCFieldDeclType(ElemTy, Result);
@@ -3618,6 +3623,8 @@
void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl,
std::string &Result) {
QualType Type = fieldDecl->getType();
+ if (isa<TypedefType>(Type))
+ return;
if (Type->isArrayType())
Type = Context->getBaseElementType(Type);
ObjCContainerDecl *IDecl =
@@ -7308,12 +7315,17 @@
addExpr);
QualType IvarT = D->getType();
- if (IvarT->isRecordType()) {
+ if (!isa<TypedefType>(IvarT) && IvarT->isRecordType()) {
RecordDecl *RD = IvarT->getAs<RecordType>()->getDecl();
RD = RD->getDefinition();
if (RD && !RD->getDeclName().getAsIdentifierInfo()) {
// decltype(((Foo_IMPL*)0)->bar) *
- std::string RecName = iFaceDecl->getDecl()->getName();
+ ObjCContainerDecl *CDecl =
+ dyn_cast<ObjCContainerDecl>(D->getDeclContext());
+ // ivar in class extensions requires special treatment.
+ if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
+ CDecl = CatDecl->getClassInterface();
+ std::string RecName = CDecl->getName();
RecName += "_IMPL";
RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
SourceLocation(), SourceLocation(),
Added: cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar-1.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar-1.mm?rev=156004&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar-1.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar-1.mm Wed May 2 12:34:59 2012
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fblocks -rewrite-objc -fms-extensions %s -o %t-rw.cpp
+// RUN: %clang_cc1 -Werror -fsyntax-only -Wno-address-of-temporary -Wno-c++11-narrowing -std=c++11 -D"Class=void*" -D"id=void*" -D"SEL=void*" -U__declspec -D"__declspec(X)=" %t-rw.cpp
+// rdar://11323187
+
+typedef unsigned long NSUInteger;
+
+typedef struct _NSRange {
+ NSUInteger location;
+ NSUInteger length;
+} NSRange;
+
+typedef struct {
+ NSUInteger _capacity;
+ NSRange _ranges[0];
+} _NSRangeInfo;
+
+ at interface Foo{
+ @protected
+ struct _bar {
+ int x:1;
+ int y:1;
+ } bar;
+ union {
+ struct {
+ NSRange _range;
+ } _singleRange;
+ struct {
+ void * _data;
+ void *_reserved;
+ } _multipleRanges;
+ } _internal;
+}
+ at end
+ at implementation Foo
+- (void)x:(Foo *)other {
+ bar.x = 0;
+ bar.y = 1;
+ self->_internal._singleRange._range = (( other ->bar.x) ? &( other ->_internal._singleRange._range) : ((NSRange *)(&(((_NSRangeInfo *)( other ->_internal._multipleRanges._data))->_ranges))))[0];
+}
+ at end
+ at interface FooS : Foo
+ at end
+ at implementation FooS
+- (void)y {
+
+ NSUInteger asdf = (( self ->bar.x) ? 1 : ((_NSRangeInfo *)( self ->_internal._multipleRanges._data))->_capacity );
+}
+ at end
More information about the cfe-commits
mailing list