Bug 21918 – segfault in getParameterStorageClasses on auto function with error

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-13T10:36:06Z
Last change time
2021-05-30T03:01:44Z
Keywords
ice, ice-on-invalid-code, pull
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2021-05-13T10:36:06Z
I was testing out whether you can use getParameterStorageClasses to find out whether the compiler inferred `scope` on parameters. The answer seems to be no, and as a bonus, I stumbled on this: ``` auto yip(int f) {return T[];} pragma(msg, __traits(getParameterStorageClasses, yip, 0)); ``` Output: test.d(1): Error: undefined identifier `T` [1] 9590 segmentation fault dmd -o- test.d
Comment #1 by dlang-bot — 2021-05-13T14:47:18Z
@MoonlightSentinel created dlang/dmd pull request #12517 "Fix 21918 - Segfault for getParameterStorageClasses for invalid funct…" fixing this issue: - Fix 21918 - Segfault for getParameterStorageClasses for invalid functions The type of a `FuncDeclaration` is set to `TypeError` if the `auto` inference fails. So `getParameters` has to check that the type is actually a `TypeFunction`. The additional check in `traits.d` prevents the invalid error message: ``` Error: parameter index must be in range 0..0 not 0 ``` https://github.com/dlang/dmd/pull/12517
Comment #2 by dlang-bot — 2021-05-14T01:04:33Z
dlang/dmd pull request #12517 "Fix 21918 - Segfault for getParameterStorageClasses for invalid funct…" was merged into stable: - 261f701c0c4dd3ba1f208b026c875adb8ef2581c by MoonlightSentinel: Fix 21918 - Segfault for getParameterStorageClasses for invalid functions The type of a `FuncDeclaration` is set to `TypeError` if the `auto` inference fails. So `getParameters` has to check that the type is actually a `TypeFunction`. The additional check in `traits.d` prevents the invalid error message: ``` Error: parameter index must be in range 0..0 not 0 ``` https://github.com/dlang/dmd/pull/12517
Comment #3 by dlang-bot — 2021-05-30T03:01:44Z
dlang/dmd pull request #12600 "merge stable" was merged into master: - 3b02dc18411a49bd5e9ec43892bec61d4ec0a51c by MoonlightSentinel: Fix 21918 - Segfault for getParameterStorageClasses for invalid functions The type of a `FuncDeclaration` is set to `TypeError` if the `auto` inference fails. So `getParameters` has to check that the type is actually a `TypeFunction`. The additional check in `traits.d` prevents the invalid error message: ``` Error: parameter index must be in range 0..0 not 0 ``` https://github.com/dlang/dmd/pull/12600