This is an archive of the discontinued LLVM Phabricator instance.

[llvm][MC] Add .pushsection/.popsection support to COFFAsmParser
ClosedPublic

Authored by cynecx on Jun 3 2023, 4:35 PM.

Details

Summary

The COFFAsmParser (to my surprise) didn't support the .pushsection and .popsection directives. These directives aren't directly useful, however for frontends that have inline asm support this is really useful. Rust in particular, has support for inline asm, which can be used together with these directives to "emulate" features like static generics. This patch adds support for the two mentioned directives.

Diff Detail

Event Timeline

cynecx created this revision.Jun 3 2023, 4:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2023, 4:35 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
cynecx requested review of this revision.Jun 3 2023, 4:35 PM

Please include more diff context. See https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface

Thanks. This extension looks reasonable to me.

These directives aren't directly useful, however for frontends that have inline asm support this is really useful.

Agree. If you know which frontend is going to use this, consider mentioning it, otherwise I'll just assume some Clang users will adopt the feature.

llvm/lib/MC/MCParser/COFFAsmParser.cpp
71

Add this after addDirectiveHandler<&COFFAsmParser::ParseDirectiveSection>(".section");

371

While changing signature, consider fixing the function case to camelCase.

llvm/test/MC/COFF/section.s
216

Add some tests with arguments (including section flags)?

cynecx edited the summary of this revision. (Show Details)Jun 6 2023, 2:41 PM
cynecx updated this revision to Diff 529050.Jun 6 2023, 2:43 PM

Addressed the comments.

cynecx marked 3 inline comments as done.Jun 6 2023, 2:44 PM

Agree. If you know which frontend is going to use this, consider mentioning it, otherwise I'll just assume some Clang users will adopt the feature.

I've updated the description.

Thank You for reviewing this :)

MaskRay added inline comments.Jun 6 2023, 8:08 PM
llvm/lib/MC/MCParser/COFFAsmParser.cpp
371

parseSectionArguments

379–380

Don't format this unrelated part.

445

This error is not tested. See llvm-mc ... --defsym ERR=1 in llcm/test/MC for error testing.

llvm/test/MC/COFF/section.s
239

//

don't mix different comment markers.

cynecx updated this revision to Diff 529309.Jun 7 2023, 8:10 AM

Addressed the remaining comments.

cynecx marked 4 inline comments as done.Jun 7 2023, 8:11 AM
MaskRay accepted this revision.Jun 7 2023, 8:12 AM

Thanks!

This revision is now accepted and ready to land.Jun 7 2023, 8:12 AM
cynecx updated this revision to Diff 529310.Jun 7 2023, 8:13 AM
cynecx added a comment.Jun 7 2023, 1:03 PM

The build failure seems unrelated (something in flang is failing, which I haven't touched here).

The build failure seems unrelated (something in flang is failing, which I haven't touched here).

Seems to pass now. Yes, you can ignore unrelated failures.

@MaskRay It would be great if you could commit these changes since I don't have commit access :)

This revision was automatically updated to reflect the committed changes.