Skip to content

Commit

Permalink
fix Issue 22674 - ImportC: compatible types declared in different tra…
Browse files Browse the repository at this point in the history
…nslation units are not treated equivalent in D
  • Loading branch information
WalterBright committed Sep 21, 2022
1 parent 58968d3 commit ab24cd2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions compiler/src/dmd/dmangle.d
Expand Up @@ -833,6 +833,22 @@ public:
printf(" parent = %s %s", s.parent.kind(), s.parent.toChars());
printf("\n");
}
if (s.parent)
{
if (auto m = s.parent.isModule())
{
if (m.filetype == FileType.c)
{
/* C types at global level get mangled into the __C global namespace
* to get the same mangling regardless of which module it
* is declared in. This works because types are the same if the mangling
* is the same.
*/
mangleIdentifier(Id.ImportC, s);
return;
}
}
}
mangleParent(s);
if (s.ident)
mangleIdentifier(s.ident, s);
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/frontend.h
Expand Up @@ -8522,6 +8522,7 @@ struct Id final
static Identifier* udaMustUse;
static Identifier* TRUE;
static Identifier* FALSE;
static Identifier* ImportC;
static Identifier* dllimport;
static Identifier* dllexport;
static Identifier* vector_size;
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/id.d
Expand Up @@ -512,6 +512,7 @@ immutable Msgtable[] msgtable =
{ "wchar_t" },

// for C compiler
{ "ImportC", "__C" },
{ "__tag" },
{ "dllimport" },
{ "dllexport" },
Expand Down
3 changes: 3 additions & 0 deletions compiler/test/compilable/imports/cimports2a.i
@@ -1 +1,4 @@
extern int xx;

typedef struct Foo *FooRef;
FooRef make_foo(void);
3 changes: 3 additions & 0 deletions compiler/test/compilable/imports/cimports2b.i
@@ -1 +1,4 @@
extern int xx;

typedef struct Foo *FooRef;
void free_foo(FooRef foo);
9 changes: 9 additions & 0 deletions compiler/test/compilable/test22674.d
@@ -0,0 +1,9 @@
// https://issues.dlang.org/show_bug.cgi?id=22674

import imports.cimports2a;
import imports.cimports2b;

void do_foo(){
FooRef f = make_foo(); // use_foo.d(5)
free_foo(f); // use_foo.d(6)
}

0 comments on commit ab24cd2

Please sign in to comment.