Skip to content

Commit 17414ea

Browse files
authored
[clang][Interp] Fix returning nullptr from functions (#67229)
isLive() is false for null pointers, so we need to special-case this here.
1 parent 6c4b3dc commit 17414ea

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
214214
// FIXME: We could be calling isLive() here, but the emitted diagnostics
215215
// seem a little weird, at least if the returned expression is of
216216
// pointer type.
217-
if (!Ret.isLive())
217+
// Null pointers are considered live here.
218+
if (!Ret.isZero() && !Ret.isLive())
218219
return false;
219220
}
220221

clang/test/AST/Interp/functions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,10 @@ namespace TemplateUndefined {
343343
constexpr int l = consume(0);
344344
static_assert(l == 0, "");
345345
}
346+
347+
namespace PtrReturn {
348+
constexpr void *a() {
349+
return nullptr;
350+
}
351+
static_assert(a() == nullptr, "");
352+
}

0 commit comments

Comments
 (0)