[clang] [clang] Add codegen regression test for friend function template (PR #231022)

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 11 11:43:53 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Demo_mod (Glitch-On)

<details>
<summary>Changes</summary>

The reproducer from #<!-- -->89400 crashed in IR generation because the friend template definition was instantiated in the wrong template context, leaving `foo<U>{}` dependent. #<!-- -->125266 fixed this but the case was not covered by a test.

The test is in CodeGenCXX because clang 19 accepts the reproducer with `-fsyntax-only` and only crashes when emitting IR.

Fixes #<!-- -->89400


---
Full diff: https://github.com/llvm/llvm-project/pull/231022.diff


1 Files Affected:

- (added) clang/test/CodeGenCXX/GH89400.cpp (+24) 


``````````diff
diff --git a/clang/test/CodeGenCXX/GH89400.cpp b/clang/test/CodeGenCXX/GH89400.cpp
new file mode 100644
index 0000000000000..1ff1f9d801070
--- /dev/null
+++ b/clang/test/CodeGenCXX/GH89400.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+// A friend function template defined inside a class template, where the
+// declaration found by the call and the one holding the definition have
+// different template contexts. The definition used to be instantiated in the
+// wrong context, so `foo<U>{}` stayed dependent and IR generation crashed.
+
+template <typename T>
+struct foo {
+  template <typename U>
+  friend foo<U> make_foo() { return foo<U>{}; }
+};
+
+template <typename U>
+foo<U> make_foo();
+
+void f() {
+  make_foo<int>();
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z1fv()
+// CHECK:         call void @_Z8make_fooIiE3fooIT_Ev()
+// CHECK-LABEL: define linkonce_odr void @_Z8make_fooIiE3fooIT_Ev()
+// CHECK:         ret void

``````````

</details>


https://github.com/llvm/llvm-project/pull/231022


More information about the cfe-commits mailing list