Merge pull request #437 from rednex/locals

Prevent local symbols that are not labels
This commit is contained in:
Eldred Habert
2020-02-26 02:56:35 +01:00
committed by GitHub
5 changed files with 46 additions and 20 deletions

View File

@@ -551,7 +551,12 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
%left NEG /* negation -- unary minus */ %left NEG /* negation -- unary minus */
%token <tzSym> T_LABEL %token <tzSym> T_LABEL
%token <tzSym> T_LOCAL_LABEL
%type <tzSym> scoped_label
%type <tzSym> scoped_label_bare
%token <tzSym> T_ID %token <tzSym> T_ID
%token <tzSym> T_LOCAL_ID
%type <tzSym> scoped_id
%token <tzSym> T_POP_EQU %token <tzSym> T_POP_EQU
%token <tzSym> T_POP_SET %token <tzSym> T_POP_SET
%token <tzSym> T_POP_EQUAL %token <tzSym> T_POP_EQUAL
@@ -654,22 +659,34 @@ line : label
| pseudoop | pseudoop
; ;
scoped_label_bare : T_LABEL | T_LOCAL_LABEL ;
scoped_label : T_LABEL ':'
{
strcpy($$, $1);
}
| T_LOCAL_LABEL ':'
{
strcpy($$, $1);
}
;
scoped_id : T_ID | T_LOCAL_ID ;
label : /* empty */ label : /* empty */
| T_LABEL | scoped_label_bare
{ {
if ($1[0] == '.') if ($1[0] == '.')
sym_AddLocalReloc($1); sym_AddLocalReloc($1);
else else
sym_AddReloc($1); sym_AddReloc($1);
} }
| T_LABEL ':' | scoped_label
{ {
if ($1[0] == '.') if ($1[0] == '.')
sym_AddLocalReloc($1); sym_AddLocalReloc($1);
else else
sym_AddReloc($1); sym_AddReloc($1);
} }
| T_LABEL ':' ':' | scoped_label ':'
{ {
if ($1[0] == '.') if ($1[0] == '.')
sym_AddLocalReloc($1); sym_AddLocalReloc($1);
@@ -925,7 +942,7 @@ purge_list : purge_list_entry
| purge_list_entry comma purge_list | purge_list_entry comma purge_list
; ;
purge_list_entry : T_ID purge_list_entry : scoped_id
{ {
sym_Purge($1); sym_Purge($1);
} }
@@ -938,7 +955,7 @@ import_list : import_list_entry
| import_list_entry comma import_list | import_list_entry comma import_list
; ;
import_list_entry : T_ID import_list_entry : scoped_id
{ {
/* /*
* This is done automatically if the label isn't found * This is done automatically if the label isn't found
@@ -955,7 +972,7 @@ export_list : export_list_entry
| export_list_entry comma export_list | export_list_entry comma export_list
; ;
export_list_entry : T_ID export_list_entry : scoped_id
{ {
sym_Export($1); sym_Export($1);
} }
@@ -968,7 +985,7 @@ global_list : global_list_entry
| global_list_entry comma global_list | global_list_entry comma global_list
; ;
global_list_entry : T_ID global_list_entry : scoped_id
{ {
sym_Export($1); sym_Export($1);
} }
@@ -1233,7 +1250,7 @@ relocexpr : relocexpr_no_str
} }
; ;
relocexpr_no_str : T_ID relocexpr_no_str : scoped_id
{ {
rpn_Symbol(&$$, $1); rpn_Symbol(&$$, $1);
} }
@@ -1265,7 +1282,7 @@ relocexpr_no_str : T_ID
| T_OP_NOT relocexpr %prec NEG { rpn_UNNOT(&$$, &$2); } | T_OP_NOT relocexpr %prec NEG { rpn_UNNOT(&$$, &$2); }
| T_OP_HIGH '(' relocexpr ')' { rpn_HIGH(&$$, &$3); } | T_OP_HIGH '(' relocexpr ')' { rpn_HIGH(&$$, &$3); }
| T_OP_LOW '(' relocexpr ')' { rpn_LOW(&$$, &$3); } | T_OP_LOW '(' relocexpr ')' { rpn_LOW(&$$, &$3); }
| T_OP_BANK '(' T_ID ')' | T_OP_BANK '(' scoped_id ')'
{ {
/* '@' is also a T_ID, it is handled here. */ /* '@' is also a T_ID, it is handled here. */
rpn_BankSymbol(&$$, $3); rpn_BankSymbol(&$$, $3);
@@ -1276,7 +1293,7 @@ relocexpr_no_str : T_ID
} }
| T_OP_DEF { | T_OP_DEF {
oDontExpandStrings = true; oDontExpandStrings = true;
} '(' T_ID ')' } '(' scoped_id ')'
{ {
struct sSymbol const *sym = sym_FindSymbol($4); struct sSymbol const *sym = sym_FindSymbol($4);
if (sym && !(sym_IsDefined(sym) && sym->type != SYM_LABEL)) if (sym && !(sym_IsDefined(sym) && sym->type != SYM_LABEL))

View File

@@ -913,10 +913,18 @@ scanagain:
goto scanagain; goto scanagain;
} }
if (token->nToken == T_ID && linestart) uint32_t type = token->nToken;
if (type == T_ID && strchr(yylval.tzSym, '.'))
type = T_LOCAL_ID;
if (linestart) {
if (type == T_ID)
return T_LABEL; return T_LABEL;
else if (type == T_LOCAL_ID)
return token->nToken; return T_LOCAL_LABEL;
}
return type;
} }
/* Longest match was a keyword or operator. */ /* Longest match was a keyword or operator. */

View File

@@ -40,6 +40,6 @@ ENDM
test_char _ test_char _
test_char @ test_char @
test_char # test_char #
test_char .
test_char .
test_char : test_char :

View File

@@ -1,5 +1,7 @@
ERROR: label-macro-arg.asm(45) -> label-macro-arg.asm::test_char(31): ERROR: label-macro-arg.asm(44) -> label-macro-arg.asm::test_char(31):
Label "sizeof_" created outside of a SECTION Local label in main scope
while expanding symbol "VAR_DEF" while expanding symbol "VAR_DEF"
ERROR: label-macro-arg.asm(45) -> label-macro-arg.asm::test_char(31): ERROR: label-macro-arg.asm(44) -> label-macro-arg.asm::test_char(31):
Macro 'something' not defined syntax error
while expanding symbol "VAR_DEF"
error: Assembly aborted (2 errors)!

View File

@@ -5,4 +5,3 @@ $8
sizeof__something equals $1 sizeof__something equals $1
sizeof_@something equals $1 sizeof_@something equals $1
sizeof_#something equals $1 sizeof_#something equals $1
sizeof_.something equals $1