Commit 4a9b08d5 by Nicolas Capens

Fix compiler crash.

Create a fake variable for function identifiers used as a variable identifier to allow continuing compilation after reporting the error. BUG=chromium:330222 Change-Id: I553804b3db95cd5dc946e94193fc9181d6b2c032 Reviewed-on: https://chromium-review.googlesource.com/180977Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarNicolas Capens <nicolascapens@chromium.org>
parent 98925f4d
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 2 #define MINOR_VERSION 2
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 2452 #define BUILD_REVISION 2453
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -183,43 +183,55 @@ identifier ...@@ -183,43 +183,55 @@ identifier
variable_identifier variable_identifier
: IDENTIFIER { : IDENTIFIER {
// The symbol table search was done in the lexical phase // The symbol table search was done in the lexical phase
const TSymbol* symbol = $1.symbol; const TSymbol *symbol = $1.symbol;
const TVariable* variable; const TVariable *variable = 0;
if (symbol == 0) {
if (!symbol)
{
context->error(@1, "undeclared identifier", $1.string->c_str()); context->error(@1, "undeclared identifier", $1.string->c_str());
context->recover(); context->recover();
TType type(EbtFloat, EbpUndefined); }
TVariable* fakeVariable = new TVariable($1.string, type); else if (!symbol->isVariable())
context->symbolTable.insert(*fakeVariable); {
variable = fakeVariable; context->error(@1, "variable expected", $1.string->c_str());
} else { context->recover();
// This identifier can only be a variable type symbol }
if (! symbol->isVariable()) { else
context->error(@1, "variable expected", $1.string->c_str()); {
context->recover();
}
variable = static_cast<const TVariable*>(symbol); variable = static_cast<const TVariable*>(symbol);
if (context->symbolTable.findBuiltIn(variable->getName()) && if (context->symbolTable.findBuiltIn(variable->getName()) &&
!variable->getExtension().empty() && !variable->getExtension().empty() &&
context->extensionErrorCheck(@1, variable->getExtension())) { context->extensionErrorCheck(@1, variable->getExtension()))
{
context->recover(); context->recover();
} }
} }
// don't delete $1.string, it's used by error recovery, and the pool if (!variable)
// pop will reclaim the memory {
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable($1.string, type);
context->symbolTable.insert(*fakeVariable);
variable = fakeVariable;
}
if (variable->getType().getQualifier() == EvqConst ) { if (variable->getType().getQualifier() == EvqConst)
{
ConstantUnion* constArray = variable->getConstPointer(); ConstantUnion* constArray = variable->getConstPointer();
TType t(variable->getType()); TType t(variable->getType());
$$ = context->intermediate.addConstantUnion(constArray, t, @1); $$ = context->intermediate.addConstantUnion(constArray, t, @1);
} else }
else
{
$$ = context->intermediate.addSymbol(variable->getUniqueId(), $$ = context->intermediate.addSymbol(variable->getUniqueId(),
variable->getName(), variable->getName(),
variable->getType(), variable->getType(),
@1); @1);
}
// don't delete $1.string, it's used by error recovery, and the pool
// pop will reclaim the memory
} }
; ;
......
...@@ -723,27 +723,27 @@ static const yytype_int16 yyrhs[] = ...@@ -723,27 +723,27 @@ static const yytype_int16 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] = static const yytype_uint16 yyrline[] =
{ {
0, 180, 180, 181, 184, 227, 230, 235, 240, 245, 0, 180, 180, 181, 184, 239, 242, 247, 252, 257,
251, 254, 257, 260, 355, 365, 378, 386, 486, 489, 263, 266, 269, 272, 367, 377, 390, 398, 498, 501,
497, 500, 506, 510, 517, 523, 532, 540, 595, 605, 509, 512, 518, 522, 529, 535, 544, 552, 607, 617,
608, 618, 628, 649, 650, 651, 656, 657, 665, 676, 620, 630, 640, 661, 662, 663, 668, 669, 677, 688,
677, 685, 696, 700, 701, 711, 721, 731, 744, 745, 689, 697, 708, 712, 713, 723, 733, 743, 756, 757,
755, 768, 772, 776, 780, 781, 794, 795, 808, 809, 767, 780, 784, 788, 792, 793, 806, 807, 820, 821,
822, 823, 840, 841, 854, 855, 856, 857, 858, 862, 834, 835, 852, 853, 866, 867, 868, 869, 870, 874,
865, 876, 884, 911, 916, 930, 985, 988, 995, 1003, 877, 888, 896, 923, 928, 942, 997, 1000, 1007, 1015,
1024, 1045, 1055, 1083, 1088, 1098, 1103, 1113, 1116, 1119, 1036, 1057, 1067, 1095, 1100, 1110, 1115, 1125, 1128, 1131,
1122, 1128, 1135, 1138, 1160, 1178, 1202, 1225, 1229, 1247, 1134, 1140, 1147, 1150, 1172, 1190, 1214, 1237, 1241, 1259,
1255, 1287, 1307, 1328, 1337, 1360, 1363, 1369, 1377, 1385, 1267, 1299, 1319, 1340, 1349, 1372, 1375, 1381, 1389, 1397,
1393, 1403, 1410, 1413, 1416, 1422, 1425, 1440, 1444, 1448, 1405, 1415, 1422, 1425, 1428, 1434, 1437, 1452, 1456, 1460,
1452, 1456, 1461, 1466, 1471, 1476, 1481, 1486, 1491, 1496, 1464, 1468, 1473, 1478, 1483, 1488, 1493, 1498, 1503, 1508,
1501, 1506, 1511, 1516, 1520, 1524, 1532, 1540, 1544, 1557, 1513, 1518, 1523, 1528, 1532, 1536, 1544, 1552, 1556, 1569,
1557, 1571, 1571, 1580, 1583, 1599, 1632, 1636, 1642, 1649, 1569, 1583, 1583, 1592, 1595, 1611, 1644, 1648, 1654, 1661,
1664, 1668, 1672, 1673, 1679, 1680, 1681, 1682, 1683, 1687, 1676, 1680, 1684, 1685, 1691, 1692, 1693, 1694, 1695, 1699,
1688, 1688, 1688, 1698, 1699, 1703, 1703, 1704, 1704, 1709, 1700, 1700, 1700, 1710, 1711, 1715, 1715, 1716, 1716, 1721,
1712, 1722, 1725, 1731, 1732, 1736, 1744, 1748, 1758, 1763, 1724, 1734, 1737, 1743, 1744, 1748, 1756, 1760, 1770, 1775,
1780, 1780, 1785, 1785, 1792, 1792, 1800, 1803, 1809, 1812, 1792, 1792, 1797, 1797, 1804, 1804, 1812, 1815, 1821, 1824,
1818, 1822, 1829, 1836, 1843, 1850, 1861, 1870, 1874, 1881, 1830, 1834, 1841, 1848, 1855, 1862, 1873, 1882, 1886, 1893,
1884, 1890, 1890 1896, 1902, 1902
}; };
#endif #endif
...@@ -2248,43 +2248,55 @@ yyreduce: ...@@ -2248,43 +2248,55 @@ yyreduce:
{ {
// The symbol table search was done in the lexical phase // The symbol table search was done in the lexical phase
const TSymbol* symbol = (yyvsp[(1) - (1)].lex).symbol; const TSymbol *symbol = (yyvsp[(1) - (1)].lex).symbol;
const TVariable* variable; const TVariable *variable = 0;
if (symbol == 0) {
if (!symbol)
{
context->error((yylsp[(1) - (1)]), "undeclared identifier", (yyvsp[(1) - (1)].lex).string->c_str()); context->error((yylsp[(1) - (1)]), "undeclared identifier", (yyvsp[(1) - (1)].lex).string->c_str());
context->recover(); context->recover();
TType type(EbtFloat, EbpUndefined); }
TVariable* fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type); else if (!symbol->isVariable())
context->symbolTable.insert(*fakeVariable); {
variable = fakeVariable; context->error((yylsp[(1) - (1)]), "variable expected", (yyvsp[(1) - (1)].lex).string->c_str());
} else { context->recover();
// This identifier can only be a variable type symbol }
if (! symbol->isVariable()) { else
context->error((yylsp[(1) - (1)]), "variable expected", (yyvsp[(1) - (1)].lex).string->c_str()); {
context->recover();
}
variable = static_cast<const TVariable*>(symbol); variable = static_cast<const TVariable*>(symbol);
if (context->symbolTable.findBuiltIn(variable->getName()) && if (context->symbolTable.findBuiltIn(variable->getName()) &&
!variable->getExtension().empty() && !variable->getExtension().empty() &&
context->extensionErrorCheck((yylsp[(1) - (1)]), variable->getExtension())) { context->extensionErrorCheck((yylsp[(1) - (1)]), variable->getExtension()))
{
context->recover(); context->recover();
} }
} }
// don't delete $1.string, it's used by error recovery, and the pool if (!variable)
// pop will reclaim the memory {
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type);
context->symbolTable.insert(*fakeVariable);
variable = fakeVariable;
}
if (variable->getType().getQualifier() == EvqConst ) { if (variable->getType().getQualifier() == EvqConst)
{
ConstantUnion* constArray = variable->getConstPointer(); ConstantUnion* constArray = variable->getConstPointer();
TType t(variable->getType()); TType t(variable->getType());
(yyval.interm.intermTypedNode) = context->intermediate.addConstantUnion(constArray, t, (yylsp[(1) - (1)])); (yyval.interm.intermTypedNode) = context->intermediate.addConstantUnion(constArray, t, (yylsp[(1) - (1)]));
} else }
else
{
(yyval.interm.intermTypedNode) = context->intermediate.addSymbol(variable->getUniqueId(), (yyval.interm.intermTypedNode) = context->intermediate.addSymbol(variable->getUniqueId(),
variable->getName(), variable->getName(),
variable->getType(), variable->getType(),
(yylsp[(1) - (1)])); (yylsp[(1) - (1)]));
}
// don't delete $1.string, it's used by error recovery, and the pool
// pop will reclaim the memory
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment