Fix #20499 - [ImportC] typedef struct with name as a pointer cannot be used with struct name (#21232)

Fixes https://github.com/dlang/dmd/issues/20499
Fixes https://github.com/dlang/dmd/issues/20963

ImportC deferred declaring "tagged" types (structs/unions/enums)
until after it saw a possible typedef so that the identifier for
a typedef declaration like:

    typedef struct { int x; } Foo;

would give the struct the name Foo. In several circumstances,
this led to tagged types not being declared. Resolve this by
chasing down those circumstances.

Also, there were other circumstances where types weren't being
correctly declared which caused other issues. Lock those down.
This commit is contained in:
drpriver 2025-04-15 00:31:21 -07:00 committed by GitHub
parent c30def82bd
commit f4ca164257
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 456 additions and 68 deletions

View file

@ -0,0 +1,61 @@
// https://github.com/dlang/dmd/issues/20499
struct Outer {
struct __attribute__((aligned(8))) {
int x;
} n;
enum {A};
enum {B} b;
};
struct Outer2 {
struct __attribute__((aligned(8))) Nested {
int x;
} n;
};
const int x = A;
const int y = B;
struct Outer o = {3};
_Static_assert(_Alignof(typeof(o.n)) == 8, "");
_Static_assert(_Alignof(struct Outer) == 8, "");
_Static_assert(_Alignof(struct Outer2) == 8, "");
_Static_assert(_Alignof(struct Nested) == 8, "");
void test(void){
struct Outer {
struct __attribute__((aligned(16))) {
int x;
} n;
enum {A=2};
enum {B=3} b;
};
struct Outer2 {
struct __attribute__((aligned(16))) Nested {
int x;
} n;
};
const int x = A;
const int y = B;
struct Outer o = {3};
_Static_assert(_Alignof(typeof(o.n)) == 16, "");
_Static_assert(_Alignof(struct Outer) == 16, "");
_Static_assert(_Alignof(struct Outer2) == 16, "");
_Static_assert(_Alignof(struct Nested) == 16, "");
}
void test2(void){
const int x = A;
const int y = B;
struct Outer o = {3};
_Static_assert(_Alignof(typeof(o.n)) == 8, "");
_Static_assert(_Alignof(struct Outer) == 8, "");
_Static_assert(_Alignof(struct Outer2) == 8, "");
_Static_assert(_Alignof(struct Nested) == 8, "");
}