www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.internals - UDA segfaults compiler

reply Elmar <chrehme gmx.de> writes:
Hello D people,

I found a segmentation fault which I can reproduce with `dmd` and 
`ldc2`.

The attack code is simple:

```
alias getOne =  (0) function int () => 1;
```

It works without the UDA but segfaults with it. I found it 
because I wanted to have user-defined attributes to the return 
values of functions. I can't put the UDA after `function` so I 
put it before.

I believe, this is a forgotton corner case or something because 
the compiler tells me, UDAs are not allowed in alias definitions.
Jul 17 2021
parent reply Basile B. <b2.temp gmx.com> writes:
On Saturday, 17 July 2021 at 16:33:54 UTC, Elmar wrote:
 Hello D people,

 I found a segmentation fault which I can reproduce with `dmd` 
 and `ldc2`.

 The attack code is simple:

 ```
 alias getOne =  (0) function int () => 1;
 ```

 It works without the UDA but segfaults with it. I found it 
 because I wanted to have user-defined attributes to the return 
 values of functions. I can't put the UDA after `function` so I 
 put it before.

 I believe, this is a forgotton corner case or something because 
 the compiler tells me, UDAs are not allowed in alias 
 definitions.
This is an assertion failure in the parser, [reported here](https://issues.dlang.org/show_bug.cgi?id=22127). The code you write should not compile because the FunctionLiteral rule does not include the UserDefinedAttributes one.
Jul 18 2021
parent Elmar <chrehme gmx.de> writes:
On Sunday, 18 July 2021 at 17:37:52 UTC, Basile B. wrote:
 On Saturday, 17 July 2021 at 16:33:54 UTC, Elmar wrote:
 Hello D people,

 I found a segmentation fault which I can reproduce with `dmd` 
 and `ldc2`.

 The attack code is simple:

 ```
 alias getOne =  (0) function int () => 1;
 ```

 It works without the UDA but segfaults with it. I found it 
 because I wanted to have user-defined attributes to the return 
 values of functions. I can't put the UDA after `function` so I 
 put it before.

 I believe, this is a forgotton corner case or something 
 because the compiler tells me, UDAs are not allowed in alias 
 definitions.
This is an assertion failure in the parser, [reported here](https://issues.dlang.org/show_bug.cgi?id=22127). The code you write should not compile because the FunctionLiteral rule does not include the UserDefinedAttributes one.
Thank you very much for clarification :-) ! I figured out UDAs are supposed to be attached to symbols only and because of compile-time staticness they can only be passed to a function via an alias-parameter but can't be passed to an op-function or constructor unfortunately. The deprecated dual-context makes it harder to pass them to methods and some other functions. Thank you for adding the report!
Jul 18 2021