Skip to content

Commit

Permalink
[clang][Interp] Fix return statements with expresssion in void functions
Browse files Browse the repository at this point in the history
If the return type of a function is void, ReturnType is not set, but we
used to emit a RVOPtr instruction, which doesn't make sense for a
function returning void.

Differential Revision: https://reviews.llvm.org/D153649
  • Loading branch information
tbaederr committed Jul 26, 2023
1 parent e9eb836 commit 744a968
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/AST/Interp/ByteCodeStmtGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ bool ByteCodeStmtGen<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
return false;
this->emitCleanup();
return this->emitRet(*ReturnType, RS);
} else if (RE->getType()->isVoidType()) {
if (!this->visit(RE))
return false;
} else {
// RVO - construct the value in the return location.
if (!this->emitRVOPtr(RE))
Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/Interp/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,12 @@ namespace ReturnLocalPtr {
// ref-note {{read of variable whose lifetime has ended}} \
// expected-error {{not an integral constant expression}}
}

namespace VoidReturn {
/// ReturnStmt with an expression in a void function used to cause problems.
constexpr void bar() {}
constexpr void foo() {
return bar();
}
static_assert((foo(),1) == 1, "");
}

0 comments on commit 744a968

Please sign in to comment.