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
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 50fdcfd..0b1632f 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -946,7 +946,12 @@
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);
}