This is an archive of the discontinued LLVM Phabricator instance.

[Sema][HLSL] Consolidate handling of HLSL attributes
ClosedPublic

Authored by bogner on Aug 24 2023, 6:25 PM.

Details

Summary

This moves the sema checking of the entrypoint sensitive HLSL
attributes all into one place. This ended up being kind of large for a
couple of reasons:

  • I had to move the call to CheckHLSLEntryPoint later in ActOnFunctionDeclarator so that we do this after redeclarations and have access to all of the attributes.
  • We need to transfer the target shader stage onto the specified entry point before doing the checking.
  • I removed "library" from the HLSLShader attribute value enum and just go through a string to convert from the triple - the other way was confusing and brittle.

Diff Detail

Event Timeline

bogner created this revision.Aug 24 2023, 6:25 PM
bogner requested review of this revision.Aug 24 2023, 6:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2023, 6:25 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
python3kgae accepted this revision.Aug 24 2023, 8:04 PM
This revision is now accepted and ready to land.Aug 24 2023, 8:04 PM
bogner updated this revision to Diff 553395.Aug 25 2023, 12:36 AM

Broke out a couple of semi-unrelated changes

aaron.ballman added inline comments.Aug 28 2023, 9:24 AM
clang/include/clang/Sema/Sema.h
3016–3019

Any const correctness you can add here to the pointees would be appreciated.

clang/lib/Sema/SemaDecl.cpp
12375

const auto *

12395–12398

Hmmm, is this going to be done as a follow-up relatively soon? report_fatal_error isn't acceptable in lieu of actual diagnostic reporting, so this should either be fixed in this patch or Really Soon After™ it lands.

12420

const auto *

12423

This should be part of the diagnostic wording itself (using %select) rather than passed in as a string argument. The same suggestion applies elsewhere -- we want to keep English strings out of the streaming arguments as much as possible to make localization efforts possible.

12439–12440

const the pointees?

bogner added inline comments.Aug 28 2023, 9:48 AM
clang/lib/Sema/SemaDecl.cpp
12395–12398

Yeah, I'm happy to go and tackle that this week. Really I want an assert/unreachable here but since it is in fact reachable at the moment this seemed better as a temporary fix. Note that before this patch we just index out of bounds of an array and get all of the fun benefits of UB.

12423

That's a good point, though in this case the words we want are the value to the compute(...) attribute or part of the triple, so translating them wouldn't really make sense. Would it be better to do something using ConvertShaderTypeToStr? Also I'll probably update the error message text to quote the other use of ConvertShaderTypeToStr so it's clear that it isn't just a random word.

bogner marked 2 inline comments as not done.Aug 28 2023, 9:48 AM
aaron.ballman added inline comments.Aug 28 2023, 11:00 AM
clang/lib/Sema/SemaDecl.cpp
12395–12398

SGTM to do it as a follow-up -- this is better than the out of bounds indexing!

12423

Doing something like ConvertShaderTypeToStr() would work as well -- it's mostly an effort to avoid having random string literals with the calls to Diag().

bogner updated this revision to Diff 554044.Aug 28 2023, 1:59 PM
  • Now with more const
  • Added DiagnoseHLSLAttrStageMismatch and avoided using raw strings in diagnostics
bogner marked 7 inline comments as done.Aug 28 2023, 1:59 PM
bogner added inline comments.Aug 29 2023, 8:12 AM
clang/lib/Sema/SemaDecl.cpp
12395–12398
This revision was automatically updated to reflect the committed changes.