[clang] [clang][bytecode][NFC] Code size is always aligned (PR #151824)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 4 12:46:23 PDT 2025
================
@@ -137,21 +137,21 @@ int32_t ByteCodeEmitter::getOffset(LabelTy Label) {
template <typename T>
static void emit(Program &P, std::vector<std::byte> &Code, const T &Val,
bool &Success) {
+ size_t ValPos = Code.size();
size_t Size;
if constexpr (std::is_pointer_v<T>)
- Size = sizeof(uint32_t);
+ Size = align(sizeof(uint32_t));
else
- Size = sizeof(T);
+ Size = align(sizeof(T));
- if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
+ if (ValPos + Size > std::numeric_limits<unsigned>::max()) {
----------------
shafik wrote:
`Code.size() + Size` could overflow. If we have assertions on `Code.size()` and `Size` then we can say hey we know that are always smaller than or equal unsigned max and so overflow is not possible.
The code just looks suspicious because it looks like a classic (wrong) overflow check and so that got me asking questions.
https://github.com/llvm/llvm-project/pull/151824
More information about the cfe-commits
mailing list