diff options
author | Chris B <chris.bieneman@me.com> | 2023-11-28 15:03:10 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 15:03:10 -0600 |
commit | d4626216943f8c4712bd17a709e439a0ffd0006b (patch) | |
tree | ae30c4f8d0fea79807fa00b9fa731dc660be320d /clang/lib/Parse/ParseDecl.cpp | |
parent | ed27a4edb03809f0fe38f780765acfb97346c127 (diff) | |
download | llvm-d4626216943f8c4712bd17a709e439a0ffd0006b.zip llvm-d4626216943f8c4712bd17a709e439a0ffd0006b.tar.gz llvm-d4626216943f8c4712bd17a709e439a0ffd0006b.tar.bz2 |
[HLSL] Parameter modifier parsing and AST (#72139)
This change implements parsing for HLSL's parameter modifier keywords
`in`, `out` and `inout`. Because HLSL doesn't support references or
pointers, these keywords are used to allow parameters to be passed in
and out of functions.
This change only implements the parsing and AST support. In the HLSL
ASTs we represent `out` and `inout` parameters as references, and we
implement the semantics of by-value passing during IR generation.
In HLSL parameters marked `out` and `inout` are ambiguous in function
declarations, and `in`, `out` and `inout` may be ambiguous at call
sites.
This means a function may be defined as `fn(in T)` and `fn(inout T)` or
`fn(out T)`, but not `fn(inout T)` and `fn(out T)`. If a funciton `fn`
is declared with `in` and `inout` or `out` arguments, the call will be
ambiguous the same as a C++ call would be ambiguous given declarations
`fn(T)` and `fn(T&)`.
Fixes #59849
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 8cb5b09..ece3698 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4514,6 +4514,9 @@ void Parser::ParseDeclarationSpecifiers( break; case tok::kw_groupshared: + case tok::kw_in: + case tok::kw_inout: + case tok::kw_out: // NOTE: ParseHLSLQualifiers will consume the qualifier token. ParseHLSLQualifiers(DS.getAttributes()); continue; @@ -5550,7 +5553,6 @@ bool Parser::isTypeSpecifierQualifier() { case tok::kw___read_write: case tok::kw___write_only: case tok::kw___funcref: - case tok::kw_groupshared: return true; case tok::kw_private: @@ -5559,6 +5561,13 @@ bool Parser::isTypeSpecifierQualifier() { // C11 _Atomic case tok::kw__Atomic: return true; + + // HLSL type qualifiers + case tok::kw_groupshared: + case tok::kw_in: + case tok::kw_inout: + case tok::kw_out: + return getLangOpts().HLSL; } } @@ -6058,6 +6067,9 @@ void Parser::ParseTypeQualifierListOpt( break; case tok::kw_groupshared: + case tok::kw_in: + case tok::kw_inout: + case tok::kw_out: // NOTE: ParseHLSLQualifiers will consume the qualifier token. ParseHLSLQualifiers(DS.getAttributes()); continue; |