Skip to content

Commit a5ccf85

Browse files
committed
[clang][Interp] Not all RVO call expressions are initializing
We do not necessarily prepare storage for the return value when we are returning a complex value.
1 parent e521752 commit a5ccf85

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,14 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
27032703
return false;
27042704
}
27052705
} else {
2706-
assert(Initializing);
2706+
// We need the result. Prepare a pointer to return or
2707+
// dup the current one.
2708+
if (!Initializing) {
2709+
if (std::optional<unsigned> LocalIndex = allocateLocal(E)) {
2710+
if (!this->emitGetPtrLocal(*LocalIndex, E))
2711+
return false;
2712+
}
2713+
}
27072714
if (!this->emitDupPtr(E))
27082715
return false;
27092716
}

clang/test/AST/Interp/complex.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ void func(void) {
124124
result = arr * ii;
125125
}
126126

127+
constexpr _Complex float getComplexFloat() {
128+
return {1,2};
129+
}
130+
static_assert(__real(getComplexFloat()) == 1, "");
131+
static_assert(__imag(getComplexFloat()) == 2, "");
132+
127133
namespace CastToBool {
128134
constexpr _Complex int F = {0, 1};
129135
static_assert(F, "");

0 commit comments

Comments
 (0)