]> andersk Git - splint.git/commitdiff
Fixed problem with unnamed unions within struct definitions.
authorevans1629 <evans1629>
Sun, 17 Mar 2002 04:32:50 +0000 (04:32 +0000)
committerevans1629 <evans1629>
Sun, 17 Mar 2002 04:32:50 +0000 (04:32 +0000)
src/Headers/uentry.h
src/cgrammar.c.der
src/cgrammar.y
src/clabstract.c
src/uentry.c
src/uentryList.c
test/Makefile.am
test/Makefile.in
test/unnamedsu.c [new file with mode: 0644]
test/unnamedsu.expect [new file with mode: 0644]

index 949e692702951235500636db4e03d0b5c007632c..fd8d27e302e33bfb77a0c9d87afe8258b862d7a3 100644 (file)
@@ -369,6 +369,7 @@ extern void uentry_showWhereLastExtra (uentry p_spec, /*@only@*/ cstring p_extra
 extern void uentry_setRefCounted (uentry p_e);
 
 extern /*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype p_t);
+extern /*@falsewhennull@*/ bool uentry_isUnnamedVariable (uentry) /*@*/;
 
 extern /*@notnull@*/ uentry 
   uentry_makeUnspecFunction (cstring p_n, ctype p_t, typeIdSet p_access, 
index 45de7c5223749ee5097082056612b732b4fd305e..19fa926572bd5b452c06c568dc7337d1eddb8ce3 100644 (file)
@@ -757,37 +757,37 @@ static const short yyrline[] = { 0,
   1215,  1216,  1217,  1218,  1219,  1220,  1221,  1228,  1229,  1230,
   1231,  1232,  1233,  1234,  1235,  1236,  1237,  1238,  1239,  1240,
   1241,  1244,  1248,  1249,  1253,  1254,  1258,  1259,  1260,  1263,
-  1264,  1268,  1275,  1277,  1279,  1280,  1282,  1284,  1285,  1287,
-  1289,  1291,  1293,  1294,  1295,  1298,  1299,  1301,  1303,  1304,
-  1307,  1310,  1311,  1312,  1315,  1317,  1321,  1323,  1327,  1328,
-  1329,  1333,  1335,  1335,  1337,  1340,  1342,  1344,  1347,  1352,
-  1359,  1360,  1361,  1368,  1372,  1373,  1377,  1378,  1381,  1382,
-  1385,  1386,  1389,  1390,  1391,  1392,  1395,  1396,  1399,  1400,
-  1403,  1404,  1405,  1408,  1408,  1409,  1410,  1413,  1425,  1441,
-  1442,  1445,  1446,  1447,  1450,  1451,  1454,  1456,  1457,  1459,
-  1460,  1462,  1464,  1466,  1468,  1474,  1475,  1476,  1477,  1478,
-  1479,  1480,  1481,  1482,  1486,  1489,  1492,  1493,  1497,  1499,
-  1501,  1503,  1507,  1508,  1510,  1514,  1516,  1518,  1521,  1522,
-  1523,  1524,  1525,  1526,  1527,  1528,  1529,  1530,  1531,  1532,
-  1533,  1536,  1537,  1542,  1545,  1548,  1549,  1552,  1553,  1554,
-  1555,  1556,  1557,  1558,  1559,  1560,  1561,  1562,  1565,  1566,
-  1573,  1574,  1580,  1581,  1582,  1583,  1586,  1587,  1588,  1589,
-  1592,  1593,  1597,  1600,  1603,  1606,  1609,  1612,  1615,  1616,
-  1617,  1618,  1620,  1621,  1623,  1625,  1631,  1635,  1637,  1639,
-  1641,  1645,  1646,  1649,  1650,  1653,  1654,  1657,  1658,  1661,
-  1662,  1665,  1666,  1669,  1670,  1671,  1674,  1687,  1692,  1693,
-  1697,  1698,  1701,  1706,  1709,  1710,  1711,  1719,  1720,  1720,
-  1724,  1725,  1726,  1737,  1744,  1745,  1748,  1749,  1752,  1753,
-  1754,  1755,  1756,  1758,  1759,  1760,  1761,  1764,  1765,  1766,
-  1767,  1768,  1769,  1770,  1771,  1772,  1773,  1776,  1777,  1780,
-  1781,  1782,  1783,  1786,  1787,  1788,  1791,  1792,  1793,  1796,
-  1797,  1798,  1799,  1800,  1803,  1804,  1805,  1808,  1809,  1812,
-  1813,  1817,  1818,  1821,  1822,  1825,  1826,  1829,  1830,  1831,
-  1832,  1835,  1836,  1837,  1838,  1839,  1840,  1841,  1842,  1843,
-  1844,  1845,  1846,  1849,  1850,  1853,  1856,  1858,  1860,  1864,
-  1865,  1867,  1869,  1872,  1873,  1874,  1876,  1877,  1878,  1879,
-  1880,  1881,  1882,  1885,  1886,  1889,  1890,  1893,  1896,  1897,
-  1898,  1899,  1900,  1903,  1904,  1905,  1906
+  1264,  1268,  1275,  1277,  1279,  1281,  1283,  1285,  1286,  1288,
+  1290,  1292,  1294,  1295,  1296,  1299,  1300,  1302,  1304,  1305,
+  1308,  1311,  1312,  1313,  1316,  1318,  1322,  1324,  1328,  1329,
+  1330,  1334,  1336,  1336,  1338,  1341,  1343,  1345,  1348,  1353,
+  1360,  1361,  1362,  1369,  1373,  1374,  1378,  1379,  1382,  1383,
+  1386,  1387,  1390,  1391,  1392,  1393,  1396,  1397,  1400,  1401,
+  1404,  1405,  1406,  1409,  1409,  1410,  1411,  1414,  1426,  1442,
+  1443,  1446,  1447,  1448,  1451,  1452,  1455,  1457,  1458,  1460,
+  1461,  1463,  1465,  1467,  1469,  1475,  1476,  1477,  1478,  1479,
+  1480,  1481,  1482,  1483,  1487,  1490,  1493,  1494,  1498,  1500,
+  1502,  1504,  1508,  1509,  1511,  1515,  1517,  1519,  1522,  1523,
+  1524,  1525,  1526,  1527,  1528,  1529,  1530,  1531,  1532,  1533,
+  1534,  1537,  1538,  1543,  1546,  1549,  1550,  1553,  1554,  1555,
+  1556,  1557,  1558,  1559,  1560,  1561,  1562,  1563,  1566,  1567,
+  1574,  1575,  1581,  1582,  1583,  1584,  1587,  1588,  1589,  1590,
+  1593,  1594,  1598,  1601,  1604,  1607,  1610,  1613,  1616,  1617,
+  1618,  1619,  1621,  1622,  1624,  1626,  1632,  1636,  1638,  1640,
+  1642,  1646,  1647,  1650,  1651,  1654,  1655,  1658,  1659,  1662,
+  1663,  1666,  1667,  1670,  1671,  1672,  1675,  1688,  1693,  1694,
+  1698,  1699,  1702,  1707,  1710,  1711,  1712,  1720,  1721,  1721,
+  1725,  1726,  1727,  1738,  1745,  1746,  1749,  1750,  1753,  1754,
+  1755,  1756,  1757,  1759,  1760,  1761,  1762,  1765,  1766,  1767,
+  1768,  1769,  1770,  1771,  1772,  1773,  1774,  1777,  1778,  1781,
+  1782,  1783,  1784,  1787,  1788,  1789,  1792,  1793,  1794,  1797,
+  1798,  1799,  1800,  1801,  1804,  1805,  1806,  1809,  1810,  1813,
+  1814,  1818,  1819,  1822,  1823,  1826,  1827,  1830,  1831,  1832,
+  1833,  1836,  1837,  1838,  1839,  1840,  1841,  1842,  1843,  1844,
+  1845,  1846,  1847,  1850,  1851,  1854,  1857,  1859,  1861,  1865,
+  1866,  1868,  1870,  1873,  1874,  1875,  1877,  1878,  1879,  1880,
+  1881,  1882,  1883,  1886,  1887,  1890,  1891,  1894,  1897,  1898,
+  1899,  1900,  1901,  1904,  1905,  1906,  1907
 };
 #endif
 
@@ -4418,7 +4418,7 @@ case 394:
 { sRef_clearGlobalScopeSafe (); ;
     break;}
 case 395:
-{ {ctype ct; ct = declareStruct (yyvsp[-9].cname, yyvsp[-4].flist); /* setGlobalStructInfo(ct, $12);*/ yyval.ctyp = ct;} ;
+{ ctype ct; ct = declareStruct (yyvsp[-9].cname, yyvsp[-4].flist); /* setGlobalStructInfo(ct, $12);*/ yyval.ctyp = ct; ;
     break;}
 case 396:
 { sRef_setGlobalScopeSafe (); ;
index ae113f38eaac0b3dbd1db6a19d7540da20e8d34a..4c7ed2c65feae72498fb9ff2283ec1faa32d0db7 100644 (file)
@@ -1276,7 +1276,8 @@ suSpc
    CreateStructInnerScope 
    structDeclList  DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
    TRBRACE 
-   optStructInvariant { {ctype ct; ct = declareStruct ($3, $8); /* setGlobalStructInfo(ct, $12);*/ $$ = ct;} } 
+   optStructInvariant 
+   { ctype ct; ct = declareStruct ($3, $8); /* setGlobalStructInfo(ct, $12);*/ $$ = ct; } 
  | NotType CUNION  newId IsType TLBRACE { sRef_setGlobalScopeSafe (); } 
    CreateStructInnerScope 
    structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); } 
@@ -1298,10 +1299,10 @@ suSpc
    { $$ = declareUnnamedUnion ($7); } 
  | NotType CSTRUCT IsType TLBRACE TRBRACE
    { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
- | NotType CUNION  IsType TLBRACE TRBRACE 
+ | NotType CUNION IsType TLBRACE TRBRACE 
    { $$ = ctype_createUnnamedUnion (uentryList_new ()); } 
  | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); } 
- | NotType CUNION  newId NotType { $$ = handleUnion ($3); }
+ | NotType CUNION newId NotType { $$ = handleUnion ($3); }
 
 NotType
  : { g_expectingTypeName = FALSE; }
index 10dbd041058d2c21b04b03bddd51202c350a8186..0a4edb4170bed52f718934c2fba89e0e76ca21eb 100644 (file)
@@ -1088,9 +1088,13 @@ fixUnnamedDecl (qtype q)
 
   if (ctype_isStruct (ct) || ctype_isUnion (ct))
     {
+      /* evans 2002-03-16: this seems like a really bad idea!
       uentryList res = ctype_getFields (ct);
 
       return (uentryList_copy (res));
+      */
+
+      return uentryList_single (uentry_makeUnnamedVariable (ct));
     }
   else if (ctype_isEnum (ct))
     {
@@ -1647,6 +1651,8 @@ declareUnnamedStruct (/*@only@*/ uentryList f)
 ctype
 declareUnnamedUnion (/*@only@*/ uentryList f)
 {
+  DPRINTF (("Unnamed union: %s", uentryList_unparse (f)));
+
   if (context_maybeSet (FLG_NUMSTRUCTFIELDS))
     {
       int num = uentryList_size (f);
@@ -1672,7 +1678,8 @@ ctype declareStruct (cstring id, /*@only@*/ uentryList f)
   uentry ue;
   int num = uentryList_size (f);
 
-  DPRINTF (("Declare struct: %s / %s", id, uentryList_unparse (f)));
+  DPRINTF (("Declare struct: %s / %s [%d]", id, uentryList_unparse (f),
+           uentryList_size (f)));
 
   ct = ctype_createStruct (cstring_copy (id), f);
 
index a7a45a5aa21841089e58c14946dfaec5e6b36316..05abe0ad3bf1b27f56ef524b7c2271b7fba09b88 100644 (file)
@@ -702,12 +702,15 @@ static void uentry_setConstantValue (uentry ue, /*@only@*/ multiVal val)
   return uentry_makeVariable (n, t, setLocation (), FALSE);
 }
 
-# ifndef NOLCL
+bool uentry_isUnnamedVariable (uentry ue)
+{
+  return uentry_isVariable (ue) && cstring_isUndefined (ue->uname);
+}
+
 /*@notnull@*/ /*@only@*/ uentry uentry_makeUnnamedVariable (ctype t)
 {
   return uentry_makeVariable (cstring_undefined, t, setLocation (), FALSE);
 }
-# endif
 
 /*@notnull@*/ uentry uentry_makeIdDatatype (idDecl id)
 {
index ae3a8a67508afeb2afb8b7fdec6b9b226192b475..96951d631248e8aa46ae8088da90ead99abddf52 100644 (file)
@@ -702,6 +702,26 @@ uentryList_lookupField (uentryList f, cstring name)
     }
   else
     {
+      uentryList_elements (f, el)
+       {
+         if (uentry_isUnnamedVariable (el))
+           {
+             ctype ct = uentry_getType (el);
+
+             if (ctype_isStruct (ct) || ctype_isUnion (ct))
+               {
+                 uentryList fields = ctype_getFields (ct);
+                 uentry ue = uentryList_lookupField (fields, name);
+
+                 if (uentry_isValid (ue))
+                   {
+                     return ue;
+                   }
+               }
+           }
+       }
+      end_uentryList_elements ;
+
       return uentry_undefined;
     }
 }
@@ -709,6 +729,8 @@ uentryList_lookupField (uentryList f, cstring name)
 /*@only@*/ uentryList
   uentryList_mergeFields (/*@only@*/ uentryList f1, /*@only@*/ uentryList f2)
 {
+  DPRINTF (("Merge: %s + %s", uentryList_unparse (f1), uentryList_unparse (f2)));
+
   if (uentryList_isUndefined (f1))
     {
       return  (f2);
index 6b149f5ef81ca6b76b9360bf7b5162f9f3630417..66bded5d5f8dfcf9812a9d3867a98e6be481c39d 100644 (file)
@@ -49,7 +49,8 @@ UNITTESTS = \
   specclauses \
   special stack staticarray strings \
   stringliteral \
-  structassign typequals typeof ud ulstypes union unioninit unreachable unsignedcompare \
+  structassign typequals typeof ud ulstypes union unioninit \
+  unnamedsu unreachable unsignedcompare \
   unused ullint utypes void widestrings
 UNITEXPECTS = $(addsuffix .expect, $(UNITTESTS))
 
@@ -811,6 +812,10 @@ union:
 unioninit:
        -$(SPLINTR) unioninit.c -expect 2
 
+.PHONY: unnamedsu
+unnamedsu:
+       -$(SPLINTR) unnamedsu.c -expect 0
+
 .PHONY: unreachable
 unreachable:
        -$(SPLINTR) unreachable.c -expect 5
@@ -1181,6 +1186,7 @@ EXTRA_DIST =  ./abst_t.lcl ./abst_t.lcs  \
               ./union.c \
               ./unreachable.c \
               ./unsignedcompare.c \
+              ./unnamedsu.c \
               ./unused.c \
               ./void.c \
               ./conditions/miroslaw.c \
@@ -1446,6 +1452,7 @@ EXTRA_DIST =  ./abst_t.lcl ./abst_t.lcs  \
               ullint.expect \
               ulstypes.expect \
               union.expect \
+              unnamedsu.expect \
               unreachable.expect \
               unsignedcompare.expect \
               unused.expect \
index b94538bdccc352cf2505cbd6336b176f0bee5a9e..d033ebb49e46ac85794c5fb0a787bb735ca21ec2 100644 (file)
@@ -126,7 +126,8 @@ UNITTESTS = \
   specclauses \
   special stack staticarray strings \
   stringliteral \
-  structassign typequals typeof ud ulstypes union unioninit unreachable unsignedcompare \
+  structassign typequals typeof ud ulstypes union unioninit \
+  unnamedsu unreachable unsignedcompare \
   unused ullint utypes void widestrings
 
 UNITEXPECTS = $(addsuffix .expect, $(UNITTESTS))
@@ -427,6 +428,7 @@ EXTRA_DIST = ./abst_t.lcl ./abst_t.lcs  \
               ./union.c \
               ./unreachable.c \
               ./unsignedcompare.c \
+              ./unnamedsu.c \
               ./unused.c \
               ./void.c \
               ./conditions/miroslaw.c \
@@ -692,6 +694,7 @@ EXTRA_DIST = ./abst_t.lcl ./abst_t.lcs  \
               ullint.expect \
               ulstypes.expect \
               union.expect \
+              unnamedsu.expect \
               unreachable.expect \
               unsignedcompare.expect \
               unused.expect \
@@ -1629,6 +1632,10 @@ union:
 unioninit:
        -$(SPLINTR) unioninit.c -expect 2
 
+.PHONY: unnamedsu
+unnamedsu:
+       -$(SPLINTR) unnamedsu.c -expect 0
+
 .PHONY: unreachable
 unreachable:
        -$(SPLINTR) unreachable.c -expect 5
diff --git a/test/unnamedsu.c b/test/unnamedsu.c
new file mode 100644 (file)
index 0000000..fe498bd
--- /dev/null
@@ -0,0 +1,19 @@
+typedef struct _su
+{
+  int x1;
+  union
+  {
+    int u1;
+    int u2;
+  } ;
+  int x2;
+} su;
+
+su wtd = { 1, NULL, 2 };
+
+int f (su *s)
+{
+  return s->u1 + s->x1;
+}
+
+
diff --git a/test/unnamedsu.expect b/test/unnamedsu.expect
new file mode 100644 (file)
index 0000000..2b06c77
--- /dev/null
@@ -0,0 +1,2 @@
+
+Finished checking --- no warnings
This page took 0.083847 seconds and 5 git commands to generate.