https://github.com/Sirraide created https://github.com/llvm/llvm-project/pull/83688
We were crashing on trying to print the layout of an uninstantiated template, which obviously doesn’t make sense. This fixes #83684. >From 4abc148104769bd756042c73edeb7ee54397a05f Mon Sep 17 00:00:00 2001 From: Sirraide <aeternalm...@gmail.com> Date: Sat, 2 Mar 2024 20:41:22 +0100 Subject: [PATCH 1/2] [Clang] [Sema] Do not attempt to dump the layout of dependent types --- clang/lib/AST/Decl.cpp | 2 +- clang/test/Layout/dump-complete.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 5d6bb72a208a1a..d069cd65732310 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -5042,7 +5042,7 @@ void RecordDecl::completeDefinition() { // Layouts are dumped when computed, so if we are dumping for all complete // types, we need to force usage to get types that wouldn't be used elsewhere. - if (Ctx.getLangOpts().DumpRecordLayoutsComplete) + if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType()) (void)Ctx.getASTRecordLayout(this); } diff --git a/clang/test/Layout/dump-complete.cpp b/clang/test/Layout/dump-complete.cpp index 9ccbf477c7052e..0a91d3329e6921 100644 --- a/clang/test/Layout/dump-complete.cpp +++ b/clang/test/Layout/dump-complete.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck %s struct a { int x; @@ -12,7 +12,34 @@ class c {}; class d; +template <typename> +struct s { + int x; +}; + +template <typename T> +struct ts { + T x; +}; + +void f() { + ts<int> a; + ts<double> b; +} + +namespace gh83684 { +template <class Pointer> +struct AllocationResult { + Pointer ptr = nullptr; + int count = 0; +}; +} + // CHECK: 0 | struct a // CHECK: 0 | struct b // CHECK: 0 | class c +// CHECK: 0 | struct ts<int> +// CHECK: 0 | struct ts<double> // CHECK-NOT: 0 | class d +// CHECK-NOT: 0 | struct s +// CHECK-NOT: 0 | struct AllocationResult >From 3056a8414cae4648a3cc8244cacef29e6dc00564 Mon Sep 17 00:00:00 2001 From: Sirraide <aeternalm...@gmail.com> Date: Sat, 2 Mar 2024 20:45:24 +0100 Subject: [PATCH 2/2] [Clang] Add release note --- clang/docs/ReleaseNotes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f44fef28b9f17f..69cf0cb643e6aa 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -308,6 +308,10 @@ Miscellaneous Bug Fixes Miscellaneous Clang Crashes Fixed ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- Do not attempt to dump the layout of dependent types when ``-fdump-record-layouts-complete`` + is passed. + Fixes (`#83684 <https://github.com/llvm/llvm-project/issues/83684>`_). + OpenACC Specific Changes ------------------------ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits