This is an archive of the discontinued LLVM Phabricator instance.

Add __declspec code_seg support
Needs RevisionPublic

Authored by kbdsmoke on Jul 28 2016, 12:58 PM.

Details

Summary

clang does not support this by default. By default, if you want to utilize declspec to assign a SectionAttr to a function, you should use declspec allocate.
However, this is not valid under MSVC. It works under clang (whether or not that is acceptable should be the subject of another patch request)

To avoid a lot of headaches for everyone here's my solution. Double __declspec in Attr.td works fine, it seems, and so the fix was fairly trivial. I also patch some code to verify code_seg is only ever used on FunctionDecls.

Reason being, without it technically code_seg on variables and so on would be valid.

Diff Detail

Repository
rL LLVM

Event Timeline

kbdsmoke updated this revision to Diff 65974.Jul 28 2016, 12:58 PM
kbdsmoke retitled this revision from to Add __declspec code_seg support.
kbdsmoke updated this object.
kbdsmoke set the repository for this revision to rL LLVM.
kbdsmoke added a subscriber: cfe-commits.
rnk added a subscriber: rnk.Jul 28 2016, 1:02 PM

Needs tests, though. The MSDN sample code is probably a good starting point.

lib/Sema/SemaDeclAttr.cpp
2659

MSDN suggests that it can also be applied to classes to control where special member functions live.

I think it might be better to have a separate attribute for this.

majnemer requested changes to this revision.Jul 28 2016, 1:07 PM
majnemer added a reviewer: majnemer.
majnemer added a subscriber: majnemer.

Thanks for contributing this! I actually worked on an implementation of this feature but never sent it out for review because I couldn't get an answer from Microsoft regarding this issue: https://connect.microsoft.com/VisualStudio/feedback/details/1203505/pragma-code-seg-and-declspec-code-seg-do-not-interact-correctly-with-nested-classes

I don't think the correct solution to __declspec(code_seg). Because it has special rules with regard to nested classes, we should have a separate attribute whose Subjects are Function and Class. During Sema processing of the attribute, I'd staple an implicit SectionAttr to all nested functions.

For future reference, please include full context in your patch.

Also, this needs tests.

This revision now requires changes to proceed.Jul 28 2016, 1:07 PM

Indeed I was incorrect, and I agree with your analysis of the problem @majnemer
I'll try to correct this issue in my own time and get some tests going