<div dir="ltr"><div>Hello all,<br><br></div>There has apparently been discussion for some time now about creating an ABI support library in Clang to be used for external developers. For some time now I've been wondering about the status of 
the proposed ABI support library. But I realized that I've effectively 
already implemented a good part of it myself. As an external developer I've been building a project on top of Clang for some time now with the aim of implementing the following features:<br><ul><li>Call into C and C++ functions declared in a header analyzed by Clang, including special members (including implicitly generated ones), operator overloads, those with defaulted arguments, and such,<br>

</li><li>Implement C and C++ functions declared in a header analyzed by Clang,</li><li>Access members of C and C++ types, including the virtual pointer and vtables,<br></li><li>Call C++ virtual functions, and implement types that effectively inherit from C++ types,</li>

<li>Code-generate C++ translation units into an LLVM module for use by external code generation mechanisms,</li><li>Create thunks with an arbitrary body for a given signature,<br></li><li>Perform C++ semantic analysis from external source; e.g. name lookup, template instantiation, overload resolution, and such,</li>

<li>Evaluate C++ macros and expressions within limited contexts; e.g. "Valid expression at global namespace scope in given TU". I am aware of one other who would be looking for "Valid statements at function scope; for given imaginary function X with local variables Y and Z of type W.",</li>
<li>Implement exception handling and RTTI with binary compatibility with Clang,<br></li>
</ul><p>Some of this stuff has been easily accessible via existing APIs; but some has not. So far I've had success implementing most of these features most of the time, but I've reached the inescapable conclusion that some of them will require patches for Clang. Since I know that I'm not the only one who would like these features, then I may as well just upstream them. <br>
</p>
<p>For semantic analysis, parsing and macro evaluation, I've generally determined that the existing APIs offer all the features required, but the user-friendliness is often a bit lacking. For example, when considering SourceLocations, some functions in the Sema randomly don't accept invalid ones, which hinders their use when invoking them externally, and I had ... fun ... trying to create my own SourceLocations that point to external locations.<br>

</p><p>The existing CodeGen modules were never designed, as far as 
I'm aware, to interface with external code generation, but in my 
experience, they can be made to do so relatively easily in <i>most</i> cases.</p>Currently, I've been operating on Itanium systems only (Ubuntu x64 and 
Windows x86 with MinGW) but I figure that it's a good start since 
Clang's own support for MSVC ABI is limited. I don't have any other targets available to test for. As for tests themselves, as far as I'm aware Clang uses a totally different testing strategy to me, so whilst I have a couple of basic existing tests, I'm not sure how they can be adapted. <br>
<br>Officially, IR-level interoperation with Clang isn't supported at all right now, and the CodeGen interfaces are private. I figure that before I start working on patches and providing 
interfaces, I want to find out if this is something that the Clang devs 
in general want to move forward with. My machine is very slow and building LLVM/Clang takes some time, so I'd really rather not get cracking only to find out that my patches are unwanted.<br></div>