fix Issue 23545 - export int a; should generate dllexport, not dllimport (#14680)

This commit is contained in:
Walter Bright 2023-02-07 16:27:41 -08:00 committed by GitHub
parent df03a1797d
commit f1b70f41f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 8 deletions

View file

@ -0,0 +1,7 @@
export int a; now generates dllexport instead of dllimport
In order to make it dllimport, use:
---
export extern int a;
---

View file

@ -1314,9 +1314,17 @@ extern (C++) class VarDeclaration : Declaration
override final bool isImportedSymbol() const
{
if (visibility.kind == Visibility.Kind.export_ && !_init && (storage_class & STC.static_ || parent.isModule()))
return true;
return false;
/* If global variable has `export` and `extern` then it is imported
* export int sym1; // definition: exported
* export extern int sym2; // declaration: imported
* export extern int sym3 = 0; // error, extern cannot have initializer
*/
bool result =
visibility.kind == Visibility.Kind.export_ &&
storage_class & STC.extern_ &&
(storage_class & STC.static_ || parent.isModule());
//printf("isImportedSymbol() %s %d\n", toChars(), result);
return result;
}
final bool isCtorinit() const pure nothrow @nogc @safe

View file

@ -501,12 +501,18 @@ Symbol *toSymbol(Dsymbol s)
/*************************************
* Create Windows import symbol from backend Symbol.
* Params:
* sym = backend symbol
* loc = location for error message purposes
* Returns:
* import symbol
*/
Symbol *toImport(Symbol *sym, Loc loc)
private Symbol *createImport(Symbol *sym, Loc loc)
{
//printf("Dsymbol.toImport('%s')\n", sym.Sident);
char *n = sym.Sident.ptr;
//printf("Dsymbol.createImport('%s')\n", sym.Sident.ptr);
const char* n = sym.Sident.ptr;
import core.stdc.stdlib : alloca;
const allocLen = 6 + strlen(n) + 1 + type_paramsize(sym.Stype).sizeof*3 + 1;
char *id = cast(char *) alloca(allocLen);
@ -549,7 +555,7 @@ Symbol *toImport(Declaration ds)
{
if (!ds.csym)
ds.csym = toSymbol(ds);
ds.isym = toImport(ds.csym, ds.loc);
ds.isym = createImport(ds.csym, ds.loc);
}
return ds.isym;
}

View file

@ -6,8 +6,11 @@ int main()
return DISABLED;
version (DigitalMars)
version (OSX) // Shared libraries are not yet supported on OSX
{
// Disable DM Dlls for now, need to redesign it
// version (OSX) // Shared libraries are not yet supported on OSX
return DISABLED;
}
Vars.set(`SRC`, `$EXTRA_FILES/dll`);
Vars.set(`EXE_NAME`, `$OUTPUT_BASE/testdll$EXE`);