diff options
| -rw-r--r-- | clang/lib/AST/Interp/Pointer.cpp | 6 | ||||
| -rw-r--r-- | clang/test/AST/Interp/literals.cpp | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp index 8a0a155..3f85635 100644 --- a/clang/lib/AST/Interp/Pointer.cpp +++ b/clang/lib/AST/Interp/Pointer.cpp @@ -232,11 +232,7 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx) const { // Primitive values. if (std::optional<PrimType> T = Ctx.classify(Ty)) { - if (T == PT_Ptr || T == PT_FnPtr) { - R = Ptr.toAPValue(); - } else { - TYPE_SWITCH(*T, R = Ptr.deref<T>().toAPValue()); - } + TYPE_SWITCH(*T, R = Ptr.deref<T>().toAPValue()); return true; } diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index f5b5f77..9202bb9 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}} + } +} |
