Refactor sizeof handling to use constant folding logic for constant 
sizeof expressions.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62941 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 49cc320..4c24205 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -916,17 +916,22 @@
   // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
   if (!SrcTy->isConstantSizeType())
     return false;
-
-  // sizeof (objc class) ?
-  if (SrcTy->isObjCInterfaceType())
-    return false;
   
   // GCC extension: sizeof(function) = 1.
   if (SrcTy->isFunctionType()) {
     Result = 1;
     return true;
   }
-  
+
+  if (SrcTy->isObjCInterfaceType()) {
+    // Slightly unusual case: the size of an ObjC interface type is the
+    // size of the class.  This code intentionally falls through to the normal
+    // case.
+    ObjCInterfaceDecl *OI = SrcTy->getAsObjCInterfaceType()->getDecl();
+    RecordDecl *RD = const_cast<RecordDecl*>(Info.Ctx.addRecordToClass(OI));
+    SrcTy = Info.Ctx.getTagDeclType(static_cast<TagDecl*>(RD));
+  }
+
   // Get information about the size.
   unsigned CharSize = Info.Ctx.Target.getCharWidth();
   Result = Info.Ctx.getTypeSize(SrcTy) / CharSize;