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
48 changes: 28 additions & 20 deletions clang/lib/AST/ByteCode/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,21 @@ Pointer &Pointer::operator=(const Pointer &P) {
StorageKind = P.StorageKind;
Offset = P.Offset;

if (P.isBlockPointer()) {
switch (StorageKind) {
case Storage::Int:
Int = P.Int;
break;
case Storage::Block:
BS = P.BS;

if (BS.Pointee)
BS.Pointee->addPointer(this);
} else if (P.isIntegralPointer()) {
Int = P.Int;
} else if (P.isFunctionPointer()) {
break;
case Storage::Fn:
Fn = P.Fn;
} else if (P.isTypeidPointer()) {
break;
case Storage::Typeid:
Typeid = P.Typeid;
} else {
assert(false && "Unhandled storage kind");
}
return *this;
}
Expand All @@ -147,19 +149,21 @@ Pointer &Pointer::operator=(Pointer &&P) {
StorageKind = P.StorageKind;
Offset = P.Offset;

if (P.isBlockPointer()) {
switch (StorageKind) {
case Storage::Int:
Int = P.Int;
break;
case Storage::Block:
BS = P.BS;

if (BS.Pointee)
BS.Pointee->addPointer(this);
} else if (P.isIntegralPointer()) {
Int = P.Int;
} else if (P.isFunctionPointer()) {
break;
case Storage::Fn:
Fn = P.Fn;
} else if (P.isTypeidPointer()) {
break;
case Storage::Typeid:
Typeid = P.Typeid;
} else {
assert(false && "Unhandled storage kind");
}
return *this;
}
Expand Down Expand Up @@ -358,13 +362,17 @@ void Pointer::print(llvm::raw_ostream &OS) const {
}

size_t Pointer::computeOffsetForComparison() const {
if (isIntegralPointer())
return asIntPointer().Value + Offset;
if (isTypeidPointer())
switch (StorageKind) {
case Storage::Int:
return Int.Value + Offset;
case Storage::Block:
// See below.
break;
case Storage::Fn:
return Fn.getIntegerRepresentation() + Offset;
case Storage::Typeid:
return reinterpret_cast<uintptr_t>(asTypeidPointer().TypePtr) + Offset;

if (!isBlockPointer())
return Offset;
}

size_t Result = 0;
Pointer P = *this;
Expand Down
14 changes: 8 additions & 6 deletions clang/lib/AST/ByteCode/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct TypeidPointer {
const Type *TypeInfoType;
};

enum class Storage { Block, Int, Fn, Typeid };
enum class Storage { Int, Block, Fn, Typeid };

/// A pointer to a memory block, live or dead.
///
Expand Down Expand Up @@ -252,14 +252,16 @@ class Pointer {

/// Checks if the pointer is null.
bool isZero() const {
if (isBlockPointer())
switch (StorageKind) {
case Storage::Int:
return Int.Value == 0 && Offset == 0;
case Storage::Block:
return BS.Pointee == nullptr;
if (isFunctionPointer())
case Storage::Fn:
return Fn.isZero();
if (isTypeidPointer())
case Storage::Typeid:
return false;
assert(isIntegralPointer());
return Int.Value == 0 && Offset == 0;
}
}
/// Checks if the pointer is live.
bool isLive() const {
Expand Down
Loading