diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1638,7 +1638,7 @@ expr = Result.getAs(); // FIXME: Why are we updating the syntactic init list? - if (!VerifyOnly) + if (!VerifyOnly && expr) IList->setInit(Index, expr); if (hadError) diff --git a/clang/test/AST/ast-dump-recovery.cpp b/clang/test/AST/ast-dump-recovery.cpp --- a/clang/test/AST/ast-dump-recovery.cpp +++ b/clang/test/AST/ast-dump-recovery.cpp @@ -181,3 +181,14 @@ // Verified that the generated call operator is invalid. // CHECK: |-CXXMethodDecl {{.*}} invalid operator() 'auto () const -> auto' using Escape = decltype([] { return undef(); }()); + +// CHECK: VarDecl {{.*}} NoCrashOnInvalidInitList +// CHECK-NEXT: `-RecoveryExpr {{.*}} '' contains-errors lvalue +// CHECK-NEXT: `-InitListExpr +// CHECK-NEXT: `-DesignatedInitExpr {{.*}} 'void' +// CHECK-NEXT: `-CXXNullPtrLiteralExpr {{.*}} 'nullptr_t' +struct { + int& abc; +} NoCrashOnInvalidInitList = { + .abc = nullptr, +};