Skip to content

Commit ff0babc

Browse files
authored
[clang][bytecode] Fix discarded pointer subtractions (#118477)
We need to pop the value.
1 parent 51a895a commit ff0babc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,10 @@ bool Compiler<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) {
10001000
if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *LT))
10011001
return false;
10021002

1003-
return this->emitSubPtr(classifyPrim(E->getType()), E);
1003+
PrimType IntT = classifyPrim(E->getType());
1004+
if (!this->emitSubPtr(IntT, E))
1005+
return false;
1006+
return DiscardResult ? this->emitPop(IntT, E) : true;
10041007
}
10051008

10061009
PrimType OffsetType;

clang/test/AST/ByteCode/literals.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,8 @@ namespace DiscardExprs {
980980
__uuidof(number); // both-error {{cannot call operator __uuidof on a type with no GUID}}
981981

982982
requires{false;};
983+
constexpr int *p = nullptr;
984+
p - p;
983985

984986
return 0;
985987
}

0 commit comments

Comments
 (0)