This is an archive of the discontinued LLVM Phabricator instance.

[Inline asm] Correctly parse GCC-style asm line following MS-style asm line
ClosedPublic

Authored by d.zobnin.bugzilla on Mar 31 2016, 9:15 AM.

Details

Summary

Clang fails to compile the following code:

void f() {

__asm mov ebx, ecx
__asm__("movl %ecx, %edx");

}

reporting unexpected token "asm" at start of statement.
Quit parsing MS-style assembly if the following statement has GCC style to handle such code.

Diff Detail

Repository
rL LLVM

Event Timeline

d.zobnin.bugzilla retitled this revision from to [Inline asm] Correctly parse GCC-style asm line following MS-style asm line.
d.zobnin.bugzilla updated this object.
d.zobnin.bugzilla added a reviewer: echristo.
d.zobnin.bugzilla added a subscriber: cfe-commits.
rsmith added a subscriber: rsmith.Mar 31 2016, 11:46 AM
rsmith added inline comments.
lib/Parse/ParseStmtAsm.cpp
423 ↗(On Diff #52222)

The next token in GCC-style inline asm could also be volatile (or const or goto -- though we don't support the latter).

Please make this GCC / MS dialect selection the same way that ParseAsmStatement does (and factor out a static isGCCAsmStatement(Token &TokAfterAsm) function or similar).

d.zobnin.bugzilla added a reviewer: rsmith.
d.zobnin.bugzilla removed a subscriber: rsmith.

Richard, thank you for the review!

I've created a static function to check if this is a GCC asm statement as you recommended to do, and also made "isTypeQualifier" function static.
I've added a check for "goto" after "asm" to treat such statements as GCC-style assembly.
Also, do you think it will be better to diagnose unsupported "asm goto" statements rather than fall into parsing them and emit "expected identifier" error or something like that?

Thank you,
Denis Zobnin

Richard, Eric,

Please take a look at the patch.

Thank you,
Denis Zobnin

rsmith accepted this revision.Apr 20 2016, 3:28 PM
rsmith edited edge metadata.

LGTM, thank you!

This revision is now accepted and ready to land.Apr 20 2016, 3:28 PM
This revision was automatically updated to reflect the committed changes.