Skip to content

Commit

Permalink
[clang][Interp] Fix returning nullptr from functions (#67229)
Browse files Browse the repository at this point in the history
isLive() is false for null pointers, so we need to special-case this
here.
  • Loading branch information
tbaederr committed Oct 10, 2023
1 parent 6c4b3dc commit 17414ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/AST/Interp/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
// FIXME: We could be calling isLive() here, but the emitted diagnostics
// seem a little weird, at least if the returned expression is of
// pointer type.
if (!Ret.isLive())
// Null pointers are considered live here.
if (!Ret.isZero() && !Ret.isLive())
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions clang/test/AST/Interp/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,10 @@ namespace TemplateUndefined {
constexpr int l = consume(0);
static_assert(l == 0, "");
}

namespace PtrReturn {
constexpr void *a() {
return nullptr;
}
static_assert(a() == nullptr, "");
}

0 comments on commit 17414ea

Please sign in to comment.