diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 9cab9a086958d..c26bda898687c 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2967,6 +2967,32 @@ TEST(Hover, All) { HI.NamespaceScope = ""; HI.Value = "0"; }}, + // Should not crash. + {R"objc( + typedef struct MyRect {} MyRect; + + @interface IFace + @property(nonatomic) MyRect frame; + @end + + MyRect foobar() { + MyRect mr; + return mr; + } + void test() { + IFace *v; + v.frame = [[foo^bar]](); + } + )objc", + [](HoverInfo &HI) { + HI.Name = "foobar"; + HI.Kind = index::SymbolKind::Function; + HI.NamespaceScope = ""; + HI.Definition = "MyRect foobar()"; + HI.Type = {"MyRect ()", "MyRect ()"}; + HI.ReturnType = {"MyRect", "MyRect"}; + HI.Parameters.emplace(); + }}, {R"cpp( void foo(int * __attribute__(([[non^null]], noescape)) ); )cpp", diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 130cf23737f10..630fb02d0531e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -7653,7 +7653,8 @@ class ExprEvaluatorBase } bool VisitOpaqueValueExpr(const OpaqueValueExpr *E) { - if (APValue *Value = Info.CurrentCall->getCurrentTemporary(E)) + if (APValue *Value = Info.CurrentCall->getCurrentTemporary(E); + Value && !Value->isAbsent()) return DerivedSuccess(*Value, E); const Expr *Source = E->getSourceExpr();