[clang] 9642aad - Revert "[clang][bytecode] Fix incorrect offset in elem() (#155157)"
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 25 06:00:31 PDT 2025
Author: Timm Bäder
Date: 2025-08-25T15:00:02+02:00
New Revision: 9642aadf7064192164d1687378d28d6bda1978c9
URL: https://github.com/llvm/llvm-project/commit/9642aadf7064192164d1687378d28d6bda1978c9
DIFF: https://github.com/llvm/llvm-project/commit/9642aadf7064192164d1687378d28d6bda1978c9.diff
LOG: Revert "[clang][bytecode] Fix incorrect offset in elem() (#155157)"
This reverts commit 0f4db1a7955e511844d7a685103aa32617fc279d.
This breaks the armv8-quick builder:
https://lab.llvm.org/buildbot/#/builders/154/builds/20676
Added:
Modified:
clang/lib/AST/ByteCode/EvaluationResult.cpp
clang/lib/AST/ByteCode/Pointer.h
clang/test/AST/ByteCode/invalid.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index 5110e243d167c..b11531f4296a2 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -178,8 +178,8 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
static void collectBlocks(const Pointer &Ptr,
llvm::SetVector<const Block *> &Blocks) {
auto isUsefulPtr = [](const Pointer &P) -> bool {
- return P.isLive() && P.isBlockPointer() && !P.isZero() && !P.isDummy() &&
- P.isDereferencable() && !P.isUnknownSizeArray() && !P.isOnePastEnd();
+ return P.isLive() && !P.isZero() && !P.isDummy() && P.isDereferencable() &&
+ !P.isUnknownSizeArray() && !P.isOnePastEnd();
};
if (!isUsefulPtr(Ptr))
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index 4ac913f5b74cc..66e85f93a124e 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -694,20 +694,15 @@ class Pointer {
assert(asBlockPointer().Pointee);
assert(isDereferencable());
assert(getFieldDesc()->isPrimitiveArray());
- assert(I < getFieldDesc()->getNumElems());
unsigned ElemByteOffset = I * getFieldDesc()->getElemSize();
- if (isArrayRoot()) {
- unsigned ReadOffset = BS.Base + sizeof(InitMapPtr) + ElemByteOffset;
- assert(ReadOffset + sizeof(T) <=
- BS.Pointee->getDescriptor()->getAllocSize());
- return *reinterpret_cast<T *>(BS.Pointee->rawData() + ReadOffset);
- }
+ if (isArrayRoot())
+ return *reinterpret_cast<T *>(asBlockPointer().Pointee->rawData() +
+ asBlockPointer().Base + sizeof(InitMapPtr) +
+ ElemByteOffset);
- unsigned ReadOffset = BS.Base + ElemByteOffset;
- assert(ReadOffset + sizeof(T) <=
- BS.Pointee->getDescriptor()->getAllocSize());
- return *reinterpret_cast<T *>(BS.Pointee->rawData() + ReadOffset);
+ return *reinterpret_cast<T *>(asBlockPointer().Pointee->rawData() + Offset +
+ ElemByteOffset);
}
/// Whether this block can be read from at all. This is only true for
diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp
index affb40eada870..2a6c2d13e8467 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -58,11 +58,3 @@ namespace Casts {
/// Just make sure this doesn't crash.
float PR9558 = reinterpret_cast<const float&>("asd");
}
-
-
-/// This used to crash in collectBlock().
-struct S {
-};
-S s;
-S *sp[2] = {&s, &s};
-S *&spp = sp[1];
More information about the cfe-commits
mailing list