This is an archive of the discontinued LLVM Phabricator instance.

PR10235: support for vector mode attributes + warning
ClosedPublic

Authored by DmitryPolukhin on Nov 17 2015, 4:56 AM.

Details

Summary

Add support for vector mode attributes like "attribute((mode(V4SF)))". Also add warning about deprecated vector modes like GCC does.

Diff Detail

Repository
rL LLVM

Event Timeline

DmitryPolukhin retitled this revision from to PR10235: support for vector mode attributes + warning.
DmitryPolukhin updated this object.
DmitryPolukhin added a reviewer: aaron.ballman.
DmitryPolukhin added a subscriber: cfe-commits.
aaron.ballman edited edge metadata.Nov 17 2015, 9:52 AM

I am a little bit confused -- this patch adds a deprecation warning for vector sizes and claims that the attribute is ignored (by placing it in the IgnoredAttributes group), but then provides the initial implementation for this functionality and makes use of the attribute. If it's deprecated, why implement the behavior? Better to say "we recognize this attribute and won't explode on it, but do not implement the functionality since it is deprecated."

include/clang/Basic/DiagnosticSemaKinds.td
2765 ↗(On Diff #40384)

How about:

"'mode' attribute is not supported for vector types; use the 'vector_size' attribute instead"

Thank you for prompt response!

include/clang/Basic/DiagnosticSemaKinds.td
2765 ↗(On Diff #40384)

Both GCC and ICC support vector types in mode attribute with similar warning so for compatibility reasons it is better to implement it. Taking into account that detection of vector types is more than half of supporting them. I do agree that warning group is confusing. I was not able to find more suitable warning group so would you recommend to create new one for this warning?

aaron.ballman added inline comments.Nov 17 2015, 11:28 AM
include/clang/Basic/DiagnosticSemaKinds.td
2765 ↗(On Diff #40384)

Are there headers from major library vendors that rely on supporting this feature? If not, then I would say it's probably better to simply not implement the diagnostic and fail to support such constructs at all. If it is used by major vendors and would prevent otherwise functional code from working, then this approach is reasonable. In that case, I would add a new diagnostic group (DeprecatedAttributes and add it to the Deprecated group).

DmitryPolukhin edited edge metadata.

Added new warning group as suggested.

I see thousands of vector types in headers on GitHub https://github.com/search?p=1&q=%22__attribute__+mode+v4sf%22+extension%3Ah&ref=searchresults&type=Code&utf8=%E2%9C%93

liboil from freedesktop.org uses vector types in headers.

Added new warning group as suggested.

I see thousands of vector types in headers on GitHub https://github.com/search?p=1&q=%22__attribute__+mode+v4sf%22+extension%3Ah&ref=searchresults&type=Code&utf8=%E2%9C%93

liboil from freedesktop.org uses vector types in headers.

The vast majority of those headers all appear to be GCC's vector-defs.h, so I'm still not convinced this is actually something we need to solve. However, I also don't see the harm.

include/clang/Basic/DiagnosticSemaKinds.td
2828 ↗(On Diff #40489)

Should be reworded slightly to be consistent with other attribute diagnostics:

"specifying vector types with the 'mode' attribute is deprecated; use the 'vector_size' attribute instead"

lib/Sema/SemaDeclAttr.cpp
3239 ↗(On Diff #40489)

parseModeAttrArg() please.

3315 ↗(On Diff #40489)

Can you have a vector of vectors with mode? I'm wondering why this isn't part of parseModeAttr(), since this is parsing part of the mode attribute.

3318 ↗(On Diff #40489)

This will cause a buffer overrun on pathological code; should also constrain based on the size of Str.

DmitryPolukhin marked 3 inline comments as done.
DmitryPolukhin added inline comments.
lib/Sema/SemaDeclAttr.cpp
3315 ↗(On Diff #40489)

No, it is not possible and more over it is not allowed to combine vector_size and vector mode (GCC does the same). Checks below prevent non-primitive types as vector elements.

3318 ↗(On Diff #40489)

Thank you for catching this!

aaron.ballman accepted this revision.Nov 18 2015, 7:12 AM
aaron.ballman edited edge metadata.

Thanks, this LGTM!

~Aaron

This revision is now accepted and ready to land.Nov 18 2015, 7:12 AM
This revision was automatically updated to reflect the committed changes.