From 23e78aedb75931a27089ea1912d5fd56dd2d0c50 Mon Sep 17 00:00:00 2001 From: aferust Date: Wed, 17 Apr 2024 00:31:16 +0300 Subject: [PATCH] fix issue 24509 --- compiler/src/dmd/cparse.d | 12 ++++++++---- compiler/src/dmd/frontend.h | 11 ++++++----- compiler/src/dmd/tokens.d | 5 ++++- compiler/test/compilable/test22727.c | 3 ++- compiler/test/unit/lexer/location_offset.d | 1 + 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/compiler/src/dmd/cparse.d b/compiler/src/dmd/cparse.d index a7e1ecf96079..1c01c59d1550 100644 --- a/compiler/src/dmd/cparse.d +++ b/compiler/src/dmd/cparse.d @@ -339,6 +339,7 @@ final class CParser(AST) : Parser!AST case TOK.volatile: case TOK.restrict: case TOK.__stdcall: + case TOK._stdcall: // alignment-specifier case TOK._Alignas: @@ -2401,7 +2402,7 @@ final class CParser(AST) : Parser!AST case TOK.const_: modx = MOD.xconst; break; case TOK.volatile: modx = MOD.xvolatile; break; case TOK.restrict: modx = MOD.xrestrict; break; - case TOK.__stdcall: modx = MOD.x__stdcall; break; + case TOK.__stdcall: case TOK._stdcall: modx = MOD.x__stdcall; break; // Type specifiers case TOK.char_: tkwx = TKW.xchar; break; @@ -2859,7 +2860,7 @@ final class CParser(AST) : Parser!AST } nextToken(); - if (token.value == TOK.__stdcall) // T (__stdcall*fp)(); + if (token.value == TOK.__stdcall || token.value == TOK._stdcall) // T (__stdcall*fp)(); { specifier.mod |= MOD.x__stdcall; nextToken(); @@ -3092,7 +3093,7 @@ final class CParser(AST) : Parser!AST case TOK.volatile: mod |= MOD.xvolatile; break; case TOK.restrict: mod |= MOD.xrestrict; break; case TOK._Atomic: mod |= MOD.x_Atomic; break; - case TOK.__stdcall: mod |= MOD.x__stdcall; break; + case TOK.__stdcall: case TOK._stdcall: mod |= MOD.x__stdcall; break; default: return mod; @@ -4476,6 +4477,7 @@ final class CParser(AST) : Parser!AST case TOK.volatile: case TOK.restrict: case TOK.__stdcall: + case TOK._stdcall: t = peek(t); any = true; continue; @@ -4668,7 +4670,7 @@ final class CParser(AST) : Parser!AST else if (t.value == TOK.leftParenthesis) { t = peek(t); - if (t.value == TOK.__stdcall) + if (t.value == TOK.__stdcall || t.value == TOK._stdcall) t = peek(t); if (!isCDeclarator(t, declarator)) return false; @@ -4720,6 +4722,7 @@ final class CParser(AST) : Parser!AST case TOK.volatile: case TOK._Atomic: case TOK.__stdcall: + case TOK._stdcall: t = peek(t); continue; @@ -4773,6 +4776,7 @@ final class CParser(AST) : Parser!AST case TOK.restrict: case TOK.volatile: case TOK.__stdcall: + case TOK._stdcall: // Type Specifiers case TOK.char_: diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index c4394042077b..e22a84e55cf4 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -2913,11 +2913,12 @@ enum class TOK : uint8_t _import_ = 218u, __cdecl_ = 219u, __declspec_ = 220u, - __stdcall_ = 221u, - __thread_ = 222u, - __pragma_ = 223u, - __int128_ = 224u, - __attribute___ = 225u, + _stdcall_ = 221u, + __stdcall_ = 222u, + __thread_ = 223u, + __pragma_ = 224u, + __int128_ = 225u, + __attribute___ = 226u, }; class FuncExp final : public Expression diff --git a/compiler/src/dmd/tokens.d b/compiler/src/dmd/tokens.d index da4a3ee209ef..03e9feda606b 100644 --- a/compiler/src/dmd/tokens.d +++ b/compiler/src/dmd/tokens.d @@ -275,6 +275,7 @@ enum TOK : ubyte _import, __cdecl, __declspec, + _stdcall, __stdcall, __thread, __pragma, @@ -582,6 +583,7 @@ private immutable TOK[] keywords = TOK._import, TOK.__cdecl, TOK.__declspec, + TOK._stdcall, TOK.__stdcall, TOK.__thread, TOK.__pragma, @@ -615,7 +617,7 @@ static immutable TOK[TOK.max + 1] Ckeywords = union_, unsigned, void_, volatile, while_, asm_, typeof_, _Alignas, _Alignof, _Atomic, _Bool, _Complex, _Generic, _Imaginary, _Noreturn, _Static_assert, _Thread_local, - _import, __cdecl, __declspec, __stdcall, __thread, __pragma, __int128, __attribute__, + _import, __cdecl, __declspec, _stdcall, __stdcall, __thread, __pragma, __int128, __attribute__, _assert ]; foreach (kw; Ckwds) @@ -896,6 +898,7 @@ extern (C++) struct Token TOK._import : "__import", TOK.__cdecl : "__cdecl", TOK.__declspec : "__declspec", + TOK._stdcall : "_stdcall", TOK.__stdcall : "__stdcall", TOK.__thread : "__thread", TOK.__pragma : "__pragma", diff --git a/compiler/test/compilable/test22727.c b/compiler/test/compilable/test22727.c index 8ff5d6fed9af..e24c5722c36b 100644 --- a/compiler/test/compilable/test22727.c +++ b/compiler/test/compilable/test22727.c @@ -3,9 +3,10 @@ int fooc(int a) { return a; } __stdcall int foostdcall(int a) { return a; } +_stdcall int _foostdcall(int a) { return a; } // test issue 24509 int __stdcall foostdcall2(int a) { return a; } int __stdcall (*fp1)(int a) = &foostdcall; -int (__stdcall *fp2)(int a) = &foostdcall2; +int(__stdcall *fp2)(int a) = &foostdcall2; diff --git a/compiler/test/unit/lexer/location_offset.d b/compiler/test/unit/lexer/location_offset.d index 21266276d2c3..cad53b748ebc 100644 --- a/compiler/test/unit/lexer/location_offset.d +++ b/compiler/test/unit/lexer/location_offset.d @@ -543,6 +543,7 @@ enum ignoreTokens _import, __cdecl, __declspec, + _stdcall, __stdcall, __thread, __pragma,