Skip to content

Commit

Permalink
[clang][Interp] Not all RVO call expressions are initializing
Browse files Browse the repository at this point in the history
We do not necessarily prepare storage for the return value when
we are returning a complex value.
  • Loading branch information
tbaederr committed Feb 26, 2024
1 parent e521752 commit a5ccf85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,14 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
return false;
}
} else {
assert(Initializing);
// We need the result. Prepare a pointer to return or
// dup the current one.
if (!Initializing) {
if (std::optional<unsigned> LocalIndex = allocateLocal(E)) {
if (!this->emitGetPtrLocal(*LocalIndex, E))
return false;
}
}
if (!this->emitDupPtr(E))
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions clang/test/AST/Interp/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ void func(void) {
result = arr * ii;
}

constexpr _Complex float getComplexFloat() {
return {1,2};
}
static_assert(__real(getComplexFloat()) == 1, "");
static_assert(__imag(getComplexFloat()) == 2, "");

namespace CastToBool {
constexpr _Complex int F = {0, 1};
static_assert(F, "");
Expand Down

0 comments on commit a5ccf85

Please sign in to comment.