Bug 24291 – ImportC: support computed goto

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-12-21T00:30:23Z
Last change time
2024-12-13T19:32:14Z
Assigned to
No Owner
Creator
mw
Moved to GitHub: dmd#20371 →

Comments

Comment #0 by mingwu — 2023-12-21T00:30:23Z
https://github.com/janet-lang/janet/releases/download/v1.32.1/janet.c https://github.com/janet-lang/janet/releases/download/v1.32.1/janet.h https://github.com/janet-lang/janet/releases/download/v1.32.1/shell.c $ dmd --version DMD64 D Compiler v2.106.0-beta.1 Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved written by Walter Bright $ dmd -P-I. -c janet.c src/core/vm.c(342): Error: expression expected, not `&&` src/core/vm.c(342): Error: found `label_JOP_NOOP` when expecting `}` src/core/vm.c(343): Error: identifier or `(` expected src/core/vm.c(597): Error: `=`, `;` or `,` expected to end declaration instead of `}` src/core/vm.c(643): Error: identifier expected following `goto` src/core/vm.c(643): Error: found `*` when expecting `;` following `goto` statement src/core/vm.c(650): Error: identifier expected following `goto` src/core/vm.c(650): Error: found `*` when expecting `;` following `goto` statement src/core/vm.c(657): Error: identifier expected following `goto` src/core/vm.c(657): Error: found `*` when expecting `;` following `goto` statement src/core/vm.c(666): Error: identifier expected following `goto` src/core/vm.c(666): Error: found `*` when expecting `;` following `goto` statement src/core/vm.c(676): Error: identifier expected following `goto` src/core/vm.c(676): Error: found `*` when expecting `;` following `goto` statement src/core/vm.c(680): Error: identifier expected following `goto` src/core/vm.c(680): Error: found `*` when expecting `;` following `goto` statement src/core/vm.c(680): Error: identifier expected following `goto` src/core/vm.c(680): Error: found `*` when expecting `;` following `goto` statement src/core/vm.c(683): Error: identifier expected following `goto` src/core/vm.c(683): Error: found `*` when expecting `;` following `goto` statement $ dmd -P-I. -c shell.c shell.c(657): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(657): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(659): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(681): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(681): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(681): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(681): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(681): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(764): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(778): Error: undefined identifier `isnan`, did you mean function `nan`? shell.c(780): Error: undefined identifier `isnan`, did you mean function `nan`?
Comment #1 by bugzilla — 2023-12-24T06:49:38Z
Can you please try reducing this to the offending few lines of code? I don't have src/core/vm.c, and probably not exactly the same .h files you're using, either.
Comment #2 by dfj1esp02 — 2023-12-25T14:20:56Z
From forum discussion: --- One Problem with Janet is that it uses computed gotos which is a gcc extension The code it complains about looks like: ```C /* opcode -> label lookup if using clang/GCC */ #ifdef JANET_USE_COMPUTED_GOTOS static void *op_lookup[255] = { &&label_JOP_NOOP, &&label_JOP_ERROR, ``` As you can see &&label is not valid C11. Which is what the import C parser complains about. --- Maybe something can be done there with that JANET_USE_COMPUTED_GOTOS define.
Comment #3 by dfj1esp02 — 2023-12-25T14:43:38Z
clang provides __has_extension function for such checks, but doesn't document computed gotos.
Comment #4 by bugzilla — 2023-12-27T20:05:13Z
If you can post the definition of JANET_USE_COMPUTED_GOTOS we can see about making it evaluate to false.
Comment #5 by wyrlon — 2023-12-27T21:23:14Z
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) #define JANET_USE_COMPUTED_GOTOS #endif
Comment #6 by dfj1esp02 — 2023-12-29T11:09:23Z
Oh, __GNUC__ means gnu C dialect? --- cjanet.c --- #undef __GNUC__ #include "janet.c" --- dmd -P-I. -c cjanet.c Does this work?
Comment #7 by bugzilla — 2023-12-30T04:47:28Z
(In reply to Daniel from comment #5) > #if defined(__GNUC__) && !defined(__EMSCRIPTEN__) > #define JANET_USE_COMPUTED_GOTOS > #endif Unfortunately, if dmd #define'd __EMSCRIPTEN__ it would likely turn on some other nutburger extensions ImportC doesn't support. importc.h cannot #undef JANET_USE_COMPUTED_GOTOS because importc.h is #include'd first. Turning off __GNUC__ will cause all kinds of other problems.
Comment #8 by bugzilla — 2023-12-30T05:20:10Z
I'm going to leave this as an enhancement request for computed goto. If there are other ImportC problems with janet, please post a bugzilla issue about it! https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
Comment #9 by bugzilla — 2023-12-30T05:29:35Z
At least I can get you a better error message: https://github.com/dlang/dmd/pull/15967
Comment #10 by robert.schadek — 2024-12-13T19:32:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20371 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB