diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp index 8a0a15547b0f2..3f85635f43674 100644 --- a/clang/lib/AST/Interp/Pointer.cpp +++ b/clang/lib/AST/Interp/Pointer.cpp @@ -232,11 +232,7 @@ std::optional Pointer::toRValue(const Context &Ctx) const { // Primitive values. if (std::optional T = Ctx.classify(Ty)) { - if (T == PT_Ptr || T == PT_FnPtr) { - R = Ptr.toAPValue(); - } else { - TYPE_SWITCH(*T, R = Ptr.deref().toAPValue()); - } + TYPE_SWITCH(*T, R = Ptr.deref().toAPValue()); return true; } diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index f5b5f77ffc624..9202bb98c822f 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -1105,3 +1105,13 @@ namespace NonConstReads { static_assert(z == 0, ""); // both-error {{not an integral constant expression}} \ // both-note {{read of non-const variable 'z'}} } + +/// This test passes a MaterializedTemporaryExpr to evaluateAsRValue. +/// That needs to return a null pointer after the lvalue-to-rvalue conversion. +/// We used to fail to do that. +namespace rdar8769025 { + __attribute__((nonnull)) void f1(int * const &p); + void test_f1() { + f1(0); // both-warning{{null passed to a callee that requires a non-null argument}} + } +}