r362034 - [ObjC] Fix encoding of ObjC pointer types that are pointers to typedefs
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Wed May 29 14:23:31 PDT 2019
Author: ahatanak
Date: Wed May 29 14:23:30 2019
New Revision: 362034
URL: http://llvm.org/viewvc/llvm-project?rev=362034&view=rev
Log:
[ObjC] Fix encoding of ObjC pointer types that are pointers to typedefs
clang was encoding pointers to typedefs as if they were pointers to
structs because that is apparently what gcc is doing.
For example:
```
@class Class1;
typedef NSArray<Class1 *> MyArray;
void foo1(void) {
const char *s0 = @encode(MyArray *); // "^{NSArray=#}"
const char *s1 = @encode(NSArray<Class1 *> *); // "@"
}
```
This commit removes the code that was there to make clang compatible
with gcc and make clang emit the correct encoding for ObjC pointers,
which is "@".
rdar://problem/50563529
Differential Revision: https://reviews.llvm.org/D61974
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/CodeGenObjC/encode-test-6.m
cfe/trunk/test/CodeGenObjC/encode-test.m
cfe/trunk/test/CodeGenObjCXX/encode.mm
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=362034&r1=362033&r2=362034&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed May 29 14:23:30 2019
@@ -2897,7 +2897,6 @@ private:
V(IsStructField, 4) \
V(EncodeBlockParameters, 5) \
V(EncodeClassNames, 6) \
- V(EncodePointerToObjCTypedef, 7)
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
OPT_LIST(V)
@@ -2916,8 +2915,7 @@ OPT_LIST(V)
LLVM_NODISCARD ObjCEncOptions forComponentType() const {
ObjCEncOptions Mask = ObjCEncOptions()
.setIsOutermostType()
- .setIsStructField()
- .setEncodePointerToObjCTypedef();
+ .setIsStructField();
return Bits & ~Mask.Bits;
}
};
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=362034&r1=362033&r2=362034&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed May 29 14:23:30 2019
@@ -6927,13 +6927,10 @@ void ASTContext::getObjCEncodingForTypeI
getObjCEncodingForTypeImpl(Field->getType(), S,
ObjCEncOptions().setExpandStructures(),
Field);
- else {
- ObjCEncOptions NewOptions = ObjCEncOptions().setExpandStructures();
- if (Options.EncodePointerToObjCTypedef())
- NewOptions.setEncodePointerToObjCTypedef();
- getObjCEncodingForTypeImpl(Field->getType(), S, NewOptions, FD,
+ else
+ getObjCEncodingForTypeImpl(Field->getType(), S,
+ ObjCEncOptions().setExpandStructures(), FD,
NotEncodedT);
- }
}
}
S += '}';
@@ -6976,36 +6973,6 @@ void ASTContext::getObjCEncodingForTypeI
return;
}
- QualType PointeeTy = OPT->getPointeeType();
- if (!Options.EncodingProperty() &&
- isa<TypedefType>(PointeeTy.getTypePtr()) &&
- !Options.EncodePointerToObjCTypedef()) {
- // Another historical/compatibility reason.
- // We encode the underlying type which comes out as
- // {...};
- S += '^';
- if (FD && OPT->getInterfaceDecl()) {
- // Prevent recursive encoding of fields in some rare cases.
- ObjCInterfaceDecl *OI = OPT->getInterfaceDecl();
- SmallVector<const ObjCIvarDecl*, 32> Ivars;
- DeepCollectObjCIvars(OI, true, Ivars);
- for (unsigned i = 0, e = Ivars.size(); i != e; ++i) {
- if (Ivars[i] == FD) {
- S += '{';
- S += OI->getObjCRuntimeNameAsString();
- S += '}';
- return;
- }
- }
- }
- ObjCEncOptions NewOptions =
- ObjCEncOptions().setEncodePointerToObjCTypedef();
- if (Options.ExpandPointedToStructures())
- NewOptions.setExpandStructures();
- getObjCEncodingForTypeImpl(PointeeTy, S, NewOptions, /*Field=*/nullptr);
- return;
- }
-
S += '@';
if (OPT->getInterfaceDecl() &&
(FD || Options.EncodingProperty() || Options.EncodeClassNames())) {
Modified: cfe/trunk/test/CodeGenObjC/encode-test-6.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test-6.m?rev=362034&r1=362033&r2=362034&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/encode-test-6.m (original)
+++ cfe/trunk/test/CodeGenObjC/encode-test-6.m Wed May 29 14:23:30 2019
@@ -34,7 +34,7 @@ typedef BABugExample BABugExampleRedefin
@synthesize property = _property;
@end
-// CHECK: private unnamed_addr constant [24 x i8] c"^{BABugExample=@}16
+// CHECK: private unnamed_addr constant [8 x i8] c"@16
// rdar://14408244
@class SCNCamera;
@@ -52,7 +52,7 @@ typedef struct
C3DCameraStorage _storage;
}
@end
-// CHECK: private unnamed_addr constant [39 x i8] c"{?=\22presentationInstance\22^{SCNCamera}}\00"
+// CHECK: private unnamed_addr constant [39 x i8] c"{?=\22presentationInstance\22@\22SCNCamera\22}\00"
// rdar://16655340
int i;
Modified: cfe/trunk/test/CodeGenObjC/encode-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test.m?rev=362034&r1=362033&r2=362034&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/encode-test.m (original)
+++ cfe/trunk/test/CodeGenObjC/encode-test.m Wed May 29 14:23:30 2019
@@ -107,7 +107,7 @@ const char g3[] = @encode(const struct S
// CHECK: @g4 = constant [6 x i8] c"{S=i}\00"
const char g4[] = @encode(const struct S);
-// CHECK: @g5 = constant [12 x i8] c"^{Object=#}\00"
+// CHECK: @g5 = constant [2 x i8] c"@\00"
const char g5[] = @encode(MyObj * const);
////
Modified: cfe/trunk/test/CodeGenObjCXX/encode.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/encode.mm?rev=362034&r1=362033&r2=362034&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/encode.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/encode.mm Wed May 29 14:23:30 2019
@@ -242,6 +242,6 @@ struct S {
@end
const char *expand_struct() {
- // CHECK: @{{.*}} = private unnamed_addr constant [16 x i8] c"{N={S<N>=^{N}}}\00"
+ // CHECK: @{{.*}} = private unnamed_addr constant [13 x i8] c"{N={S<N>=@}}\00"
return @encode(N);
}
More information about the cfe-commits
mailing list