[clang] [clang][Interp] Fix returning nullptr from functions (PR #67229)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 01:28:03 PDT 2023
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/67229
>From 32d5ecddc5b6aff44440924b48a0b35128be7b07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sat, 23 Sep 2023 11:41:52 +0200
Subject: [PATCH] [clang][Interp] Fix returning nullptr from functions
isLive() is false for null pointers, so we need to special-case
this here.
---
clang/lib/AST/Interp/Interp.h | 3 ++-
clang/test/AST/Interp/functions.cpp | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index d62e64bedb213ac..47dc1d08c9c4d8b 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -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;
}
diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index 5cdecbff1e9d3d4..68082576f2735e9 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -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, "");
+}
More information about the cfe-commits
mailing list