Skip to content

Magic UDAs dont get recogize by uda.cpp #5028

@zero-vector

Description

@zero-vector

Code to reproduce

file: test1.d

extern(C) __gshared bool test = true; 
void main() {}

file: test2.d

module test2; 
import ldc.attributes : weak; 

extern(C) __gshared @weak bool test = false; 
pragma(msg,  __traits(getAttributes, test)); // this triggers the error

command:
ldc2 -c test2.d && ldc2 test1.d test2.o

result

AliasSeq!(_weak())
/usr/bin/ld: test2.o:(.bss.test+0x0): multiple definition of `test'; test1.o:(.data.test+0x0): first defined here
collect2: error: ld returned 1 exit status

Observation

ldc defines most udas in arguments.d like this:

immutable weak = _weak();
private struct _weak {}

immutable weak = _weak();

uda.cpp scans symbols for attributes by checking isStructLiteralExp()

if (auto sle = attr->isStructLiteralExp())

but if expressionSemantic was run prior to this check, the attr expression is VarExp and the check fails.

A simple __traits(getAttributes, sym) can trigger this error.

Changing immutable to enum fixes the issue, but there is probably a reason immutable was chosen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions