The calling convention is:
[RVO pointer]
[instance pointer]
[... args ...]
We handle the instance pointer ourselves, BUT for the RVO pointer, we
just assumed in visitReturnStmt() that it is on top of the stack. Which
isn't true if there are other args present (and a this pointer, maybe).
Fix this by recording the RVO pointer explicitly when creating an
InterpFrame, just like we do with the instance/This pointer.
There is already a "RVOAndParams()" test in test/AST/Inter/records.cpp,
that was supposed to test this, however, it didn't trigger any
problematic behavior because the parameter and the return value have the
same type.
Differential Revision: https://reviews.llvm.org/D137392
This way we're invoking the copy constructor, which might be necessary
if the argument is not trivially constructible.
Differential Revision: https://reviews.llvm.org/D138554
This was done as a test for D137302 and it makes sense to push these changes
Reviewed By: shafik
Differential Revision: https://reviews.llvm.org/D137491
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.
They get allocated when calling initialize() on a primitive array. And
they get free'd when the array is fully initialized. However, when that
never happens, they get leaked. Fix that by calling the destructor of
global variables.
Differential Revision: https://reviews.llvm.org/D136826
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 fixes the following warning:
../tools/clang/lib/AST/Interp/Disasm.cpp: In member function ‘void clang::interp::Function::dump(llvm::raw_ostream&) const’:
../tools/clang/lib/AST/Interp/Disasm.cpp:43:25: warning: cast from type ‘const clang::interp::Function*’ to type ‘void*’ casts away qualifiers [-Wcast-qual]
43 | OS << " " << (void*)this << ":\n";
| ^~~~
This reverts commit 6fa1795d1f.
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.
Since we pass this via the stack, we need to account for it when
desribing the stack frame (parameters). This fixes a previously
commented-out test case.
Differential Revision: https://reviews.llvm.org/D136670
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
8e41e6a4ea.
Their last uses were removed on October 13, 2022 in commit
0e754cfadc.