Author: Demo_mod
Date: 2026-11-27T10:09:45+01:00
New Revision: 097a3e7e588148774075cc9a283578e6ace432b0

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

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

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

Added: 
    

Modified: 
    clang/test/CodeGenCXX/template-instantiation.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGenCXX/template-instantiation.cpp 
b/clang/test/CodeGenCXX/template-instantiation.cpp
index bd0b5890c1a602..8c7b0eebf1e29e 100644
--- a/clang/test/CodeGenCXX/template-instantiation.cpp
+++ b/clang/test/CodeGenCXX/template-instantiation.cpp
@@ -204,3 +204,16 @@ namespace PR10666 {
     h2(s1); h2(s2); h2(s3);
   }
 }
+
+// The friend template definition used to be instantiated in the wrong template
+// context, so foo<U>{} stayed dependent and IR generation crashed.
+namespace GH89400 {
+  template <typename T> struct foo {
+    template <typename U> friend foo<U> make_foo() { return foo<U>{}; }
+  };
+  template <typename U> foo<U> make_foo();
+  // CHECK-LABEL: define void @_ZN7GH894004testEv()
+  // CHECK: call void @_ZN7GH894008make_fooIiEENS_3fooIT_EEv()
+  // CHECK-LABEL: define linkonce_odr void 
@_ZN7GH894008make_fooIiEENS_3fooIT_EEv()
+  void test() { make_foo<int>(); }
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to