Issue 174204
Summary [Clang] C++11 inheriting constructors are ABI incompatible with MSVC
Labels clang
Assignees
Reporter chrismile
    According to https://clang.llvm.org/docs/MSVCCompatibility.html, Clang aims to be ABI compatible with MSVC. AMD compiles their distributions of PyTorch with LLVM, while some Python modules relying on PyTorch, or PyTorch C++ extensions, may be using the MSVC compiler. While ABI compatibility should in theory work, there have been multiple user reports of undefined symbol errors:
- https://github.com/ROCm/TheRock/issues/2733
- https://github.com/ROCm/TheRock/issues/1490

The issue seems to be that PyTorch makes use of the C++11 inheriting constructors feature in its interface. An abbreviated version of the code can be found below.

```c++
namespace c10 {

class C10_API Error : public std::exception {
 public:
  Error(SourceLocation source_location, std::string msg);
  // ...
};

class C10_API ValueError : public Error {
  using Error::Error;
};

}
```

I have included a minimal reproducer in the attachment ([reproducer.zip](https://github.com/user-attachments/files/24407443/reproducer.zip)).
- When compiling with MSVC, `dumpbin /linkermember c10.lib` produces the following output:
```
1B __imp_??0ValueError@c10@@QEAA@$$QEAV01@@Z
1A __imp_??0ValueError@c10@@QEAA@AEBV01@@Z
21 __imp_??0ValueError@c10@@QEAA@USourceLocation@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
20 __imp_??0ValueError@c10@@QEAA@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
1F __imp_??0ValueError@c10@@QEAA@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$shared_ptr@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@3@@Z
1E __imp_??0ValueError@c10@@QEAA@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$shared_ptr@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@3@PEBX@Z
```
- When compiling with clang-cl.exe (`cmake -G Ninja -DCMAKE_C_COMPILER=%LLVM_PATH%/llvm-21.1.8/bin/clang-cl.exe -DCMAKE_CXX_COMPILER=%LLVM_PATH%/llvm-21.1.8/bin/clang-cl.exe -DCMAKE_RC_COMPILER=%LLVM_PATH%/llvm-21.1.8/bin/llvm-rc.exe ..`), the constructor taking `SourceLocation` is missing, which causes the undefined symbol errors for PyTorch. Please find the output of dumpbin below.
```
A __imp_??0ValueError@c10@@QEAA@$$QEAV01@@Z
B __imp_??0ValueError@c10@@QEAA@AEBV01@@Z
```
- The issue persists even when using `-fms-compatibility -fms-extensions` via `-DCMAKE_CXX_FLAGS="-fms-compatibility -fms-extensions"`.

I have reproduced the issue with the latest binary release of Clang+LLVM, i.e., version 21.1.8. The symbols that Clang-built libraries miss seem to be present both when compiling with MSVC 2022 and MSVC 2026.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to