Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/lib/AST/ByteCode/EvaluationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.isZero() && !P.isDummy() && P.isDereferencable() &&
!P.isUnknownSizeArray() && !P.isOnePastEnd();
return P.isLive() && P.isBlockPointer() && !P.isZero() && !P.isDummy() &&
P.isDereferencable() && !P.isUnknownSizeArray() && !P.isOnePastEnd();
};

if (!isUsefulPtr(Ptr))
Expand Down
17 changes: 11 additions & 6 deletions clang/lib/AST/ByteCode/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,20 @@ class Pointer {
assert(asBlockPointer().Pointee);
assert(isDereferencable());
assert(getFieldDesc()->isPrimitiveArray());
assert(I < getFieldDesc()->getNumElems());

unsigned ElemByteOffset = I * getFieldDesc()->getElemSize();
if (isArrayRoot())
return *reinterpret_cast<T *>(asBlockPointer().Pointee->rawData() +
asBlockPointer().Base + sizeof(InitMapPtr) +
ElemByteOffset);
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);
}

return *reinterpret_cast<T *>(asBlockPointer().Pointee->rawData() + Offset +
ElemByteOffset);
unsigned ReadOffset = BS.Base + ElemByteOffset;
assert(ReadOffset + sizeof(T) <=
BS.Pointee->getDescriptor()->getAllocSize());
return *reinterpret_cast<T *>(BS.Pointee->rawData() + ReadOffset);
}

/// Whether this block can be read from at all. This is only true for
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/ByteCode/invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ 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];
Loading