Skip to content

Wrong named address space for anonymous struct #119705

@ubizjak

Description

@ubizjak

The following code when compiled with clang-19 (-O2):

struct s
{
  struct
  {
    int a;
    int b;
  } __seg_gs *c;
  int d;
};

struct s n;

void __seg_gs *t2 (void)
{
  return n.c;
}

errors out with:

_.c:34:10: error: returning 'struct (unnamed struct at segstr.c:22:3) *' from a function with result type '__attribute__((address_space(256))) void *' changes address space of pointer.

The error is wrong, as the c member should be put into __seg_gs named address space. Equivalent code with named struct:

struct _r
{
  int a;
  int b;
};

struct r
{
  struct _r __seg_gs *c;
  int d;
};

struct r m;

void __seg_gs *t1 (void)
{
  return m.c;
}

compiles OK.

GCC-14.2.1 is able to compile both testcases to the expected (the same) code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions