aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-01-24 22:19:05 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-01-24 22:19:05 +0000
commitf2da9dfef96dc11b7b5effb1d02cb427b2d71599 (patch)
tree9654cafde71aee7d782208147dc8dc4f04fa1195 /lib/AST/ExprConstant.cpp
parentaf707ab8fbb9451e8febb8d766f6c043628125c4 (diff)
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
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 49cc3201db..4c242059b5 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -916,17 +916,22 @@ bool IntExprEvaluator::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {
// 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;