summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
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
commit4a4fefcd29a980914e3c8d0c68faaf296e0c65aa (patch)
tree9e0aef9388c706640fe462ee5b64e7881226b00e /clang/lib/AST
parent5c273ce20e7df422244e44e94e687c145f0388f5 (diff)
downloadbcm5719-llvm-4a4fefcd29a980914e3c8d0c68faaf296e0c65aa.tar.gz
bcm5719-llvm-4a4fefcd29a980914e3c8d0c68faaf296e0c65aa.zip
PR4326: Handle constant evaluation for void* pointer subtraction
correctly. llvm-svn: 72886
Diffstat (limited to 'clang/lib/AST')
-rw-r--r--clang/lib/AST/ExprConstant.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 50fdcfd6eb2..0b1632f234b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/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);
}
OpenPOWER on IntegriCloud