This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP51]Initial parsing/sema for append_args clause for 'declare variant'
ClosedPublic

Authored by mikerice on Oct 14 2021, 4:58 PM.

Details

Summary

Adds initial parsing and sema for the 'append_args' clause.

Note that an AST clause is not created as it instead adds its values
to the OMPDeclareVariantAttr.

Diff Detail

Event Timeline

mikerice created this revision.Oct 14 2021, 4:58 PM
mikerice requested review of this revision.Oct 14 2021, 4:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2021, 4:58 PM

I'm not super familiar with OpenMP code, but are changes needed for AST serialization as well (so that PCH, modules, etc continue to work properly)?

clang/include/clang/Basic/DiagnosticParseKinds.td
1363

I'm hoping this diagnostic makes more sense in situ because I'm not certain what it's telling me. append-op is not a term of art we've used elsewhere, is there a better term we could use or will this be familiar to OpenMP users?

clang/lib/Parse/ParseOpenMP.cpp
1451

Do we need to do any error recovery here for the parser to get back to a known-perhaps-good state?

1501

Because we already know the token is an identifier, we don't need to go back to the preprocessor for this (and that particular interface involves memory allocations because it uses std::string). I think you can do: Tok.getIdentifierInfo()->isStr("target") instead.

1544

Same suggestion here as in the previous function.

1557–1558

Maybe add some comments here about why this is correct and not diagnosed?

1573–1574

Does this need to be a while loop because OpenMP is weird about SkipUntil?

clang/lib/Sema/SemaOpenMP.cpp
7015–7017
7018–7020

Why is this valid? (Functions without prototypes do specify their return type information btw, so it's very weird that we convert this to return void when ginning up a prototype).

7022–7023

I'd like an assertion that PTy is nonnull.

7029

If the lookup fails, silently using a void pointer type is okay?

mikerice marked 6 inline comments as done.Oct 19 2021, 3:29 PM

Thanks for the review! As far as serialization goes, yes we need it, and the OpenMP tests test this is the ast print and codegen tests. This patch doesn't need anything special since it is just adding another field to the attribute which is serialized correctly with tablegen code afaik.

clang/include/clang/Basic/DiagnosticParseKinds.td
1363

That is from the syntax in the spec: https://www.openmp.org/spec-html/5.1/openmpsu29.html#x46-450002.3.5. Open to suggestions but I don't know what would be better.

clang/lib/Parse/ParseOpenMP.cpp
1451

You mean get back to a good state inside the directive? It seems we mostly just skip out of the OpenMP directives when there is an error like this does.

1573–1574

I think this one is okay. It will stop at the r_paren and consume it here. The caller will skip the tokens until the end of the directive.

clang/lib/Sema/SemaOpenMP.cpp
7018–7020

You're right the return type is wrong here. Thinking about this more though, I don't think we really need to handle the unprototyped case. When append_args are used the variant must be prototyped and contain the extra omp_interop_t parameters. That means we'd be matching a prototyped function with an unprototyped function where we treat it as (void). That would handle only cases where the variant had only interop parameters... seems not useful. I'll instead give an error for the unprototyped case.

mikerice updated this revision to Diff 380795.Oct 19 2021, 3:32 PM

Addressed review comments.

Thanks for the review! As far as serialization goes, yes we need it, and the OpenMP tests test this is the ast print and codegen tests. This patch doesn't need anything special since it is just adding another field to the attribute which is serialized correctly with tablegen code afaik.

Hmmm, I took a look through the serialization code that includes OMP.inc and I don't see anything to suggest that this addition causes a change to the AST version. So the situation I'm worried about is where new Clang generates a PCH file with this feature and then hands it to an older Clang without this feature. If you think we have sufficient test coverage for this sort of thing, then okay. But if you think there's not sufficient test coverage, this might be worth a follow-up patch to improve test coverage in general.

The rest of my comments are mostly nits because I'm not really an expert in OpenMP. :-)

clang/include/clang/Basic/DiagnosticParseKinds.td
1363

We usually try to only use grammar terms when they make sensible English prose by removing the hyphens, so I'm thinking of something along the lines of:

unexpected operation specified in 'append_args' clause, expected 'interop'

clang/include/clang/Basic/DiagnosticSemaKinds.td
10752
10754
clang/lib/Parse/ParseOpenMP.cpp
1451

Oh yeah, I see, this skips later, sorry for the noise.

clang/lib/Sema/SemaOpenMP.cpp
7018–7020

+1 -- unprototyped functions have been deprecated for longer than some WG14 committee members have been alive; I think it's a feature to not support them in new offerings.

ABataev added inline comments.Oct 21 2021, 4:39 AM
clang/include/clang/Parse/Parser.h
3209

parseOpenMPAppendArgs

clang/lib/Parse/ParseOpenMP.cpp
1493

Better to introduce an enum here and return it as a result. Or return Optional<OMPDeclareVariantAttr::InteropType>

clang/test/OpenMP/declare_variant_clauses_messages.cpp
17–87

Add (a) test(s) for varargs functions. Also, what about templates, member functions, static member functions, virtual functions, pure virtual functions?

mikerice marked 5 inline comments as done.Oct 21 2021, 4:31 PM
mikerice added inline comments.
clang/test/OpenMP/declare_variant_clauses_messages.cpp
17–87

Added positive and negative tests for templates, member functions, and static member functions. Virtual functions are not allowed for declare variant so I didn't add anything for those. Added a diagnostic for varargs with append_args since it is not clear how that would work or what it means.

mikerice updated this revision to Diff 381428.Oct 21 2021, 4:35 PM

Addressed comments.

ABataev added inline comments.Oct 22 2021, 6:24 AM
clang/lib/Parse/ParseOpenMP.cpp
1496–1497

Can you worjk with OMPDeclareVariantAttr::InteropType type var instead of using these vars?

clang/test/OpenMP/declare_variant_clauses_messages.cpp
17–87

Can you add tests that (pure) virtual functions are correctly rejected (if don't have ones)?

mikerice updated this revision to Diff 381689.Oct 22 2021, 5:49 PM
mikerice marked an inline comment as done.

Added tests for virtual and pure virtual functions.

mikerice added inline comments.Oct 22 2021, 5:50 PM
clang/lib/Parse/ParseOpenMP.cpp
1496–1497

Could do that, but it seems to make the code uglier. Instead of

if (IsTarget)
  Diag
isTarget = true;

We'd get:

if (IT == OMPDeclareVariantAttr::Target ||          
    IT == OMPDeclareVariantAttr::Target_TargetSync)
  Diag
if (IT == OMPDeclareVariantAttr::TargetSync)
  IT = OMPDeclareVariantAttr::Target_TargetSync;
else    
  IT = OMPDeclareVariantAttr::Target;

And again for the targetsync case.

Plus there is no unset value in OMPDeclareVariantAttr::Interop type so we'd need to add one (complicating other code) or initialize it with (OMPDeclareVariantAttr::InteropType)-1 or something.

This revision is now accepted and ready to land.Oct 25 2021, 6:29 AM
This revision was landed with ongoing or failed builds.Oct 25 2021, 9:43 AM
This revision was automatically updated to reflect the committed changes.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 25 2021, 9:43 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript