[clang] 97b8dab - [AST] Fix a null initializer crash for InitListExpr

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 2 01:58:10 PDT 2020


Author: Haojian Wu
Date: 2020-06-02T10:48:48+02:00
New Revision: 97b8dabba5c5c1d799bd8b6856d4a81360361769

URL: https://github.com/llvm/llvm-project/commit/97b8dabba5c5c1d799bd8b6856d4a81360361769
DIFF: https://github.com/llvm/llvm-project/commit/97b8dabba5c5c1d799bd8b6856d4a81360361769.diff

LOG: [AST] Fix a null initializer crash for InitListExpr

Summary:
The Initializer of a InitListExpr can be reset to null, which leads to
nullptr-acces crashes.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80980

Added: 
    

Modified: 
    clang/lib/Sema/SemaInit.cpp
    clang/test/AST/ast-dump-recovery.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 56d7ac8dde50..0a98cb2a5ce0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1638,7 +1638,7 @@ void InitListChecker::CheckReferenceType(const InitializedEntity &Entity,
 
   expr = Result.getAs<Expr>();
   // 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
index 9b13f4d3e06b..a212ff41c0c9 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -181,3 +181,14 @@ void InitializerForAuto() {
 // 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 {{.*}} '<dependent type>' contains-errors lvalue
+// CHECK-NEXT:   `-InitListExpr
+// CHECK-NEXT:     `-DesignatedInitExpr {{.*}} 'void'
+// CHECK-NEXT:       `-CXXNullPtrLiteralExpr {{.*}} 'nullptr_t'
+struct {
+  int& abc;
+} NoCrashOnInvalidInitList = {
+  .abc = nullptr,
+};


        


More information about the cfe-commits mailing list