John Emmas via llvm-dev
2021-Sep-24 10:46 UTC
[llvm-dev] Disabling inline compilation (Clang with VS2019)
On 23/09/2021 16:03, John Emmas wrote:> > perhaps a DLL function CAN be inlined but only if it's specifically > declared as such? That makes a lot of sense and it would also explain > why I've never seen it here with ordinary DLL declarations (i.e. those > not declared using inline) >I found this Microsoft document about inlining:- https://docs.microsoft.com/en-us/cpp/cpp/inline-functions-cpp?view=msvc-160 About half way down there are two examples and the 2nd one states that class member functions which get implemented in a header file are now regarded as being implicitly inlined. This supports Paul's statement yesterday about the One Definition Rule - but what MS doesn't clarify is whether or not that'd also apply to DLL functions. Paul wrote:- On 23/09/2021 14:14, paul.robinson at sony.com wrote:> If MSVC promises not to inline a dllimport method, that seems like > something Clang should take into consideration in MS-compatibility > mode. >Two decades of experience with MSVC suggests that where a dllimport method isn't also declared as 'inline' the compiler won't attempt to inline it. To me that makes perfect sense but frustratingly, I just can't find it in writing anywhere :-( John
John Emmas via llvm-dev
2021-Sep-27 15:28 UTC
[llvm-dev] Disabling inline compilation (Clang with VS2019)
Aaaargh!! I just realised this was a spelling mistake at my end. Here's my original example... On 22/09/2021 13:22, John Emmas wrote:> > #if defined (BUILDING_DLL) > #define DLL_API __declspec(dllexport) > #else > #define DLL_API __declspec(dllimport) > #endif >But because the library can be built for different platforms, the actual code here was slightly more complicated - looking like this:- #if defined (COMPILER_MSVC) #if defined (BUILDING_DLL) #define DLL_API __declspec(dllexport) #else #define DLL_API __declspec(dllimport) #endif #else #define DLL_API #endif I'd changed the first line to read #if defined (COMPILER_MSVC) || defined (COMPILER_CLANG) - except that in the actual VS project file I'd then mis-spelled COMPILER_CLANG - so apologies and thanks to everyone who's helped here... I'd spent days looking through header files and source files without even thinking to check the VS project itself :-( Fixing this has made it compile and link with optimizations disabled ('/Ob0') but I guess I'll need to check what happens once I enable them again. If header-defined functions are routinely treated as inlined, I guess the problem might come back again :-( I suppose this brings up an obvious question... when building with MSVC I could have used the built-in preprocessor directive _MSC_VER rather than using my own COMPILER_MSVC - so does Clang have something built-in that's always similarly #defined? Or even better - does anyone know if there's some preprocessor directive that's always specified for both compilers (i.e. when they're being used with Visual Studio) ? Thanks again, John