This previously ran into an "unknown type" assertion when trying to emit
a 'Zero' op for a pointer type. Emit a NullPtr op instead.
Differential Revision: https://reviews.llvm.org/D137235
Just like we do (or will do) for floating types, we need to take into
acocunt that the LHSComputationType, ResultType and type of the
expression (what we ultimately store) might be different.
Do this by emitting cast ops before and after doing the computation.
This fixes the test failures introduced by
490e8214fca48824beda8b508d6d6bbbf3d8d9a7 on big endian machines.
Differential Revision: https://reviews.llvm.org/D142328
We often visit the same variable multiple times, e.g. once when checking
its initializer and later when compiling the function. Unify both of
those in visitVarDecl() and do the returning of the value in
visitDecl().
This time, use a VariableScope instead of a DeclScope for local
variables. This way, we don't emit Destroy ops for the local variables
immediately after creating them.
Differential Revision: https://reviews.llvm.org/D136815
We often visit the same variable multiple times, e.g. once when checking
its initializer and later when compiling the function. Unify both of
those in visitVarDecl() and do the returning of the value in
visitDecl().
Differential Revision: https://reviews.llvm.org/D136815
Use an InlineDescriptor per local variable to track whether locals
have been initialized or not. This way we can support uninitialized
local variables in constexpr functions.
Differential Revision: https://reviews.llvm.org/D135750
Before, when emitting a regular integer constant, we went:
Int -> APInt -> int -> emit
Fix this by using regular integer constants in emitConst() and instead
converting APInt to those once.
This was confusing. InitElem peeks a pointer, while InitElemPop will
pop the pointer. However, for fields, InitField would pop the pointer
and no InitFieldPop exists. At least make InitField and InitElem behave
the same.
If we don't need the result anyway, use StorePop, instead of a Store+Pop
combination. That way we save one instruction and not using the result
is the common case anyway.
visit (lowercase V) sets DiscardValue to false and calls Visit
(uppercase V). So we can't just call Visit (uppercase V) ourselves,
since then we aren't handling DiscardValue correctly.
This is currently irrelevant but will make a difference later.
Also, the naming isn't my fault and might change later.
When assigning to them, we can't classify the expression type, because
that doesn't contain the right information.
And when reading from them, we need to do the extra deref, just like we
do when reading from a DeclRefExpr.
Differential Revision: https://reviews.llvm.org/D136012
This reverts commit 6fa1795d1fd4770f9f5c00f5a30937d68c3feb17.
This breaks a windows builder:
../../clang/lib/AST/Interp/ByteCodeExprGen.h(236,11): error: call to constructor of 'clang::interp::APInt' (aka 'llvm::APInt') is ambiguous
APInt WrappedValue(getIntWidth(Ty), Value, std::is_signed<T>::value);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../clang/lib/AST/Interp/ByteCodeExprGen.cpp(409,16): note: in instantiation of function template specialization 'clang::interp::ByteCodeExprGen<clang::interp::ByteCodeEmitter>::emitConst<unsigned int>' requested here
return this->emitConst(E, E->getValue());
^
../../clang/lib/AST/Interp/ByteCodeExprGen.cpp(1149,16): note: in instantiation of member function 'clang::interp::ByteCodeExprGen<clang::interp::ByteCodeEmitter>::VisitCharacterLiteral' requested here
template class ByteCodeExprGen<ByteCodeEmitter>;
^
../../llvm/include\llvm/ADT/APInt.h(108,3): note: candidate constructor
APInt(unsigned numBits, uint64_t val, bool isSigned = false)
^
../../llvm/include\llvm/ADT/APInt.h(134,3): note: candidate constructor
APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
^
Instead of getting a pointer to a pointer to a value, followed by
dereferencing once, leaving us with a pointer to a value, we can instead
just get the pointer to the value (the reference in question) directly.
This simplifies (and shrinks) the generated bytecode somewhat.
This patch fixes:
clang/lib/AST/Interp/ByteCodeExprGen.cpp:978:24: warning: variable
‘T’ set but not used [-Wunused-but-set-variable]
T and ReturnType were introduced on August 19, 2022 in commit
8e41e6a4eafa2b667ec37ece33a85493fe0156c2.
Their last uses were removed on October 13, 2022 in commit
0e754cfadc9487282d9b6119c41962c5c6c3660f.