https://github.com/Glitch-On updated https://github.com/llvm/llvm-project/pull/231022
>From 4a989d7b1d32a14fe4a433c9469541c7d0d842af Mon Sep 17 00:00:00 2001 From: Vansh <[email protected]> Date: Mon, 12 Oct 2026 00:09:11 +0530 Subject: [PATCH] [clang] Add codegen regression test for friend function template 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 --- clang/test/CodeGenCXX/GH89400.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 clang/test/CodeGenCXX/GH89400.cpp 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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
