[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).
Zahira Ammarguellat via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 3 14:48:47 PDT 2022
zahiraam added a comment.
In D137107#3906413 <https://reviews.llvm.org/D137107#3906413>, @mstorsjo wrote:
> In D137107#3905443 <https://reviews.llvm.org/D137107#3905443>, @zahiraam wrote:
>
>> and the same assembly (load __imp_?val) (is that why you made the comment above?). And the test case runs.
>
> Yes, pretty much - the actual value of the address of `&val` isn't known at compile time and it cannot be produced in a way to initialize e.g. static memory, which I would believe that one can expect of constexpr. The runtime linker that loads DLLs can't fix it so that the address is available as a statically initialized data, but to use it it does require runtime code to fetch the address.
>
>> Without constexpr the symbol generated is
>>
>> 0E 00000000 UNDEF notype External | __imp_?val@@3HA (__declspec(dllimport) int val)
>>
>> and the assembly generates a ‘load __imp_? Val’. Same than MSVC, but the test case fails to run. @rnk Shouldn't this run?
>
> Can you give the full exact repro for this case, without constexpr, which you say fails to run - I tried to follow the instructions but for me it seems to work just fine, without constexpr.
Here is an even smaller test case.
lib.cpp:
__declspec(dllexport) int val=12;
t1.cpp:
int main () {
extern int _declspec(dllimport) val;
int& val_ref = val;
return val;
}
$ clang.exe -LD lib.cpp (this will create a.lib and a.exp)
$ clang.exe t1.cpp -la
$ ./a.exe
This will result in a popup message: "The application was unable to start correctly ..."
With MSVC
$ cl /LD lib.cpp (this will create lib.lib and lib.dll)
$ cl t1.cpp /link lib.lib
$ t1.exe
$ echo $?
12
$
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137107/new/
https://reviews.llvm.org/D137107
More information about the cfe-commits
mailing list