[llvm-branch-commits] [clang] ebbb544 - [Clang] Fix variant crashes from GH58028, GH57370

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Oct 3 03:54:42 PDT 2022


Author: Roy Jacobson
Date: 2022-10-03T09:04:51+02:00
New Revision: ebbb5446b0a241a1dc751df2eaa9898b26668834

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

LOG: [Clang] Fix variant crashes from GH58028, GH57370

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

Reviewed By: shafik

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

(cherry picked from commit 9415aad6a40fec74296008a25f34164a95c857f4)

Added: 
    clang/test/SemaCXX/specialization-diagnose-crash.cpp

Modified: 
    clang/lib/Sema/SemaInit.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d3b454843234b..bf7ca718a36b2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -695,10 +695,10 @@ void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
         //   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;

diff  --git a/clang/test/SemaCXX/specialization-diagnose-crash.cpp b/clang/test/SemaCXX/specialization-diagnose-crash.cpp
new file mode 100644
index 0000000000000..5fd387cab19d9
--- /dev/null
+++ b/clang/test/SemaCXX/specialization-diagnose-crash.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only %s --std=c++17 -verify
+// This is a reduction of GH57370 and GH58028, originally appearing
+// in libstdc++'s variant code.
+
+struct V1 {};
+struct V2 : V1 {
+  int &a;
+};
+
+template <class T> using void_t = void;
+
+template <class T> struct X { T x; };
+
+template <class T1, class T2, class = void> struct Variant {
+  Variant() = delete; // expected-note {{deleted here}}
+};
+
+template <class T1, class T2>
+struct Variant<T1, T2, void_t<decltype(X<T2>{T1()})>> {};
+
+void f() {
+  Variant<V1, V1>();
+  Variant<V1, V2>(); // expected-error {{call to deleted constructor}}
+}


        


More information about the llvm-branch-commits mailing list