<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Preprocessor too eager to stringify in assembler-with-cpp mode?"
   href="http://llvm.org/bugs/show_bug.cgi?id=16371">16371</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Preprocessor too eager to stringify in assembler-with-cpp mode?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>aseipp@pobox.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>While continuing my porting GHC-to-clang work, I have run into a rather odd
discrepancy in the way Clang's preprocessor handles hashes in parameters and
whatnot vs GCC, and I'm not sure if this is a bug or not. :)

Here is a minimal test case vs GCC 4.7.3:

--------------------------------------------------------
$ gcc -E -undef -traditional -x assembler-with-cpp -o - -
#define foo(a,b,c) \
test asdfx# a b c

foo(a,b,c)

foo(a#,b#,c#)
^D
# 1 "<stdin>"
# 1 "<command-line>"
# 1 "<stdin>"



test asdfx# a b c

test asdfx# a# b# c#
$
$ clang -E -undef -traditional -x assembler-with-cpp -o - -  
#define foo(a,b,c) \
test asdfx# a b c

foo(a,b,c)

foo(a#,b#,c#)
^D
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<stdin>" 2



test asdfx"a" b c

test asdfx"a#" b# c#
--------------------------------------------------------

Note the stringification of the first argument. I'm not sure if this
discrepancy is expected, but we force assembler-with-cpp mode in GHC now.
Perhaps this could be alleviated.

As a more extreme test case, consider the test from <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - Segmentation fault when preprocessing in assembler-with-cpp mode"
   href="show_bug.cgi?id=16363">bug 16363</a>, cut down
slightly (this is Haskell code but the deficiency should be obvious)

GCC:

--------------------------------------------------------
$ gcc -E -undef -traditional -x assembler-with-cpp -o - -
#define derivePrim(ty, ctr, sz, align) \
instance Prim ty where {                                        \
  sizeOf# _ = unI# sz                                           \
; alignment# _ = unI# align   

derivePrim(Word, W#, sIZEOF_WORD, aLIGNMENT_WORD)
# 1 "<stdin>"
# 1 "<command-line>"
# 1 "<stdin>"





instance Prim Word where {                                          sizeOf# _ =
unI#  sIZEOF_WORD                                           ; alignment# _ =
unI#  aLIGNMENT_WORD

--------------------------------------------------------

Clang:

--------------------------------------------------------
$ clang -E -undef -traditional -x assembler-with-cpp -o - -
#define derivePrim(ty, ctr, sz, align) \
instance Prim ty where {                                        \
  sizeOf# _ = unI# sz                                           \
; alignment# _ = unI# align   

derivePrim(Word, W#, sIZEOF_WORD, aLIGNMENT_WORD)
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<stdin>" 2





instance Prim Word where { sizeOf# _ = unI" sIZEOF_WORD" ; alignment# _ = unI"
aLIGNMENT_WORD"
--------------------------------------------------------

If it's not outrageous, could this be accommodated at all?

Attached is a file containing the problematic parts (it is a smaller version of
the attachment from <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - Segmentation fault when preprocessing in assembler-with-cpp mode"
   href="show_bug.cgi?id=16363">bug 16363</a>.) You can run 'gcc -E -x assembler-with-cpp' over
it to see the expected output vs what Clang outputs.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>