[clang] [Clang] Handle null templated declaration in visibility lookup (PR #234892)

Amrutha Tamminana via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 02:51:42 PST 2026


https://github.com/amrutha-tamminana updated https://github.com/llvm/llvm-project/pull/234892

>From a8972e218c3dbc1c33cef807e257763802ec134b Mon Sep 17 00:00:00 2001
From: Amrutha <cs24btech11060 at iith.ac.in>
Date: Fri, 23 Oct 2026 09:01:17 +0000
Subject: [PATCH 1/2] [Clang] Handle null templated declaration in visibility
 lookup

---
 clang/lib/AST/Decl.cpp                         |  6 ++++--
 .../CodeGenCXX/builtin-template-linkage.cpp    | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/builtin-template-linkage.cpp

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index ddf71ad1199af6..9ca825494683c6 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1305,8 +1305,10 @@ getExplicitVisibilityAux(const NamedDecl *ND,
   }
 
   // The visibility of a template is stored in the templated decl.
-  if (const auto *TD = dyn_cast<TemplateDecl>(ND))
-    return getVisibilityOf(TD->getTemplatedDecl(), kind);
+  if (const auto *TD = dyn_cast<TemplateDecl>(ND)) {
+    if (const NamedDecl *Templated = TD->getTemplatedDecl())
+      return getVisibilityOf(Templated, kind);
+  }
 
   return std::nullopt;
 }
diff --git a/clang/test/CodeGenCXX/builtin-template-linkage.cpp b/clang/test/CodeGenCXX/builtin-template-linkage.cpp
new file mode 100644
index 00000000000000..37d7152c73c3f6
--- /dev/null
+++ b/clang/test/CodeGenCXX/builtin-template-linkage.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// CHECK-DAG: @_ZN1QI19__type_pack_elementE1vE = linkonce_odr global
+// CHECK-DAG: @_ZTV1RI18__make_integer_seqE = linkonce_odr constant
+// CHECK-DAG: @r = global %struct.R
+// CHECK: define linkonce_odr void @_ZN1RI18__make_integer_seqE1fEv
+
+template <template <unsigned long, class...> class> struct Q {
+  static int v;
+};
+template <template <unsigned long, class...> class M> int Q<M>::v;
+int *p = &Q<__type_pack_element>::v;
+
+template <template <template <class T, T...> class, class T, T> class>
+struct R {
+  virtual void f() {}
+};
+
+R<__make_integer_seq> r;

>From ebc761372cd6696f8acde8f03307e691c8142e8d Mon Sep 17 00:00:00 2001
From: Amrutha <cs24btech11060 at iith.ac.in>
Date: Wed, 4 Nov 2026 10:50:28 +0000
Subject: [PATCH 2/2] [Clang] Add release note for builtin template visibility
 crash

---
 clang/docs/ReleaseNotes.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 523af5d0351c7d..32040719b08859 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1094,6 +1094,10 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
 
 #### Miscellaneous Clang Crashes Fixed
 
+- Fixed a crash during code generation when builtin templates such as
+  `__type_pack_element` or `__make_integer_seq` were used as template
+  template arguments of emitted entities. (#GH232739)
+
 - Fixed a crash in preprocessor conditionals containing `_Pragma`.
 - Fixed a crash when Microsoft extensions were enabled and an unterminated
   `__identifier` expression reached the end of a preprocessing directive or



More information about the cfe-commits mailing list