aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-06-04 20:04:03 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-06-04 20:04:03 +0000
commit147bd641dd264fde2fc5a0074f30eace71016ea9 (patch)
tree9a45328ef23563fc4657067821ba287032388f31
parent0b308ad34ffb29e508b681b155696f8f999532bb (diff)
PR4326: Handle constant evaluation for void* pointer subtraction
correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72886 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ExprConstant.cpp7
-rw-r--r--test/Sema/const-eval.c1
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 50fdcfd6eb..0b1632f234 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -946,7 +946,12 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
const QualType ElementType = Type->getAsPointerType()->getPointeeType();
uint64_t D = LHSValue.getLValueOffset() - RHSValue.getLValueOffset();
- D /= Info.Ctx.getTypeSize(ElementType) / 8;
+ uint64_t ElemSize;
+ if (ElementType->isVoidType() || ElementType->isFunctionType())
+ ElemSize = 8;
+ else
+ ElemSize = Info.Ctx.getTypeSize(ElementType);
+ D /= ElemSize / 8;
return Success(D, E);
}
diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c
index 79f96b9c39..971986b2d3 100644
--- a/test/Sema/const-eval.c
+++ b/test/Sema/const-eval.c
@@ -65,3 +65,4 @@ static const struct a V1 = (struct a){ 1, 2};
EVAL_EXPR(30, (int)(_Complex float)((1<<30)-1) == (1<<30) ? 1 : -1)
EVAL_EXPR(31, (int*)0 == (int*)0 ? 1 : -1)
EVAL_EXPR(32, (int*)0 != (int*)0 ? -1 : 1)
+EVAL_EXPR(33, (void*)0 - (void*)0 == 0 ? 1 : -1)