[svn:parrot] r43532 - in trunk: compilers/imcc t/compilers/imcc/syn
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Fri Jan 22 07:31:55 UTC 2010
Author: chromatic
Date: Fri Jan 22 07:31:52 2010
New Revision: 43532
URL: https://trac.parrot.org/parrot/changeset/43532
Log:
[IMCC] Forbade use of relative macro labels in PIR (in IMCC anyway). This
fixes the segfault reported by Will Coleda in TT #902. His test case is now a
test.
Modified:
trunk/compilers/imcc/imcc.l
trunk/compilers/imcc/imclexer.c
trunk/t/compilers/imcc/syn/macro.t
Modified: trunk/compilers/imcc/imcc.l
==============================================================================
--- trunk/compilers/imcc/imcc.l Thu Jan 21 20:30:00 2010 (r43531)
+++ trunk/compilers/imcc/imcc.l Fri Jan 22 07:31:52 2010 (r43532)
@@ -718,8 +718,16 @@
}
<macro>".$"{ID} {
- if (valp) {
- const size_t len = strlen(IMCC_INFO(interp)->cur_macro_name) + yyleng + 12;
+ if (valp) {
+ if (!IMCC_INFO(interp)->cur_macro_name) {
+ if (valp->s)
+ mem_sys_free(valp->s);
+ IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
+ "Invalid LABEL outside of macro");
+ }
+ else {
+ const size_t len = strlen(IMCC_INFO(interp)->cur_macro_name)
+ + yyleng + 12;
char * const label = (char *)mem_sys_allocate(len);
snprintf(label, len, "local__%s__%s__$",
@@ -729,10 +737,11 @@
mem_sys_free(valp->s);
valp->s = label;
}
-
- return IDENTIFIER;
}
+ return IDENTIFIER;
+}
+
<macro>^{WS}+ /* skip leading ws */;
<macro>{WS}+ DUP_AND_RET(valp, ' ');
<macro>[SNIP]{DIGITS} DUP_AND_RET(valp, REG);
@@ -1139,7 +1148,7 @@
m = find_macro(interp, name);
if (m) {
- int i,c,start_cond;
+ int i, c, start_cond;
macro_frame_t * frame = new_frame(interp);
frame->params = &m->params;
Modified: trunk/compilers/imcc/imclexer.c
==============================================================================
--- trunk/compilers/imcc/imclexer.c Thu Jan 21 20:30:00 2010 (r43531)
+++ trunk/compilers/imcc/imclexer.c Fri Jan 22 07:31:52 2010 (r43532)
@@ -3901,8 +3901,16 @@
YY_RULE_SETUP
#line 720 "compilers/imcc/imcc.l"
{
- if (valp) {
- const size_t len = strlen(IMCC_INFO(interp)->cur_macro_name) + yyleng + 12;
+ if (valp) {
+ if (!IMCC_INFO(interp)->cur_macro_name) {
+ if (valp->s)
+ mem_sys_free(valp->s);
+ IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR,
+ "Invalid LABEL outside of macro");
+ }
+ else {
+ const size_t len = strlen(IMCC_INFO(interp)->cur_macro_name)
+ + yyleng + 12;
char * const label = (char *)mem_sys_allocate(len);
snprintf(label, len, "local__%s__%s__$",
@@ -3912,55 +3920,56 @@
mem_sys_free(valp->s);
valp->s = label;
}
-
- return IDENTIFIER;
}
+
+ return IDENTIFIER;
+}
YY_BREAK
case 141:
YY_RULE_SETUP
-#line 736 "compilers/imcc/imcc.l"
+#line 745 "compilers/imcc/imcc.l"
/* skip leading ws */;
YY_BREAK
case 142:
YY_RULE_SETUP
-#line 737 "compilers/imcc/imcc.l"
+#line 746 "compilers/imcc/imcc.l"
DUP_AND_RET(valp, ' ');
YY_BREAK
case 143:
YY_RULE_SETUP
-#line 738 "compilers/imcc/imcc.l"
+#line 747 "compilers/imcc/imcc.l"
DUP_AND_RET(valp, REG);
YY_BREAK
case 144:
YY_RULE_SETUP
-#line 739 "compilers/imcc/imcc.l"
+#line 748 "compilers/imcc/imcc.l"
DUP_AND_RET(valp, REG);
YY_BREAK
case 145:
YY_RULE_SETUP
-#line 740 "compilers/imcc/imcc.l"
+#line 749 "compilers/imcc/imcc.l"
DUP_AND_RET(valp, IDENTIFIER);
YY_BREAK
case 146:
YY_RULE_SETUP
-#line 741 "compilers/imcc/imcc.l"
+#line 750 "compilers/imcc/imcc.l"
DUP_AND_RET(valp, MACRO);
YY_BREAK
case 147:
YY_RULE_SETUP
-#line 742 "compilers/imcc/imcc.l"
+#line 751 "compilers/imcc/imcc.l"
DUP_AND_RET(valp, yytext[0]);
YY_BREAK
case YY_STATE_EOF(macro):
-#line 743 "compilers/imcc/imcc.l"
+#line 752 "compilers/imcc/imcc.l"
yyterminate();
YY_BREAK
case 148:
YY_RULE_SETUP
-#line 745 "compilers/imcc/imcc.l"
+#line 754 "compilers/imcc/imcc.l"
ECHO;
YY_BREAK
-#line 3964 "compilers/imcc/imclexer.c"
+#line 3973 "compilers/imcc/imclexer.c"
case YY_STATE_EOF(pod):
case YY_STATE_EOF(cmt1):
case YY_STATE_EOF(cmt2):
@@ -5162,7 +5171,7 @@
#define YYTABLES_NAME "yytables"
-#line 745 "compilers/imcc/imcc.l"
+#line 754 "compilers/imcc/imcc.l"
@@ -5561,7 +5570,7 @@
m = find_macro(interp, name);
if (m) {
- int i,c,start_cond;
+ int i, c, start_cond;
macro_frame_t * frame = new_frame(interp);
frame->params = &m->params;
Modified: trunk/t/compilers/imcc/syn/macro.t
==============================================================================
--- trunk/t/compilers/imcc/syn/macro.t Thu Jan 21 20:30:00 2010 (r43531)
+++ trunk/t/compilers/imcc/syn/macro.t Fri Jan 22 07:31:52 2010 (r43532)
@@ -1,5 +1,5 @@
#!perl
-# Copyright (C) 2001-2009, Parrot Foundation.
+# Copyright (C) 2001-2010, Parrot Foundation.
# $Id$
use strict;
@@ -8,7 +8,7 @@
use Test::More;
use Parrot::Config;
-use Parrot::Test tests => 41;
+use Parrot::Test tests => 42;
# macro tests
@@ -585,6 +585,27 @@
my_func_2 my_func_2
OUTPUT
+pir_error_output_like( <<'CODE', <<'OUTPUT', 'macro label outside of macro declaration (TT #902)' );
+.macro While(conditional, code)
+
+.label $beginwhile:
+ unless .conditional goto .$endwhile
+ .code
+ goto .$beginwhile
+.label $endwhile:
+.endm
+
+.sub main
+.While($I0 < 3, {
+say $I0
+goto .$endwhile
+inc $I0
+})
+.end
+CODE
+/Invalid LABEL outside of macro/
+OUTPUT
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
More information about the parrot-commits
mailing list