Author: Timm Baeder Date: 2024-12-03T14:34:32+01:00 New Revision: ff0babc9172b42a3e9f552d6959f9d98ae450633
URL: https://github.com/llvm/llvm-project/commit/ff0babc9172b42a3e9f552d6959f9d98ae450633 DIFF: https://github.com/llvm/llvm-project/commit/ff0babc9172b42a3e9f552d6959f9d98ae450633.diff LOG: [clang][bytecode] Fix discarded pointer subtractions (#118477) We need to pop the value. Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/literals.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index a95353fd2943c9..705ab1ec8e8ab6 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -1000,7 +1000,10 @@ bool Compiler<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) { if (!visitAsPointer(RHS, *RT) || !visitAsPointer(LHS, *LT)) return false; - return this->emitSubPtr(classifyPrim(E->getType()), E); + PrimType IntT = classifyPrim(E->getType()); + if (!this->emitSubPtr(IntT, E)) + return false; + return DiscardResult ? this->emitPop(IntT, E) : true; } PrimType OffsetType; diff --git a/clang/test/AST/ByteCode/literals.cpp b/clang/test/AST/ByteCode/literals.cpp index 13d6c4feb35002..662823c49cd4a0 100644 --- a/clang/test/AST/ByteCode/literals.cpp +++ b/clang/test/AST/ByteCode/literals.cpp @@ -980,6 +980,8 @@ namespace DiscardExprs { __uuidof(number); // both-error {{cannot call operator __uuidof on a type with no GUID}} requires{false;}; + constexpr int *p = nullptr; + p - p; return 0; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits