Skip to content

Commit 9642aad

Browse files
committed
Revert "[clang][bytecode] Fix incorrect offset in elem() (llvm#155157)"
This reverts commit 0f4db1a. This breaks the armv8-quick builder: https://lab.llvm.org/buildbot/#/builders/154/builds/20676
1 parent 3db6011 commit 9642aad

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

clang/lib/AST/ByteCode/EvaluationResult.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
178178
static void collectBlocks(const Pointer &Ptr,
179179
llvm::SetVector<const Block *> &Blocks) {
180180
auto isUsefulPtr = [](const Pointer &P) -> bool {
181-
return P.isLive() && P.isBlockPointer() && !P.isZero() && !P.isDummy() &&
182-
P.isDereferencable() && !P.isUnknownSizeArray() && !P.isOnePastEnd();
181+
return P.isLive() && !P.isZero() && !P.isDummy() && P.isDereferencable() &&
182+
!P.isUnknownSizeArray() && !P.isOnePastEnd();
183183
};
184184

185185
if (!isUsefulPtr(Ptr))

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -694,20 +694,15 @@ class Pointer {
694694
assert(asBlockPointer().Pointee);
695695
assert(isDereferencable());
696696
assert(getFieldDesc()->isPrimitiveArray());
697-
assert(I < getFieldDesc()->getNumElems());
698697

699698
unsigned ElemByteOffset = I * getFieldDesc()->getElemSize();
700-
if (isArrayRoot()) {
701-
unsigned ReadOffset = BS.Base + sizeof(InitMapPtr) + ElemByteOffset;
702-
assert(ReadOffset + sizeof(T) <=
703-
BS.Pointee->getDescriptor()->getAllocSize());
704-
return *reinterpret_cast<T *>(BS.Pointee->rawData() + ReadOffset);
705-
}
699+
if (isArrayRoot())
700+
return *reinterpret_cast<T *>(asBlockPointer().Pointee->rawData() +
701+
asBlockPointer().Base + sizeof(InitMapPtr) +
702+
ElemByteOffset);
706703

707-
unsigned ReadOffset = BS.Base + ElemByteOffset;
708-
assert(ReadOffset + sizeof(T) <=
709-
BS.Pointee->getDescriptor()->getAllocSize());
710-
return *reinterpret_cast<T *>(BS.Pointee->rawData() + ReadOffset);
704+
return *reinterpret_cast<T *>(asBlockPointer().Pointee->rawData() + Offset +
705+
ElemByteOffset);
711706
}
712707

713708
/// Whether this block can be read from at all. This is only true for

clang/test/AST/ByteCode/invalid.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,3 @@ namespace Casts {
5858
/// Just make sure this doesn't crash.
5959
float PR9558 = reinterpret_cast<const float&>("asd");
6060
}
61-
62-
63-
/// This used to crash in collectBlock().
64-
struct S {
65-
};
66-
S s;
67-
S *sp[2] = {&s, &s};
68-
S *&spp = sp[1];

0 commit comments

Comments
 (0)