<html>
    <head>
      <base href="https://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 falls for a trick code during macro expansion"
   href="https://llvm.org/bugs/show_bug.cgi?id=26920">26920</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Preprocessor falls for a trick code during macro expansion
          </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>viniciustinti@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16028" name="attach_16028" title="Preprocessor tricky code">attachment 16028</a> <a href="attachment.cgi?id=16028&action=edit" title="Preprocessor tricky code">[details]</a></span>
Preprocessor tricky code

The preprocessor is tricked to insert an extra space during macro expansion in
the following code:

// clang -E asm.S -o -
#define CONCAT(a,b)    a##b
#define    XMM(i)        CONCAT(%xmm, i)
.macro foo n
    x = XMM(\n)
.endm

Instead of emitting '%xmm\n' it emits '%xmm \n'.

Even weird if one define 'XMM(i)' as 'CONCAT(%xmm,i)' without a leading space
on 'i' it emits '%xmm\n'.

At least I dont expect such a change impact on codegen.

The line that triggers it is:

// <a href="https://github.com/llvm-mirror/clang/blob/master/lib/Lex/TokenLexer.cpp#L186">https://github.com/llvm-mirror/clang/blob/master/lib/Lex/TokenLexer.cpp#L186</a>
...
if (i != 0 && !Tokens[i-1].is(tok::hashhash) && CurTok.hasLeadingSpace())
  NextTokGetsSpace = true;
...</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>