From: Anders Carlsson Date: Thu, 19 Feb 2009 04:55:58 +0000 (+0000) Subject: Handle the GNU void* and function pointer arithmetic extensions for constant expressi... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d4c50dd8b4db191c38782414665fb7608315a36;p=clang Handle the GNU void* and function pointer arithmetic extensions for constant expressions as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65013 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index d573236783..da251fcea9 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -292,7 +292,13 @@ APValue PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { return APValue(); QualType PointeeType = PExp->getType()->getAsPointerType()->getPointeeType(); - uint64_t SizeOfPointee = Info.Ctx.getTypeSize(PointeeType) / 8; + uint64_t SizeOfPointee; + + // Explicitly handle GNU void* and function pointer arithmetic extensions. + if (PointeeType->isVoidType() || PointeeType->isFunctionType()) + SizeOfPointee = 1; + else + SizeOfPointee = Info.Ctx.getTypeSize(PointeeType) / 8; uint64_t Offset = ResultLValue.getLValueOffset(); diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index 7307aea791..a56504151c 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -32,3 +32,5 @@ _Complex float g16 = (1.0f + 1.0fi); // ?: in constant expressions. int g17[(3?:1) - 2]; + +EVAL_EXPR(18, (int)((void*)10 + 10));