[PATCH] D117569: Constexpr not supported with __declspec(dllimport).

Zahira Ammarguellat via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 21 14:25:39 PST 2022


zahiraam added a comment.

@majnemer

I did take an example completely different with no use of the constexpr in order to understand (at least for me) when the _imp prefix is generated with CL.
This is sample.cpp:
#include<iostream>

__declspec(dllexport) void PrintHello()
{

  std::cout << "hello" << std::endl;

}

$ cl  sample.cpp /LD /EHsc
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27045 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

sample.cpp
Microsoft (R) Incremental Linker Version 14.16.27045.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:sample.dll
/dll
/implib:sample.lib
sample.obj

  Creating library sample.lib and object sample.exp

$
This is testapp.cpp:
extern void __declspec(dllimport)PrintHello();

void main()
{

  PrintHello();

}

$ cl  testapp.cpp /EHsc /link sample.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27045 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

testapp.cpp
Microsoft (R) Incremental Linker Version 14.16.27045.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:testapp.exe
sample.lib
testapp.obj
$
$ dumpbin /symbols testapp.obj | grep imp
008 00000000 UNDEF  notype       External     | __imp_?PrintHello@@YAXXZ (__declspec(dllimport) void __cdecl PrintHello(void))
$

My understanding that the _imp prefix is generated because of the dllimport in testapp.cpp.
So if we go back to the test case above:

extern int __declspec(dllimport) dll_import_int;
constexpr int& dll_import_constexpr_ref = dll_import_int;
int& get() {

  return dll_import_constexpr_ref;

}
int main () {

  get();
  return 0;

}

CLANG (with this patch and ICL for that matter) generates the symbol:

011 00000000 UNDEF  notype       External     | __imp_?dll_import_int@@3HA (__declspec(dllimport) int dll_import_int)

but not MSVC. This seems incorrect to me since the _imp prefix is always generated for dllimport symbols?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117569/new/

https://reviews.llvm.org/D117569



More information about the cfe-commits mailing list