Bug 10747 - preprocessor permits invalid construct
Summary: preprocessor permits invalid construct
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-08 13:43 UTC by Frank Ch. Eigler
Modified: 2010-01-18 20:18 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Ch. Eigler 2009-10-08 13:43:35 UTC
%( 1 == 0 %? yes %? no %)
%( 1 == 1 %? yes %? no %)
                 ^^  notice no %:
Comment 1 Wenji Huang 2009-10-12 09:23:38 UTC
In fact, there will be error reported when executing

$ stap -e 'probe begin{ a = %( 1 == 0 %? yes %? no %)}'
parse error: expected literal string or number
        saw: operator '}' at <input>:1:43
     source: probe begin{ a = %( 1 == 0 %? yes %? no %)}
                                                       ^
1 parse error(s).
Pass 1: parse failed.  Try again with another '--vp 1' option.

but, maybe more accurate message is better, like
$ stap -e 'probe begin{ a = %( 1 == 0 %? yes %? no %)}'
parse error: incomplete conditional - missing '%('
        at: operator '%?' at <input>:1:35
     source: probe begin{ a = %( 1 == 0 %? yes %? no %)}
                                               ^
parse error: expected statement
        saw: <input> EOF
2 parse error(s).
Pass 1: parse failed.  Try again with another '--vp 1' option.

This can be reached by the following patch.
diff --git a/parse.cxx b/parse.cxx
index b88ef7f..2ae8c68 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -394,6 +394,8 @@ parser::scan_pp (bool wildcard)
 
           if (m && m->type == tok_operator && m->content == "%(") // nested %(
             nesting ++;
+          if (m && m->type == tok_operator && m->content == "%?" && !nesting)
+            throw parse_error ("incomplete conditional - missing '%('", m);
           if (nesting == 0 && m && (m->type == tok_operator && (m->content ==
"%:" || // ELSE
                                                                 m->content ==
"%)"))) // END
             break;
Comment 2 Wenji Huang 2010-01-12 05:53:44 UTC
commit c28668eaddf956b8c481e436e939d0b35bacaf68
Author: Wenji Huang <wenji.huang@oracle.com>
Date:   Tue Jan 12 13:45:55 2010 +0800

    PR10747: check invalid preprocessor construct
    
    * parse.cxx (scan_pp): Match '%(' and '%?'.
    * testsuite/semko/conditional.stp: New test.
Comment 3 Frank Ch. Eigler 2010-01-18 20:18:45 UTC
committed