From 5261facbd70ba4be6da3931c2a15942faa59d0ef Mon Sep 17 00:00:00 2001 From: Russell Joyce Date: Fri, 12 Jun 2020 15:30:32 +0100 Subject: [PATCH] Fixed bug with typedef, introduced with extra type qualifier parsing Caused by overwriting the value of the actual type token being parsed by any following tokens that were examined or consumed, rather than just ignoring their values. --- c-tests/types.c | 3 +++ type.c | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/c-tests/types.c b/c-tests/types.c index 353a95f..eda768f 100644 --- a/c-tests/types.c +++ b/c-tests/types.c @@ -14,6 +14,9 @@ int volatile static j; const int x; long const y; +typedef int MyInt; +MyInt z = 1; + int main(void) { return 0; } diff --git a/type.c b/type.c index d9cc0d3..b6fedd2 100644 --- a/type.c +++ b/type.c @@ -421,7 +421,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, } /* handle any trailing type qualifiers/storage classes */ - enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false); + enum LexToken FollowToken = LexGetToken(Parser, NULL, false); while (FollowToken == TokenStaticType || FollowToken == TokenAutoType || FollowToken == TokenRegisterType || FollowToken == TokenExternType || FollowToken == TokenVolatileType || FollowToken == TokenConstType) { @@ -430,8 +430,8 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, else if (FollowToken == TokenVolatileType) VolatileQualifier = true; - LexGetToken(Parser, &LexerValue, true); - FollowToken = LexGetToken(Parser, &LexerValue, false); + LexGetToken(Parser, NULL, true); + FollowToken = LexGetToken(Parser, NULL, false); } if (IsStatic != NULL) @@ -441,7 +441,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, /* handle signed/unsigned with no trailing type */ if (Token == TokenSignedType || Token == TokenUnsignedType) { - enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false); + enum LexToken FollowToken = LexGetToken(Parser, NULL, false); Unsigned = (Token == TokenUnsignedType); if (FollowToken != TokenIntType && FollowToken != TokenLongType && @@ -459,9 +459,9 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, /* handle long with trailing int by consuming and ignoring the int */ if (Token == TokenLongType) { - enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false); + enum LexToken FollowToken = LexGetToken(Parser, NULL, false); if (FollowToken == TokenIntType) { - LexGetToken(Parser, &LexerValue, true); + LexGetToken(Parser, NULL, true); } }