Bug 24121 – ImportC: typedef enum fails to compile when generating .di file

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2023-08-30T15:05:50Z
Last change time
2023-10-27T07:44:31Z
Keywords
ImportC, pull, rejects-valid
Assigned to
Walter Bright
Creator
Adam Wilson
See also
https://issues.dlang.org/show_bug.cgi?id=22726

Comments

Comment #0 by flyboynw — 2023-08-30T15:05:50Z
The following C code causes a segfault in DMD: typedef enum { SQL_IS_YEAR = 1, SQL_IS_MONTH = 2, SQL_IS_DAY = 3, SQL_IS_HOUR = 4, SQL_IS_MINUTE = 5, SQL_IS_SECOND = 6, SQL_IS_YEAR_TO_MONTH = 7, SQL_IS_DAY_TO_HOUR = 8, SQL_IS_DAY_TO_MINUTE = 9, SQL_IS_DAY_TO_SECOND = 10, SQL_IS_HOUR_TO_MINUTE = 11, SQL_IS_HOUR_TO_SECOND = 12, SQL_IS_MINUTE_TO_SECOND = 13 } SQLINTERVAL; May be a regression of: https://issues.dlang.org/show_bug.cgi?id=22726
Comment #1 by rjmcguire — 2023-09-01T11:16:44Z
I came here to report a similar issue with typedef enums but my code now works. I tried the enum posted here and the code compiles fine for me. Do you know which version of DMD this segfault was in? I'm using linux DMD64 D Compiler v2.105.0.
Comment #2 by flyboynw — 2023-09-02T09:59:10Z
(In reply to Rory from comment #1) > I came here to report a similar issue with typedef enums but my code now > works. I tried the enum posted here and the code compiles fine for me. > > Do you know which version of DMD this segfault was in? > > I'm using linux DMD64 D Compiler v2.105.0. I am using Windows DMD64 2.105 and I just verified the segfault. The commandline used is: dmd sql.i -Hf=sql.di -verrors=0 -main If I remove the -Hf=sql.di switch then it works.
Comment #3 by bugzilla — 2023-09-12T00:29:07Z
The problem is that C code is not always representable as D code. D doesn't have anonymous enum types, for example, which I'm pretty sure is the cause of the seg fault. One reason for ImportC is it enables the D compiler to accommodate exact C semantics. The D compiler can import a C file, and use its declarations directly. If the C file was converted to a .di file, then the D compiler can import the .di file and use its declarations directly. Consequently, there should be no need to covert a C file to a .di file.
Comment #4 by bugzilla — 2023-10-25T19:26:14Z
Adam and Bruce have convinced me that there is indeed a need for C to di conversion, so I'll see about addressing this.
Comment #5 by bugzilla — 2023-10-25T22:54:25Z
Currently, the .i file: typedef enum { SQL_IS_YEAR = 1, SQL_IS_MONTH = 2 } SQLINTERVAL; produces a .di file: // D import file generated from 'test.i' extern (C) { align enum SQLINTERVAL { SQL_IS_YEAR = 1, SQL_IS_MONTH = 2, } alias SQLINTERVAL = enum SQLINTERVAL; } which is just wrong.
Comment #6 by bugzilla — 2023-10-27T01:48:09Z
*** Issue 24201 has been marked as a duplicate of this issue. ***
Comment #7 by dlang-bot — 2023-10-27T06:12:32Z
@WalterBright created dlang/dmd pull request #15736 "fix Issue 24121 - ImportC: typedef enum fails to compile when generat…" fixing this issue: - fix Issue 24121 - ImportC: typedef enum fails to compile when generating .di file https://github.com/dlang/dmd/pull/15736
Comment #8 by dlang-bot — 2023-10-27T07:44:31Z
dlang/dmd pull request #15736 "fix Issue 24121 - ImportC: typedef enum fails to compile when generat…" was merged into master: - 7a3ae70494706f49aa8b54f8752d3f2444523a41 by Walter Bright: fix Issue 24121 - ImportC: typedef enum fails to compile when generating .di file https://github.com/dlang/dmd/pull/15736