This is an archive of the discontinued LLVM Phabricator instance.

Parsing MS pragma intrinsic
ClosedPublic

Authored by agutowski on Aug 26 2016, 1:19 PM.

Details

Summary

Parse pragma intrinsic, display warning if the function isn't a builtin function in clang and suggest including intrin.h.

Diff Detail

Repository
rL LLVM

Event Timeline

agutowski updated this revision to Diff 69430.Aug 26 2016, 1:19 PM
agutowski retitled this revision from to Parsing MS pragma intrinsic.
agutowski updated this object.
agutowski added a reviewer: rnk.
rnk added inline comments.Aug 29 2016, 10:37 AM
include/clang/Basic/DiagnosticParseKinds.td
916 ↗(On Diff #69430)

I'd use this wording:

'%0' is not a recognized builtin
919 ↗(On Diff #69430)

Generally notes are attached to other source locations, which we don't have in this case. I'd replace this note with a second diagnostic with an extra clause:

def warn_pragma_intrinsic_builtin_suggest : Warning<
  "'%0' is not a recognized builtin; consider including <intrin.h> to access non-builtin intrinsics">;

If you search for "suggest" in the diagnostic file, you can see other instances of this.

agutowski updated this revision to Diff 69605.Aug 29 2016, 1:04 PM

Changed warning messages

agutowski marked 2 inline comments as done.Aug 29 2016, 1:07 PM
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman added inline comments.
include/clang/Basic/DiagnosticParseKinds.td
918 ↗(On Diff #69605)

I would combine this with the above and use %select to decide whether to include the "consider including" bit. aka, "%0 is not a recognized builtin%select{|; consider including <intrin.h> to access non-builtin intrinsics"}1".

lib/Parse/ParsePragma.cpp
2148 ↗(On Diff #69605)
  • tells the compiler
  • of the function
2150 ↗(On Diff #69605)

pragma -> #pragma

2157 ↗(On Diff #69605)

Not for your patch, but I wish we could use the balanced delimiter tracker for parsing pragmas.

2164 ↗(On Diff #69605)

Is this safe to rely on? I'm not familiar with how we do our intrinsics, but it's spelled __INTRIN_H_ in MSVC 2015, but perhaps we only care about intrin.h from Clang?

2169–2174 ↗(On Diff #69605)

Should elide braces here.

agutowski added inline comments.Aug 29 2016, 3:30 PM
lib/Parse/ParsePragma.cpp
2164 ↗(On Diff #69605)

I guess we only care about intrin.h from Clang - as far as I can see, MSVC's intrin.h contains only declarations, so including it won't change anything most of the time if the intrinsic isn't implemented in Clang.

agutowski updated this revision to Diff 69632.Aug 29 2016, 4:11 PM

Changed warning template to use select, fixed some mistakes in the comments.

agutowski marked 4 inline comments as done.Aug 29 2016, 4:13 PM
aaron.ballman accepted this revision.Aug 30 2016, 11:49 AM
aaron.ballman edited edge metadata.

LGTM, but you should wait for @rnk to accept as well.

This revision is now accepted and ready to land.Aug 30 2016, 11:49 AM
rnk edited edge metadata.Aug 30 2016, 12:59 PM

One buglet, otherwise looks good.

lib/Parse/ParsePragma.cpp
2169 ↗(On Diff #69632)

This doesn't seem like the right test. I think '1' is a valid builtin. This should probably be != 0. __builtin_atan2 looks like it has builtin id 1, and you can use that to test.

agutowski updated this revision to Diff 69767.Aug 30 2016, 3:16 PM
agutowski edited edge metadata.

Fixed checking if the function is an intrinsic. Updated getBuiltinID description.

agutowski updated this revision to Diff 69768.Aug 30 2016, 3:23 PM

Fixed typo

agutowski marked an inline comment as done.Aug 30 2016, 3:32 PM
rnk accepted this revision.Aug 30 2016, 4:40 PM
rnk edited edge metadata.

lgtm

This revision was automatically updated to reflect the committed changes.