From db92f687e40c6ecf6c775c4f1df9a7d0a87a482b Mon Sep 17 00:00:00 2001 From: Tim Schendekehl Date: Sat, 8 Jun 2024 12:17:16 +0200 Subject: [PATCH] Fix bugzilla 24580 - ImportC: Asm label after attributes results in syntax error --- compiler/src/dmd/cparse.d | 28 +++++++++++++++++--------- compiler/test/compilable/testcstuff2.c | 5 +++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/compiler/src/dmd/cparse.d b/compiler/src/dmd/cparse.d index 7fbcd6d9bc1f..62882dc0fbb1 100644 --- a/compiler/src/dmd/cparse.d +++ b/compiler/src/dmd/cparse.d @@ -1872,22 +1872,30 @@ final class CParser(AST) : Parser!AST * init-declarator: * declarator simple-asm-expr (opt) gnu-attributes (opt) * declarator simple-asm-expr (opt) gnu-attributes (opt) = initializer + * + * Clang also allows simple-asm-expr after gnu-attributes. */ + while (1) + { + if (token.value == TOK.asm_) + { + asmName = cparseGnuAsmLabel(); + /* This is a data definition, there cannot now be a + * function definition. + */ + first = false; + } + else if (token.value == TOK.__attribute__) + cparseGnuAttributes(specifier); + else + break; + } + switch (token.value) { case TOK.assign: case TOK.comma: case TOK.semicolon: - case TOK.asm_: - case TOK.__attribute__: - if (token.value == TOK.asm_) - asmName = cparseGnuAsmLabel(); - if (token.value == TOK.__attribute__) - { - cparseGnuAttributes(specifier); - if (token.value == TOK.leftCurly) - break; // function definition - } /* This is a data definition, there cannot now be a * function definition. */ diff --git a/compiler/test/compilable/testcstuff2.c b/compiler/test/compilable/testcstuff2.c index 2b46bfdff8e5..9e0e1449b355 100644 --- a/compiler/test/compilable/testcstuff2.c +++ b/compiler/test/compilable/testcstuff2.c @@ -758,3 +758,8 @@ typedef enum DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO = 1, DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = 0x80000000, } DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY; + +/************************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=24580 + +int ioctl(int __fd, unsigned __request, ...) __attribute__((overloadable)) __attribute__((enable_if(1, ""))) asm("ioctl");