[clang] [clang][bytecode] Fix discarded pointer subtractions (PR #118477)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 04:02:26 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We need to pop the value.
---
Full diff: https://github.com/llvm/llvm-project/pull/118477.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4-1)
- (modified) clang/test/AST/ByteCode/literals.cpp (+2)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/118477
More information about the cfe-commits
mailing list