[PATCH] Sema: Allow dll attributes on inline functions

Aaron Ballman aaron at aaronballman.com
Wed Apr 2 05:45:18 PDT 2014


>    // A redeclaration is not allowed to drop a dllimport attribute, the only
>    // exception being inline function definitions.
> -  // FIXME: Handle inline functions.
>    // NB: MSVC converts such a declaration to dllexport.
> -  if (OldImportAttr && !HasNewAttr) {
> +  FunctionDecl *NewFD = dyn_cast<FunctionDecl>(NewDecl);
> +  if (OldImportAttr && !HasNewAttr && !(NewFD && NewFD->isInlined())) {
>      S.Diag(NewDecl->getLocation(),

Is the NB comment still applicable? I don't see anything converting
such a declaration into a dllexport.

> +    bool IsExplicit =
> +      FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization ||
> +      FD->getTemplateSpecializationKind() ==TSK_ExplicitInstantiationDefinition;

Formatting is a bit weird here with the space missing -- is this how
clang-format handles it?

err_attribute_can_be_applied_only_to_symbol_declaration is no longer
used, and can be removed from DiagnosticSemaKinds.td.

Something appears to be amiss with this patch -- the follow example
works in MSVC 2013 and creates an exported function, but causes a
fatal error in clang.

struct S {
  __declspec(dllimport) inline void func(void) {}
};

void func() {
  S s;
  s.func();
}

MSVC:
EXTRN __imp_?func at S@@QAEXXZ:PROC

clang (with your patch applied):

E:\llvm\2013>clang -S -emit-llvm -o - -fms-compatibility "E:\Aaron Ballman\Deskt
op\test.cpp"
Function is marked as dllimport, but not external.
void (%struct.S*)* @"\01?func at S@@QAEXXZ"
fatal error: error in backend: Broken function found, compilation aborted!
Stack dump:
0.      Program arguments: e:\llvm\2013\Debug\bin\clang.exe -cc1 -triple i686-pc
-windows-msvc -emit-llvm -disable-free -main-file-name test.cpp -mrelocation-mod
el static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -ta
rget-cpu pentium4 -coverage-file E:\llvm\2013\- -resource-dir e:\llvm\2013\Debug
\bin\..\lib\clang\3.5.0 -internal-isystem e:\llvm\2013\Debug\bin\..\lib\clang\3.
5.0\include -internal-isystem D:\Program Files (x86)\Microsoft Visual Studio 12.
0\VC\INCLUDE -internal-isystem D:\Program Files (x86)\Microsoft Visual Studio 12
.0\VC\ATLMFC\INCLUDE -internal-isystem C:\Program Files (x86)\Windows Kits\8.1\i
nclude\shared -internal-isystem C:\Program Files (x86)\Windows Kits\8.1\include\
um -internal-isystem C:\Program Files (x86)\Windows Kits\8.1\include\winrt -std=
c++11 -fdeprecated-macro -fdebug-compilation-dir E:\llvm\2013 -ferror-limit 19 -
fmessage-length 80 -mstackrealign -fms-extensions -fms-compatibility -fmsc-versi
on=1700 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexcepti
ons -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o - -x c++ E:\
Aaron Ballman\Desktop\test.cpp
1.      <eof> parser at end of file
2.      Per-function optimization
3.      Running pass 'Module Verifier' on function '@"\01?func at S@@QAEXXZ"'
clang.exe: error: clang frontend command failed with exit code 70 (use -v to see
 invocation)
clang version 3.5.0 (205324)
Target: i686-pc-windows-msvc
Thread model: posix
clang.exe: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/b
ugs/ and include the crash backtrace, preprocessed source, and associated run sc
ript.
clang.exe: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang.exe: note: diagnostic msg: E:\temp\test-f4323c.cpp
clang.exe: note: diagnostic msg: E:\temp\test-f4323c.sh
clang.exe: note: diagnostic msg:

********************

Thanks for working on this!

~Aaron

On Wed, Apr 2, 2014 at 2:34 AM, Nico Rieck <nico.rieck at gmail.com> wrote:
> This patch implements semantic handling of inline functions declared
> dllimport or dllexport.
>
> Both attributes are allowed on function definitions if they are declared
> inline. Explicit specializations and instantiation definitions
> do not have to be specified as inline (this is how MSVC behaves).
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list