Thread overview
importC: __asm volatile parsing failure - issue or not?
March 31

In fact, this is my first time using importC, so maybe I messed something up

This is real piece of FreeRTOS header. It contains ARM assembler instruction and attended to use with GCC:

$ cat test.h
__attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
{
    uint8_t ucReturn;

    __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

    return ucReturn;
}

Preprocessing this C header:

$ arm-none-eabi-gcc -std=c11 -E test.h -o test_gcc.i
$ cat test_gcc.i
# 0 "test.h"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "test.h"
__attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
{
    uint8_t ucReturn;

    __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

    return ucReturn;
}

Trying to use it from D:

$ dmd test_gcc.i -Hf=test.di
test.h(5): Error: found `volatile` when expecting `;` following statement
test.h(5): Error: found `:` when expecting `)`
test.h(5): Error: found `"=r"` when expecting `;` following statement
test.h(5): Error: found `:` when expecting `;` following statement
test.h(5): Error: found `"r"` instead of statement

$ dmd --version
DMD64 D Compiler v2.107.1
Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved written by Walter Bright
$ ldc2 --mtriple=thumbv7em-unknown-none-eabi test_gcc.i -Hf=test.di
test.h(5): Error: found `volatile` when expecting `;` following statement
test.h(5): Error: found `:` when expecting `)`
test.h(5): Error: found `"=r"` when expecting `;` following statement
test.h(5): Error: found `:` when expecting `;` following statement
test.h(5): Error: found `"r"` instead of statement

$ ldc2 --version
LDC - the LLVM D compiler (1.37.0):
  based on DMD v2.107.1 and LLVM 17.0.6
  built with LDC - the LLVM D compiler (1.37.0)

Something went wrong with "__asm volatile" syntax?

March 31

On Sunday, 31 March 2024 at 08:42:55 UTC, Denis Feklushkin wrote:

>
    __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ```

Tried to replace (non-standard?) __asm by __asm__ - nothing changed

March 31

On Sunday, 31 March 2024 at 09:35:01 UTC, Denis Feklushkin wrote:

>

On Sunday, 31 March 2024 at 08:42:55 UTC, Denis Feklushkin wrote:

>
    __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ```

Tried to replace (non-standard?) __asm by __asm__ - nothing changed

"asm volatile" works as expected, but "asm" isn't C11 keyword

March 31
On 3/31/2024 2:38 AM, Denis Feklushkin wrote:
> "asm volatile" works as expected, but "asm" isn't C11 keyword

"asm" is a C11 keyword, see C11.j.5.10

dmd doesn't support the gcc asm syntax, only the Microsoft & Digital Mars syntaxes.

Usually, in header files with asm syntax, it can be disabled with an #ifdef.
April 01
On Monday, 1 April 2024 at 00:18:15 UTC, Walter Bright wrote:
> On 3/31/2024 2:38 AM, Denis Feklushkin wrote:
>> "asm volatile" works as expected, but "asm" isn't C11 keyword
>
> "asm" is a C11 keyword, see C11.j.5.10

Really! I just got confused
Thank you!

> dmd doesn't support the gcc asm syntax, only the Microsoft & Digital Mars syntaxes.
>
> Usually, in header files with asm syntax, it can be disabled with an #ifdef.

This is just the opposite case: FreeRTOS code is full of asm entries which isn't be able to disabled. But, preliminarily, a simple mass replacement to "asm volatile" works for me
April 17
On Monday, 1 April 2024 at 18:02:33 UTC, Denis Feklushkin wrote:
> On Monday, 1 April 2024 at 00:18:15 UTC, Walter Bright wrote:
>> On 3/31/2024 2:38 AM, Denis Feklushkin wrote:
>>> "asm volatile" works as expected, but "asm" isn't C11 keyword
>>
>> "asm" is a C11 keyword, see C11.j.5.10
>
> Really! I just got confused
> Thank you!
>
>> dmd doesn't support the gcc asm syntax, only the Microsoft & Digital Mars syntaxes.
>>
>> Usually, in header files with asm syntax, it can be disabled with an #ifdef.
>
> This is just the opposite case: FreeRTOS code is full of asm entries which isn't be able to disabled. But, preliminarily, a simple mass replacement to "asm volatile" works for me

Fixed in this PR: https://github.com/dlang/dmd/pull/16386
Please review!