@@ -480,3 +480,37 @@ void RecoveryForStmtCond() {
480480 // CHECK-NEXT: `-CompoundStmt {{.*}}
481481 for (int i = 0 ; i < invalid; ++i) {}
482482}
483+
484+ // Fix crash issue https://github.com/llvm/llvm-project/issues/112560.
485+ // Make sure clang compiles the following code without crashing:
486+
487+ // CHECK:NamespaceDecl {{.*}} GH112560
488+ // CHECK-NEXT: |-CXXRecordDecl {{.*}} referenced union U definition
489+ // CHECK-NEXT: | |-DefinitionData {{.*}}
490+ // CHECK-NEXT: | | |-DefaultConstructor {{.*}}
491+ // CHECK-NEXT: | | |-CopyConstructor {{.*}}
492+ // CHECK-NEXT: | | |-MoveConstructor {{.*}}
493+ // CHECK-NEXT: | | |-CopyAssignment {{.*}}
494+ // CHECK-NEXT: | | |-MoveAssignment {{.*}}
495+ // CHECK-NEXT: | | `-Destructor {{.*}}
496+ // CHECK-NEXT: | |-CXXRecordDecl {{.*}} implicit union U
497+ // CHECK-NEXT: | `-FieldDecl {{.*}} invalid f 'int'
498+ // CHECK-NEXT: | `-RecoveryExpr {{.*}} 'int' contains-errors
499+ // DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
500+ namespace GH112560 {
501+ union U {
502+ int f = ;
503+ };
504+
505+ // CHECK: FunctionDecl {{.*}} foo 'void ()'
506+ // CHECK-NEXT: `-CompoundStmt {{.*}}
507+ // CHECK-NEXT: `-DeclStmt {{.*}}
508+ // CHECK-NEXT: `-VarDecl {{.*}} g 'U':'GH112560::U' listinit
509+ // CHECK-NEXT: `-InitListExpr {{.*}} 'U':'GH112560::U' contains-errors field Field {{.*}} 'f' 'int'
510+ // CHECK-NEXT: `-CXXDefaultInitExpr {{.*}} 'int' contains-errors has rewritten init
511+ // CHECK-NEXT: `-RecoveryExpr {{.*}} 'int' contains-errors
512+ // DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
513+ void foo () {
514+ U g{};
515+ }
516+ } // namespace GH112560
0 commit comments