[clang] MSVC ABI mangler crashes on template<auto F> when F is pointer to explicit object parameter member function
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Repro
```C++
struct S {
int f(this const S&, int x) { return x; }
};
template
int call() { return 0; }
int main() {
return call<&S::f>();
}
```
[godbolt](https://gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:2,endLineNumber:8,positionColumn:2,positionLineNumber:8,selectionStartColumn:2,selectionStartLineNumber:8,startColumn:2,startLineNumber:8),source:'struct+S+%7B%0A++++int+f(this+const+S%26,+int+x)+%7B+return+x%3B+%7D%0A%7D%3B%0Atemplate%3Cauto+F%3E%0Aint+call()+%7B+return+0%3B+%7D%0Aint+main()+%7B%0A++++return+call%3C%26S::f%3E()%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:56.421180766889826,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:c%2B%2B,libs:!(),options:'+-std%3Dc%2B%2B23+--target%3Dx86_64-pc-windows-msvc',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+(trunk)+(Editor+%231)',t:'0')),k:49.9550907245516,l:'4',m:50,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+(trunk)',editorid:1,fontScale:14,fontUsePx:'0',j:2,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+(trunk)+(Compiler+%232)',t:'0')),header:(),l:'4',m:50,n:'0',o:'',s:0,t:'0')),k:43.57881923311016,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) repro
Crashes: clang++ -std=c++23 --target=x86_64-pc-windows-msvc -c repro.cpp
OK: clang++ -std=c++23 --target=x86_64-pc-linux-gnu -c repro.cpp
OK: clang++ -std=c++23 --target=x86_64-pc-windows-gnu -c repro.cpp
## Affected version
Clang 20.1.8 through 22.1.3
clang version 22.1.3 (https://github.com/llvm/llvm-project e9846648fd6183ee6d8cbdb4502213fcf902a211)
## Crash stack
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: "C:\\Program Files\\LLVM\\bin\\clang++.exe" -std=c++23 -c temp/repro.cpp -o temp/repro.o
1. parser at end of file
2. temp/repro.cpp:14:5: LLVM IR generation of declaration 'main'
3. temp/repro.cpp:14:5: Generating code for declaration 'main'
4. temp/repro.cpp:12:5: Mangling declaration 'call'
Exception Code: 0xC0000005
#0 0x00007ff6364fe493 (C:\Program Files\LLVM\bin\clang++.exe+0x19e493)
#1 0x00007ff6364fdfe3 (C:\Program Files\LLVM\bin\clang++.exe+0x19dfe3)
#2 0x00007ff637ae869d (C:\Program Files\LLVM\bin\clang++.exe+0x178869d)
#3 0x00007ff637adfa36 (C:\Program Files\LLVM\bin\clang++.exe+0x177fa36)
#4 0x00007ff637addf2d (C:\Program Files\LLVM\bin\clang++.exe+0x177df2d)
#5 0x00007ff637ad7b48 (C:\Program Files\LLVM\bin\clang++.exe+0x1777b48)
#6 0x00007ff637a687ee (C:\Program Files\LLVM\bin\clang++.exe+0x17087ee)
#7 0x00007ff637c81308 (C:\Program Files\LLVM\bin\clang++.exe+0x1921308)
#8 0x00007ff637c7fded (C:\Program Files\LLVM\bin\clang++.exe+0x191fded)
#9 0x00007ff637c74b7b (C:\Program Files\LLVM\bin\clang++.exe+0x1914b7b)
#10 0x00007ff637c72685 (C:\Program Files\LLVM\bin\clang++.exe+0x1912685)
#11 0x00007ff637c710fc (C:\Program Files\LLVM\bin\clang++.exe+0x19110fc)
#12 0x00007ff637c6ad79 (C:\Program Files\LLVM\bin\clang++.exe+0x190ad79)
#13 0x00007ff637c68341 (C:\Program Files\LLVM\bin\clang++.exe+0x1908341)
#14 0x00007ff636365f8f (C:\Program Files\LLVM\bin\clang++.exe+0x5f8f)
#15 0x00007ff6375fbfae (C:\Program Files\LLVM\bin\clang++.exe+0x129bfae)
#16 0x00007ff6375fbc1f (C:\Program Files\LLVM\bin\clang++.exe+0x129bc1f)
#17 0x00007ff6375fa2e2 (C:\Program Files\LLVM\bin\clang++.exe+0x129a2e2)
#18 0x00007ff6375f6b8d (C:\Program Files\LLVM\bin\clang++.exe+0x1296b8d)
#19 0x00007ff6375f5ed5 (C:\Program Files\LLVM\bin\clang++.exe+0x1295ed5)
#20 0x00007ff637a5e25b (C:\Program Files\LLVM\bin\clang++.exe+0x16fe25b)
#21 0x00007ff637a5ba7c (C:\Program Files\LLVM\bin\clang++.exe+0x16fba7c)
#22 0x00007ff638366e56 (C:\Program Files\LLVM\bin\clang++.exe+0x2006e56)
#23 0x00007ff6377ef5c5 (C:\Program Files\LLVM\bin\clang++.exe+0x148f5c5)
#24 0x00007ff636998493 (C:\Program Files\LLVM\bin\clang++.exe+0x638493)
#25 0x00007ff6369980cd (C:\Program Files\LLVM\bin\clang++.exe+0x6380cd)
#26 0x00007ff6369962c9 (C:\Program Files\LLVM\bin\clang++.exe+0x6362c9)
#27 0x00007ff6369921af (C:\Program Files\LLVM\bin\clang++.exe+0x6321af)
#28 0x00007ff636990b25 (C:\Program Files\LLVM\bin\clang++.exe+0x630b25)
#29 0x00007ff6372e8a5d (C:\Program Files\LLVM\bin\clang++.exe+0xf88a5d)
#30 0x00007ff636b601d5 (C:\Program Files\LLVM\bin\clang++.exe+0x8001d5)
#31 0x00007ff636b5ffc8 (C:\Program Files\LLVM\bin\clang++.exe+0x7fffc8)
#32 0x00007ff6364a083b (C:\Program Files\LLVM\bin\clang++.exe+0x14083b)
#33 0x00007ff6364a017e (C:\Program Files\LLVM\bin\clang++.exe+0x14017e)
#34 0x00007ff63649fe92 (C:\Program Files\LLVM\bin\clang++.exe+0x13fe92)
#35 0x00007ff636497b0d (C:\Program Files\LLVM\bin\clang++.exe+0x137b0d)
#36 0x00007ff636494a83 (C:\Program Files\LLVM\bin\clang++.exe+0x134a83)
#37 0x00007ff6383bc9ec (C:\Program Files\LLVM\bin\clang++.exe+0x205c9ec)
#38 0x00007ffd9727e8d7 (C:\windows\System32\KERNEL32.DLL+0x2e8d7)
#39 0x00007ffd97e1c34c (C:\windows\SYSTEM32\ntdll.dll+0x3c34c)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 22.1.3 (https://github.com/llvm/llvm-project e9846648fd6183ee6d8cbdb4502213fcf902a211)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
```
## Cause analyzes from AI
The crash is in MicrosoftMangle.cpp (the MSVC ABI name mangler). When mangling a template specialization where F is &S::f and f is declared with an explicit object parameter (this const S&), the mangler hits a null pointer dereference (0xC0000005) because it doesn't know how to represent this function pointer type in the MSVC mangling scheme.
Key observations:
- Itanium ABI (Linux, MinGW targets): works fine -- the Itanium mangler handles this correctly
- MSVC ABI (windows-msvc target): crashes -- the Microsoft mangler doesn't handle explicit object parameter member function pointers as NTTP values
- Affects clang 20, 22, and likely trunk (the MSVC mangler code for NTTP has known gaps per issue #97792)
## Not an Existing Bug
- #106660 #106865 is about clang rejecting F(x) invocation syntax (a Sema error), not a mangler crash
- No open issue matches "explicit object" + "mangl" on LLVM's issue tracker
Contributor guide
Research direction
Start by reproducing the crash with the provided C++ source and clang++ -std=c++23 --target=x86_64-pc-windows-msvc. Read the MSVC ABI mangling path in MicrosoftMangle.cpp, especially handling of template non-type parameters and explicit-object member-function pointers. Done means the reproducer compiles without crashing and coverage exists for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100