summaryrefslogtreecommitdiffstats
path: root/clang/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
commit2aa38fea3545e31642c048ebac0f7362b4831946 (patch)
treee50f0e7dd068e747743efbe3818d1127f6e484ce /clang/lib/AST/ExprConstant.cpp
parentb09b0242ca34a184f6caa2699d7c938ad3c3832e (diff)
downloadbcm5719-llvm-2aa38fea3545e31642c048ebac0f7362b4831946.tar.gz
bcm5719-llvm-2aa38fea3545e31642c048ebac0f7362b4831946.zip
Refactor sizeof handling to use constant folding logic for constant
sizeof expressions. llvm-svn: 62941
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 49cc3201db9..4c242059b52 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/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;
OpenPOWER on IntegriCloud