diff options
| author | Timm Bäder <tbaeder@redhat.com> | 2024-02-13 08:41:45 +0100 |
|---|---|---|
| committer | Timm Bäder <tbaeder@redhat.com> | 2024-02-13 08:44:15 +0100 |
| commit | 66f73100b8c758248724d53598165d850fdaf364 (patch) | |
| tree | 5e27e8983c330745564bfd530dbfc1f4a171cc54 | |
| parent | d033366bd2189e33343ca93d276b40341dc39770 (diff) | |
| download | llvm-66f73100b8c758248724d53598165d850fdaf364.zip llvm-66f73100b8c758248724d53598165d850fdaf364.tar.gz llvm-66f73100b8c758248724d53598165d850fdaf364.tar.bz2 | |
[clang][Interp] Fix ltor conversion for pointer types
This special case is wrong, we need to handle pointer types here
just like anything else.
| -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}} + } +} |
