]> granicus.if.org Git - clang/commitdiff
Handle the GNU void* and function pointer arithmetic extensions for constant expressi...
authorAnders Carlsson <andersca@mac.com>
Thu, 19 Feb 2009 04:55:58 +0000 (04:55 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 19 Feb 2009 04:55:58 +0000 (04:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65013 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/Sema/const-eval.c

index d573236783eaf1155fda5ef08291f8c5fef30668..da251fcea9aa0920f5f75b97a5c19df7501c95fe 100644 (file)
@@ -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();
 
index 7307aea791f4ce398d20b852cb6a54acff5b4bc6..a56504151cb0e2de6a17f28c9f9297e2feb2ceeb 100644 (file)
@@ -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));