Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asm and std=c99 incompatibility #20012

Closed
danielclarke opened this issue Jul 12, 2022 · 1 comment
Closed

asm and std=c99 incompatibility #20012

danielclarke opened this issue Jul 12, 2022 · 1 comment

Comments

@danielclarke
Copy link
Contributor

danielclarke commented Jul 12, 2022

Calls to extended asm fail to compile with gcc when std=c99 compiler flag is set

Example

{.passC: "-std=c99".}

proc main =
  let src = 41
  var dst = 0

  asm """
    mov %1, %0\n\t
    add $1, %0
    : "=r" (`dst`)
    : "r" (`src`)"""

  echo dst

main()

Current Output

mtest.nim.c:104:5: error: expected ')'
    : "=r" (dst)
    ^
mtest.nim.c:102:5: note: to match this '('
        asm("    mov %1, %0\n\t\n"
           ^
1 error generated.

Expected Output

42

Possible Solution

I have a PR with the following change and a test, however this definitely feels out of my depth

In extccomp.nim, under compiler gcc:, replace

asmStmtFrmt: "asm($1);$n",

with

asmStmtFrmt: "__asm__($1);$n",
$ nim -v

Nim Compiler Version 1.7.1 [MacOSX: amd64]
Compiled at 2022-07-10
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: e8ee2f9c2ad06cad2f62fe7505acbb43530f28d7
@danielclarke
Copy link
Contributor Author

PR here: #20013

FedericoCeratto pushed a commit to FedericoCeratto/Nim that referenced this issue Jul 30, 2022
* replace gcc asm with __asm__ and add a test

* update test case to specify gcc or clang and not cpp

Co-authored-by: daniel <danielclarke@wearepopgun.com>
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
* replace gcc asm with __asm__ and add a test

* update test case to specify gcc or clang and not cpp

Co-authored-by: daniel <danielclarke@wearepopgun.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant