Author: Timm Bäder Date: 2024-02-13T08:44:15+01:00 New Revision: 66f73100b8c758248724d53598165d850fdaf364
URL: https://github.com/llvm/llvm-project/commit/66f73100b8c758248724d53598165d850fdaf364 DIFF: https://github.com/llvm/llvm-project/commit/66f73100b8c758248724d53598165d850fdaf364.diff LOG: [clang][Interp] Fix ltor conversion for pointer types This special case is wrong, we need to handle pointer types here just like anything else. Added: Modified: clang/lib/AST/Interp/Pointer.cpp clang/test/AST/Interp/literals.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp index 8a0a15547b0f2f..3f85635f43674d 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 f5b5f77ffc624b..9202bb98c822fc 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}} + } +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits