Author: Timm Baeder Date: 2023-10-10T11:19:14+02:00 New Revision: 17414eae242b77fe40ce671793bce5fb2e6a3a04
URL: https://github.com/llvm/llvm-project/commit/17414eae242b77fe40ce671793bce5fb2e6a3a04 DIFF: https://github.com/llvm/llvm-project/commit/17414eae242b77fe40ce671793bce5fb2e6a3a04.diff LOG: [clang][Interp] Fix returning nullptr from functions (#67229) isLive() is false for null pointers, so we need to special-case this here. Added: Modified: clang/lib/AST/Interp/Interp.h clang/test/AST/Interp/functions.cpp Removed: ################################################################################ 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, ""); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits