@@ -136,7 +136,7 @@ class TestPreprocessor : public TestFixture {
136136 if (inlineSuppression)
137137 preprocessor.inlineSuppressions (*inlineSuppression);
138138 preprocessor.removeComments ();
139- preprocessor.simplifyPragmaAsm ();
139+ preprocessor.simplifyAsm ();
140140
141141 std::map<std::string, std::string> cfgcode;
142142 if (cfgs.empty ()) {
@@ -255,6 +255,13 @@ class TestPreprocessor : public TestFixture {
255255 TEST_CASE (pragma);
256256 TEST_CASE (pragma_asm_1);
257257 TEST_CASE (pragma_asm_2);
258+ TEST_CASE (sdccAsmOperands);
259+ TEST_CASE (sdccAsmEmptyAndAdjacent);
260+ TEST_CASE (sdccAsmComments);
261+ TEST_CASE (sdccAsmIncomplete);
262+ TEST_CASE (sdccAsmOtherSyntax);
263+ TEST_CASE (sdccAsmConditional);
264+ TEST_CASE (sdccAsmControlFlow);
258265 TEST_CASE (endifsemicolon);
259266 TEST_CASE (missing_doublequote);
260267 TEST_CASE (handle_error);
@@ -1562,6 +1569,151 @@ class TestPreprocessor : public TestFixture {
15621569 ASSERT_EQUALS (" asm ( )\n ;\n\n bbb" , actual.at (" " ));
15631570 }
15641571
1572+ void sdccAsmOperands () { // #6028
1573+ {
1574+ const char code[] = " void f() {\n "
1575+ " __asm\n "
1576+ " movx @dptr,a\n "
1577+ " __endasm;\n "
1578+ " }\n " ;
1579+ ASSERT_EQUALS (" void f ( ) {\n asm ( )\n\n ;\n }" , getcode (settings0, *this , code).at (" " ));
1580+ }
1581+ {
1582+ const char code[] = " __asm\n "
1583+ " mov b,#(s_XINIT>>8)\n "
1584+ " __endasm" ;
1585+ ASSERT_EQUALS (" asm ( )\n\n ;" , getcode (settings0, *this , code).at (" " ));
1586+ }
1587+ {
1588+ const char code[] = " int f(int x) {\n "
1589+ " ++x;\n "
1590+ " __asm\n "
1591+ " anl a,#0x0f\n "
1592+ " inc a\n "
1593+ " movc a,@a+pc\n "
1594+ " ret\n "
1595+ " __endasm;\n "
1596+ " return x;\n "
1597+ " }\n " ;
1598+ ASSERT_EQUALS (" int f ( int x ) {\n ++ x ;\n asm ( )\n\n\n\n\n ;\n return x ;\n }" ,
1599+ getcode (settings0, *this , code).at (" " ));
1600+ }
1601+ ASSERT_EQUALS (" " , errout_str ());
1602+ }
1603+
1604+ void sdccAsmEmptyAndAdjacent () {
1605+ ASSERT_EQUALS (" asm ( )\n ;" , getcode (settings0, *this , " __asm\n __endasm" ).at (" " ));
1606+ const char code[] = " __asm\n "
1607+ " __endasm;\n "
1608+ " __asm\n "
1609+ " nop\n "
1610+ " __endasm;\n "
1611+ " int after;\n " ;
1612+ ASSERT_EQUALS (" asm ( )\n ;\n asm ( )\n\n ;\n int after ;" , getcode (settings0, *this , code).at (" " ));
1613+ ASSERT_EQUALS (" " , errout_str ());
1614+ }
1615+
1616+ void sdccAsmComments () {
1617+ const char code[] = " /* __asm */\n "
1618+ " const char *s = \" __asm __endasm\" ;\n "
1619+ " __asm ; __endasm } #error ignored\n "
1620+ " ; __asm {\n "
1621+ " mov a,b ; __endasm\n "
1622+ " /* __endasm */ nop\n "
1623+ " mov a,__endasm\n "
1624+ " __endasm;\n "
1625+ " int after; // __asm\n " ;
1626+ ASSERT_EQUALS (" \n const char * s = \" __asm __endasm\" ;\n asm ( )\n\n\n\n\n ;\n int after ;" ,
1627+ getcode (settings0, *this , code).at (" " ));
1628+ ASSERT_EQUALS (" " , errout_str ());
1629+ }
1630+
1631+ void sdccAsmIncomplete () {
1632+ ASSERT_EQUALS (" __asm\n nop" , getcode (settings0, *this , " __asm\n nop" ).at (" " ));
1633+ ASSERT_EQUALS (" __asm\n nop\n __asm\n nop" , getcode (settings0, *this , " __asm\n nop\n __asm\n nop" ).at (" " ));
1634+ ASSERT_EQUALS (" __asm\n nop\n __asm\n nop\n __endasm ;\n int after ;" ,
1635+ getcode (settings0, *this , " __asm\n nop\n __asm\n nop\n __endasm;\n int after;" ).at (" " ));
1636+ {
1637+ const char code[] = " void f() {\n "
1638+ " __asm\n "
1639+ " nop\n "
1640+ " }\n "
1641+ " int after;\n "
1642+ " __endasm;\n " ;
1643+ ASSERT_EQUALS (" void f ( ) {\n __asm\n nop\n }\n int after ;\n __endasm ;" ,
1644+ getcode (settings0, *this , code).at (" " ));
1645+ }
1646+ {
1647+ const char code[] = " __asm\n "
1648+ " nop\n "
1649+ " #define N 1\n "
1650+ " __endasm;\n "
1651+ " int after;\n " ;
1652+ ASSERT_EQUALS (" __asm\n nop\n\n __endasm ;\n int after ;" , getcode (settings0, *this , code).at (" " ));
1653+ }
1654+ ASSERT_EQUALS (" " , errout_str ());
1655+ }
1656+
1657+ void sdccAsmOtherSyntax () {
1658+ const char code[] = " void f() {\n "
1659+ " __asm (\" nop\" );\n "
1660+ " __asm\n "
1661+ " (\" nop\" );\n "
1662+ " __asm volatile (\" nop\" );\n "
1663+ " __asm goto (\"\" : : : : label);\n "
1664+ " label: ;\n "
1665+ " __asm { nop }\n "
1666+ " }\n "
1667+ " __asm void g(void) {\n "
1668+ " nop\n "
1669+ " }\n " ;
1670+ ASSERT_EQUALS (" void f ( ) {\n __asm ( \" nop\" ) ;\n __asm\n ( \" nop\" ) ;\n "
1671+ " __asm volatile ( \" nop\" ) ;\n __asm goto ( \"\" : : : : label ) ;\n "
1672+ " label : ;\n __asm { nop }\n }\n __asm void g ( void ) {\n nop\n }" ,
1673+ getcode (settings0, *this , code).at (" " ));
1674+ ASSERT_EQUALS (" \n void f ( ) { $__asm ( \" nop\" ) ; }" ,
1675+ getcode (settings0, *this , " #define ASM __asm\n void f() { ASM(\" nop\" ); }" ).at (" " ));
1676+ ASSERT_EQUALS (" " , errout_str ());
1677+ }
1678+
1679+ void sdccAsmConditional () {
1680+ const char code[] = " void f() {\n "
1681+ " #ifdef USE_ASM\n "
1682+ " __asm\n "
1683+ " mov b,#(s_XINIT>>8)\n "
1684+ " movx @dptr,a\n "
1685+ " __endasm;\n "
1686+ " #else\n "
1687+ " fallback();\n "
1688+ " #endif\n "
1689+ " after();\n "
1690+ " }\n " ;
1691+ ASSERT_EQUALS (" void f ( ) {\n\n asm ( )\n\n\n ;\n\n\n\n after ( ) ;\n }" ,
1692+ getcodeforcfg (settings0, *this , code, " USE_ASM" , " file.c" ));
1693+ ASSERT_EQUALS (" void f ( ) {\n\n\n\n\n\n\n fallback ( ) ;\n\n after ( ) ;\n }" ,
1694+ getcodeforcfg (settings0, *this , code, " " , " file.c" ));
1695+ ASSERT_EQUALS (" " , errout_str ());
1696+ }
1697+
1698+ void sdccAsmControlFlow () {
1699+ const char code[] = " void f(int x) {\n "
1700+ " if (x)\n "
1701+ " __asm\n "
1702+ " nop\n "
1703+ " __endasm;\n "
1704+ " else\n "
1705+ " fallback();\n "
1706+ " do\n "
1707+ " __asm\n "
1708+ " nop\n "
1709+ " __endasm /* comment */;\n "
1710+ " while (x);\n "
1711+ " }\n " ;
1712+ ASSERT_EQUALS (" void f ( int x ) {\n if ( x )\n asm ( )\n\n ;\n else\n fallback ( ) ;\n "
1713+ " do\n asm ( )\n\n ;\n while ( x ) ;\n }" , getcode (settings0, *this , code).at (" " ));
1714+ ASSERT_EQUALS (" " , errout_str ());
1715+ }
1716+
15651717 void endifsemicolon () {
15661718 const char filedata[] = " void f() {\n "
15671719 " #ifdef A\n "
0 commit comments