forked from OSchip/llvm-project
PR4326: Handle constant evaluation for void* pointer subtraction
correctly. llvm-svn: 72886
This commit is contained in:
parent
5c273ce20e
commit
4a4fefcd29
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue