royjacobson created this revision. royjacobson added a reviewer: shafik. Herald added a project: All. royjacobson requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes a null dereference in some diagnostic issuing code. Closes https://github.com/llvm/llvm-project/issues/57370 Closes https://github.com/llvm/llvm-project/issues/58028 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134885 Files: clang/lib/Sema/SemaInit.cpp clang/test/SemaCXX/specialization-diagnose-crash.cpp Index: clang/test/SemaCXX/specialization-diagnose-crash.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/specialization-diagnose-crash.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify +// expected-no-diagnostics +// This is a reduction of GH57370 and GH58028, originally appearing +// in libstdc++'s variant code. + +struct V1 {}; +struct V2 : V1 { + int &a; +}; + +template <typename T> struct X { T x; }; + +template <class T1, class T2, class = void> struct Variant {}; + +template <class T1, class T2> struct Variant<T1, T2, decltype(X<T2>{T1()})> {}; + +void f() { Variant<V1, V2>(); } Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -695,10 +695,10 @@ // member of reference type uninitialized, the program is // ill-formed. SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized) - << Field->getType() - << ILE->getSyntacticForm()->getSourceRange(); - SemaRef.Diag(Field->getLocation(), - diag::note_uninit_reference_member); + << Field->getType() + << (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm()) + ->getSourceRange(); + SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member); } hadError = true; return;
Index: clang/test/SemaCXX/specialization-diagnose-crash.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/specialization-diagnose-crash.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify +// expected-no-diagnostics +// This is a reduction of GH57370 and GH58028, originally appearing +// in libstdc++'s variant code. + +struct V1 {}; +struct V2 : V1 { + int &a; +}; + +template <typename T> struct X { T x; }; + +template <class T1, class T2, class = void> struct Variant {}; + +template <class T1, class T2> struct Variant<T1, T2, decltype(X<T2>{T1()})> {}; + +void f() { Variant<V1, V2>(); } Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -695,10 +695,10 @@ // member of reference type uninitialized, the program is // ill-formed. SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized) - << Field->getType() - << ILE->getSyntacticForm()->getSourceRange(); - SemaRef.Diag(Field->getLocation(), - diag::note_uninit_reference_member); + << Field->getType() + << (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm()) + ->getSourceRange(); + SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member); } hadError = true; return;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits