[cfe-commits] r61355 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp test/CodeGenObjC/encode-test.m

Fariborz Jahanian fjahanian at apple.com
Mon Dec 22 15:22:29 PST 2008


Author: fjahanian
Date: Mon Dec 22 17:22:27 2008
New Revision: 61355

URL: http://llvm.org/viewvc/llvm-project?rev=61355&view=rev
Log:
More encoding support; in this case, encoding of
outer-most const of pointer types.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/CodeGenObjC/encode-test.m

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=61355&r1=61354&r2=61355&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Dec 22 17:22:27 2008
@@ -546,7 +546,8 @@
   void getObjCEncodingForTypeImpl(QualType t, std::string &S, 
                                   bool ExpandPointedToStructures,
                                   bool ExpandStructures,
-                                  FieldDecl *Field) const;
+                                  FieldDecl *Field,
+                                  bool OutermostType = false) const;
   
 };
   

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=61355&r1=61354&r2=61355&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Dec 22 17:22:27 2008
@@ -1755,13 +1755,15 @@
   // 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 @@
   }
   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 @@
           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);
         }

Modified: cfe/trunk/test/CodeGenObjC/encode-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test.m?rev=61355&r1=61354&r2=61355&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/encode-test.m (original)
+++ cfe/trunk/test/CodeGenObjC/encode-test.m Mon Dec 22 17:22:27 2008
@@ -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 at 0:4\[3\[4{Test=i}]]8" %t | count 1
+// RUN: grep -e "v12 at 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 @@
 -(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);
 }
 





More information about the cfe-commits mailing list