24 #include "llvm/ADT/APSInt.h" 26 using namespace clang;
33 template <PrimType Name, class T = typename PrimConv<Name>::T>
50 if (!ReturnValue<T>(Ret, Result))
75 llvm::report_fatal_error(
"Interpreter cannot return values");
107 S.
FFDiag(Loc, diag::note_constexpr_access_uninit) << AK <<
false;
128 assert(R && R->
isUnion() &&
"Not a union");
130 for (
unsigned I = 0, N = R->
getNumFields(); I < N; ++I) {
139 S.
FFDiag(Loc, diag::note_constexpr_access_inactive_union_member)
140 << AK << InactiveField << !ActiveField << ActiveField;
157 S.
FFDiag(E, diag::note_constexpr_access_static_temporary, 1) << AK;
188 S.
FFDiag(Loc, diag::note_constexpr_ltor_non_constexpr, 1) << VD;
189 S.
Note(VD->getLocation(), diag::note_declared_at);
198 S.
FFDiag(E, diag::note_constexpr_unsized_array_indexed);
210 S.
FFDiag(Src, diag::note_constexpr_access_null) << AK;
218 S.
FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp;
236 S.
FFDiag(Loc, diag::note_constexpr_null_subobject) << CSK;
245 S.
FFDiag(Loc, diag::note_constexpr_access_past_end) << AK;
254 S.
FFDiag(Loc, diag::note_constexpr_past_end_subobject) << CSK;
259 assert(Ptr.
isLive() &&
"Pointer is not live");
266 S.
FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
271 assert(Ptr.
isLive() &&
"Pointer is not live");
278 S.
FFDiag(Loc, diag::note_constexpr_access_mutable, 1) <<
AK_Read << Field;
279 S.
Note(Field->getLocation(), diag::note_declared_at);
338 S.
CCEDiag(Loc, diag::note_constexpr_virtual_call);
350 if (CD && CD->isInheritingConstructor()) {
352 if (!Inherited->isConstexpr())
353 DiagDecl = CD = Inherited;
359 if (CD && CD->isInheritingConstructor())
360 S.
FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
361 << CD->getInheritedConstructor().getConstructor()->getParent();
363 S.
FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
367 S.
FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
381 bool IsImplicit =
false;
382 if (
auto *E = dyn_cast_or_null<CXXThisExpr>(Loc.
asExpr()))
383 IsImplicit = E->isImplicit();
386 S.
FFDiag(Loc, diag::note_constexpr_this) << IsImplicit;
397 S.
FFDiag(E, diag::note_constexpr_pure_virtual_call, 1) << MD;
410 #include "Opcodes.inc"
Defines the clang::ASTContext interface.
bool CheckInvoke(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a method can be invoked on an object.
Represents a function declaration or definition.
A (possibly-)qualified type.
bool isMutable() const
Checks if the field is mutable.
InterpFrame * Current
The current frame.
bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr, CheckSubobjectKind CSK)
Checks if a pointer is null.
Pointer into the code segment.
SourceLocation getLocation(CodePtr PC) const
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD)
Checks if a method is pure virtual.
void push(Tys &&... Args)
Constructs a value in place on the top of the stack.
Frame storing local variables.
bool isElementPastEnd() const
Checks if the pointer is an out-of-bounds element pointer.
llvm::Optional< unsigned > getCurrentDecl() const
Returns the current declaration ID.
const FunctionDecl * getDecl() const
Returns the original FunctionDecl.
Represents a C++ constructor within a class.
bool This(InterpState &S, CodePtr OpPC)
Describes the statement/declaration an opcode was generated from.
Defines the clang::Expr interface and subclasses for C++ expressions.
A pointer to a memory block, live or dead.
InterpFrame * Caller
The frame of the previous function.
bool Interpret(InterpState &S, APValue &Result)
Interpreter entry point.
Represents a member of a struct/union/class.
T pop()
Returns the value from the top of the stack and removes it.
InterpStack & Stk
Temporary stack.
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
AccessKinds
Kinds of access we can perform on an object, for diagnostics.
static bool Jt(InterpState &S, CodePtr &PC, int32_t Offset)
Structure/Class descriptor.
bool isStatic() const
Checks if the storage is static.
static bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
const ValueDecl * asValueDecl() const
bool isActive() const
Checks if the object is active.
QualType getType() const
Returns the type of the innermost field.
T read()
Reads data and advances the pointer.
bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the variable has externally defined storage.
void popArgs()
Pops the arguments off the stack.
bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is live and accesible.
llvm::Optional< unsigned > getDeclID() const
Returns the declaration ID.
bool isUnion() const
Checks if the record is a union.
bool isField() const
Checks if the item is a field in an object.
bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if the array is offsetable.
static bool Jmp(InterpState &S, CodePtr &PC, int32_t Offset)
virtual SourceInfo getSource(CodePtr PC) const
Map a location to a source.
OptionalDiagnostic FFDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
static bool RetVoid(InterpState &S, CodePtr &PC, APValue &Result)
size_t getFrameOffset() const
Returns the offset on the stack at which the frame starts.
bool isStaticTemporary() const
Checks if the storage is a static temporary.
static bool CheckTemporary(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
bool isConstQualified() const
Determine whether this type is const-qualified.
Encodes a location in the source.
bool isPure() const
Whether this virtual function is pure, i.e.
bool isExtern() const
Checks if the storage is extern.
static bool Jf(InterpState &S, CodePtr &PC, int32_t Offset)
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Represents a static or instance method of a struct/union/class.
static bool CheckGlobal(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be stored in a block.
bool isVirtual() const
Checks if the function is virtual.
OptionalDiagnostic Note(SourceLocation Loc, diag::kind DiagId)
Add a note to a prior diagnostic.
bool isTemporary() const
Checks if the storage is temporary.
static bool RetValue(InterpState &S, CodePtr &Pt, APValue &Result)
unsigned CallStackDepth
Call stack depth.
bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a pointer points to const storage.
CXXConstructorDecl * getConstructor() const
bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a pointer points to a mutable field.
SourceLocation getDeclLoc() const
Dataflow Directional Tag Classes.
CodePtr getPC() const
Returns the PC of the frame's code start.
bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
Checks if a pointer is in range.
bool CheckCallable(InterpState &S, CodePtr OpPC, Function *F)
Checks if a method can be called.
bool isLive() const
Checks if the pointer is live.
bool isInitialized() const
Checks if an object was initialized.
bool isUnknownSizeArray() const
Checks if the structure is an array of unknown size.
bool isOnePastEnd() const
Checks if the index is one past end.
Record * getRecord() const
Returns the record descriptor of a class.
size_t size() const
Returns the size of the stack in bytes.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
Program & P
Reference to the module containing all bytecode.
const FieldDecl * getField() const
Returns the field information.
const LangOptions & getLangOpts() const
bool isZero() const
Checks if the pointer is null.
Descriptor * getDeclDesc() const
Accessor for information about the declaration site.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
OptionalDiagnostic CCEDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation does not produce a C++11 core constant expression.
bool isConstexpr() const
Checks if the function is valid to call in constexpr.
bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This)
Checks the 'this' pointer.
bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be loaded from a block.
bool isConst() const
Checks if an object or a subfield is mutable.
bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr)
Checks if a value can be initialized.
static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, AccessKinds AK)
bool checkingPotentialConstantExpression() const override
const Expr * asExpr() const
const Field * getField(const FieldDecl *FD) const
Returns a field.
CodePtr getRetPC() const
Returns the return address of the frame.
SourceLocation getLocation() const
Pointer getBase() const
Returns a pointer to the object of which this pointer is a field.