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: 3 additions & 1 deletion clang/lib/AST/ByteCode/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
Kind = FunctionKind::Dtor;
} else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
Virtual = MD->isVirtual();
if (IsLambdaStaticInvoker) // MD->isLambdaStaticInvoker())
if (IsLambdaStaticInvoker)
Kind = FunctionKind::LambdaStaticInvoker;
else if (clang::isLambdaCallOperator(F))
Kind = FunctionKind::LambdaCallOperator;
else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
Kind = FunctionKind::CopyOrMoveOperator;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/AST/ByteCode/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Function final {
Dtor,
LambdaStaticInvoker,
LambdaCallOperator,
CopyOrMoveOperator,
};
using ParamDescriptor = std::pair<PrimType, Descriptor *>;

Expand Down Expand Up @@ -159,6 +160,10 @@ class Function final {
bool isConstructor() const { return Kind == FunctionKind::Ctor; }
/// Checks if the function is a destructor.
bool isDestructor() const { return Kind == FunctionKind::Dtor; }
/// Checks if the function is copy or move operator.
bool isCopyOrMoveOperator() const {
return Kind == FunctionKind::CopyOrMoveOperator;
}

/// Returns whether this function is a lambda static invoker,
/// which we generate custom byte code for.
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
if (!CheckInvoke(S, OpPC, ThisPtr))
return cleanup();
if (!Func->isConstructor() && !Func->isDestructor() &&
!Func->isCopyOrMoveOperator() &&
!CheckActive(S, OpPC, ThisPtr, AK_MemberCall))
return false;
}
Expand Down
29 changes: 29 additions & 0 deletions clang/test/AST/ByteCode/unions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,33 @@ namespace ActiveDestroy {
static_assert(foo2());
}

namespace MoveOrAssignOp {
struct min_pointer {
int *ptr_;
constexpr min_pointer(int *p) : ptr_(p) {}
min_pointer() = default;
};

class F {
struct __long {
min_pointer __data_;
};
union __rep {
int __s;
__long __l;
} __rep_;

public:
constexpr F() {
__rep_ = __rep();
__rep_.__l.__data_ = nullptr;
}
};

constexpr bool foo() {
F f{};
return true;
}
static_assert(foo());
}
#endif