https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/67229

isLive() is false for null pointers, so we need to special-case this here.

>From 60a6eade88991e9f80627cb52eb55c1aecbbc1cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@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       | 2 +-
 clang/test/AST/Interp/functions.cpp | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 8453856e526a6b2..71d49a0894f4e35 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -209,7 +209,7 @@ 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())
+    if (!Ret.isZero() && !Ret.isLive())
       return false;
   }
 
diff --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 331df74d50b3d62..7f03271d152db5c 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -332,3 +332,10 @@ namespace InvalidReclRefs {
   }
 #endif
 }
+
+namespace PtrReturn {
+  constexpr void *a() {
+    return nullptr;
+  }
+  static_assert(a() == nullptr, "");
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to