hokein created this revision. hokein added a reviewer: sammccall. Herald added a project: clang.
The crash is triggered on accessing a null InitExpr. For group declaration, e.g. `auto c = a, &d = {a};`, what's happening: 1. each VarDecl is built separately during the parsing stage. 2. perform the semantic analysis (Sema::BuildDeclaratorGroup) to check whether the type of the two VarDecl is the same, if not mark it as invalid. in step 1, VarDecl c and d are built, both of them are valid (after D77395 <https://reviews.llvm.org/D77395>), but d is without the InitExpr attached (under -fno-recovery-ast), crash happens in step 2 when accessing the source range of d's InitExpr. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D79473 Files: clang/lib/Sema/SemaDecl.cpp clang/test/SemaCXX/auto-invalid-init-crash.cpp Index: clang/test/SemaCXX/auto-invalid-init-crash.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/auto-invalid-init-crash.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fno-recovery-ast -verify %s + +namespace std { +template <typename> +class initializer_list{}; +int a; +auto c = a, &d = {a}; // expected-error {{'auto' deduced as 'int'}} \ + expected-error {{non-const lvalue reference to type}} +} // namespace std Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -13208,13 +13208,15 @@ DeducedDecl = D; } else if (!Context.hasSameType(DT->getDeducedType(), Deduced)) { auto *AT = dyn_cast<AutoType>(DT); - Diag(D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(), - diag::err_auto_different_deductions) - << (AT ? (unsigned)AT->getKeyword() : 3) - << Deduced << DeducedDecl->getDeclName() - << DT->getDeducedType() << D->getDeclName() - << DeducedDecl->getInit()->getSourceRange() - << D->getInit()->getSourceRange(); + auto Dia = Diag(D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(), + diag::err_auto_different_deductions) + << (AT ? (unsigned)AT->getKeyword() : 3) << Deduced + << DeducedDecl->getDeclName() << DT->getDeducedType() + << D->getDeclName(); + if (DeducedDecl->hasInit()) + Dia << DeducedDecl->getInit()->getSourceRange(); + if (D->getInit()) + Dia << D->getInit()->getSourceRange(); D->setInvalidDecl(); break; }
Index: clang/test/SemaCXX/auto-invalid-init-crash.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/auto-invalid-init-crash.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fno-recovery-ast -verify %s + +namespace std { +template <typename> +class initializer_list{}; +int a; +auto c = a, &d = {a}; // expected-error {{'auto' deduced as 'int'}} \ + expected-error {{non-const lvalue reference to type}} +} // namespace std Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -13208,13 +13208,15 @@ DeducedDecl = D; } else if (!Context.hasSameType(DT->getDeducedType(), Deduced)) { auto *AT = dyn_cast<AutoType>(DT); - Diag(D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(), - diag::err_auto_different_deductions) - << (AT ? (unsigned)AT->getKeyword() : 3) - << Deduced << DeducedDecl->getDeclName() - << DT->getDeducedType() << D->getDeclName() - << DeducedDecl->getInit()->getSourceRange() - << D->getInit()->getSourceRange(); + auto Dia = Diag(D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(), + diag::err_auto_different_deductions) + << (AT ? (unsigned)AT->getKeyword() : 3) << Deduced + << DeducedDecl->getDeclName() << DT->getDeducedType() + << D->getDeclName(); + if (DeducedDecl->hasInit()) + Dia << DeducedDecl->getInit()->getSourceRange(); + if (D->getInit()) + Dia << D->getInit()->getSourceRange(); D->setInvalidDecl(); break; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits