Skip to content

Commit

Permalink
fix issue 24509
Browse files Browse the repository at this point in the history
  • Loading branch information
aferust committed Apr 16, 2024
1 parent 9a86c4e commit 23e78ae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
12 changes: 8 additions & 4 deletions compiler/src/dmd/cparse.d
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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_:
Expand Down
11 changes: 6 additions & 5 deletions compiler/src/dmd/frontend.h
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dmd/tokens.d
Expand Up @@ -275,6 +275,7 @@ enum TOK : ubyte
_import,
__cdecl,
__declspec,
_stdcall,
__stdcall,
__thread,
__pragma,
Expand Down Expand Up @@ -582,6 +583,7 @@ private immutable TOK[] keywords =
TOK._import,
TOK.__cdecl,
TOK.__declspec,
TOK._stdcall,
TOK.__stdcall,
TOK.__thread,
TOK.__pragma,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion compiler/test/compilable/test22727.c
Expand Up @@ -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;
1 change: 1 addition & 0 deletions compiler/test/unit/lexer/location_offset.d
Expand Up @@ -543,6 +543,7 @@ enum ignoreTokens
_import,
__cdecl,
__declspec,
_stdcall,
__stdcall,
__thread,
__pragma,
Expand Down

0 comments on commit 23e78ae

Please sign in to comment.