aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2008-12-22 23:22:27 +0000
committerFariborz Jahanian <fjahanian@apple.com>2008-12-22 23:22:27 +0000
commit5b8c7d9fb620ba3a71e996d61e7b9bdf763b5c09 (patch)
treece2567b962105aedc612e6d57c855e1327a1a5df
parent1a9376408941d65c285ddad8a0f1a2ac518df344 (diff)
More encoding support; in this case, encoding of
outer-most const of pointer types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61355 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/ASTContext.h3
-rw-r--r--lib/AST/ASTContext.cpp11
-rw-r--r--test/CodeGenObjC/encode-test.m6
3 files changed, 16 insertions, 4 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 35b48e96f7..4ac1c5d764 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -546,7 +546,8 @@ private:
void getObjCEncodingForTypeImpl(QualType t, std::string &S,
bool ExpandPointedToStructures,
bool ExpandStructures,
- FieldDecl *Field) const;
+ FieldDecl *Field,
+ bool OutermostType = false) const;
};
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index f81d41aa61..ad6c0dfc6c 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1755,13 +1755,15 @@ void ASTContext::getObjCEncodingForType(QualType T, std::string& S,
// directly pointed to, and expanding embedded structures. Note that
// these rules are sufficient to prevent recursive encoding of the
// same type.
- getObjCEncodingForTypeImpl(T, S, true, true, Field);
+ getObjCEncodingForTypeImpl(T, S, true, true, Field,
+ true /* outermost type */);
}
void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
bool ExpandPointedToStructures,
bool ExpandStructures,
- FieldDecl *FD) const {
+ FieldDecl *FD,
+ bool OutermostType) const {
if (const BuiltinType *BT = T->getAsBuiltinType()) {
if (FD && FD->isBitField()) {
const Expr *E = FD->getBitWidth();
@@ -1805,6 +1807,8 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
}
else if (const PointerType *PT = T->getAsPointerType()) {
QualType PointeeTy = PT->getPointeeType();
+ if (OutermostType && PointeeTy.isConstQualified())
+ S += 'r';
if (isObjCIdType(PointeeTy)) {
S += '@';
return;
@@ -1879,6 +1883,9 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
getObjCEncodingForTypeImpl(Field->getType(), S, false, true,
(*Field));
} else {
+ // FIXME! Another legacy kludge: 32-bit longs are encoded as
+ // 'l' or 'L', but not always. For typedefs, we need to use
+ // 'i' or 'I' instead if encoding a struct field, or a pointer!
getObjCEncodingForTypeImpl(Field->getType(), S, false, true,
FD);
}
diff --git a/test/CodeGenObjC/encode-test.m b/test/CodeGenObjC/encode-test.m
index 8e894c4220..0ae4f13c50 100644
--- a/test/CodeGenObjC/encode-test.m
+++ b/test/CodeGenObjC/encode-test.m
@@ -2,7 +2,8 @@
// RUN: grep -e "\^{Innermost=CC}" %t | count 1 &&
// RUN: grep -e "{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}" %t | count 1 &&
// RUN: grep -e "{B1=#@c}" %t | count 1 &&
-// RUN: grep -e "v12@0:4\[3\[4{Test=i}]]8" %t | count 1
+// RUN: grep -e "v12@0:4\[3\[4{Test=i}]]8" %t | count 1 &&
+// RUN: grep -e "r^{S=i}" %t | count 1
@class Int1;
@@ -72,10 +73,13 @@ struct Innermost {
-(void) test3: (Test [3] [4])b {}
@end
+struct S { int iS; };
int main()
{
const char *en = @encode(Derived);
const char *eb = @encode(B1);
+ const char *es = @encode(const struct S *);
+ const char *ec = @encode(const struct S);
}