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
11 changes: 6 additions & 5 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5432,8 +5432,7 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
unsigned EndIndex = 0;
// Find the init list.
for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) {
if (InitStack[StartIndex].Kind == InitLink::K_InitList ||
InitStack[StartIndex].Kind == InitLink::K_This) {
if (InitStack[StartIndex].Kind == InitLink::K_DIE) {
EndIndex = StartIndex;
--StartIndex;
break;
Expand All @@ -5446,7 +5445,8 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
continue;

if (InitStack[StartIndex].Kind != InitLink::K_Field &&
InitStack[StartIndex].Kind != InitLink::K_Elem)
InitStack[StartIndex].Kind != InitLink::K_Elem &&
InitStack[StartIndex].Kind != InitLink::K_DIE)
break;
}

Expand All @@ -5457,7 +5457,8 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {

// Emit the instructions.
for (unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
if (InitStack[I].Kind == InitLink::K_InitList)
if (InitStack[I].Kind == InitLink::K_InitList ||
InitStack[I].Kind == InitLink::K_DIE)
continue;
if (!InitStack[I].template emit<Emitter>(this, E))
return false;
Expand Down Expand Up @@ -6328,8 +6329,8 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {

unsigned FirstLinkOffset =
R->getField(cast<FieldDecl>(IFD->chain()[0]))->Offset;
InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(InitExpr));
InitLinkScope<Emitter> ILS(this, InitLink::Field(FirstLinkOffset));
InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(InitExpr));
if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
IsUnion))
return false;
Expand Down
17 changes: 13 additions & 4 deletions clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ struct InitLink {
K_Decl = 3,
K_Elem = 5,
K_RVO = 6,
K_InitList = 7
K_InitList = 7,
K_DIE = 8,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does DIE stand for here? The rest of the fields are mostly self explanatory. Either a different name or a comment would help. Also DIE is a dwarf think and so we are now overloading the term, which is not good.

};

static InitLink This() { return InitLink{K_This}; }
static InitLink InitList() { return InitLink{K_InitList}; }
static InitLink RVO() { return InitLink{K_RVO}; }
static InitLink DIE() { return InitLink{K_DIE}; }
static InitLink Field(unsigned Offset) {
InitLink IL{K_Field};
IL.Offset = Offset;
Expand Down Expand Up @@ -668,22 +670,29 @@ template <class Emitter> class InitLinkScope final {

~InitLinkScope() { this->Ctx->InitStack.pop_back(); }

private:
public:
Compiler<Emitter> *Ctx;
};

template <class Emitter> class InitStackScope final {
public:
InitStackScope(Compiler<Emitter> *Ctx, bool Active)
: Ctx(Ctx), OldValue(Ctx->InitStackActive) {
: Ctx(Ctx), OldValue(Ctx->InitStackActive), Active(Active) {
Ctx->InitStackActive = Active;
if (Active)
Ctx->InitStack.push_back(InitLink::DIE());
}

~InitStackScope() { this->Ctx->InitStackActive = OldValue; }
~InitStackScope() {
this->Ctx->InitStackActive = OldValue;
if (Active)
Ctx->InitStack.pop_back();
}

private:
Compiler<Emitter> *Ctx;
bool OldValue;
bool Active;
};

} // namespace interp
Expand Down
21 changes: 21 additions & 0 deletions clang/test/AST/ByteCode/cxx14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,24 @@ constexpr int(*null_ptr)() = nullptr;
constexpr int test4 = (*null_ptr)(); // both-error {{must be initialized by a constant expression}} \
// both-note {{evaluates to a null function pointer}}

struct E {
int n = 0;
struct {
void *x = this;
};
void *y = this;
};
constexpr E e1 = E();
static_assert(e1.x != e1.y, "");
constexpr E e2 = E{0};
static_assert(e2.x != e2.y, "");

struct S {
int &&a = 2;
int b[1]{a};
};
constexpr int foo() {
S s{12};
return s.b[0];
}
static_assert(foo() == 12, "");
Loading