diff options
author | Chris B <chris.bieneman@me.com> | 2024-02-15 14:58:06 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-15 14:58:06 -0600 |
commit | 5c57fd717d5d6a285efeb8402c6fe0c8f70592f3 (patch) | |
tree | cd4b71c05decd37f40090f06456570ad485e044e /clang/lib/Sema/SemaChecking.cpp | |
parent | edfc859af89e44207bf499b5d702aa26a7357da4 (diff) | |
download | llvm-5c57fd717d5d6a285efeb8402c6fe0c8f70592f3.zip llvm-5c57fd717d5d6a285efeb8402c6fe0c8f70592f3.tar.gz llvm-5c57fd717d5d6a285efeb8402c6fe0c8f70592f3.tar.bz2 |
[HLSL] Vector standard conversions (#71098)
HLSL supports vector truncation and element conversions as part of
standard conversion sequences. The vector truncation conversion is a C++
second conversion in the conversion sequence. If a vector truncation is
in a conversion sequence an element conversion may occur after it before
the standard C++ third conversion.
Vector element conversions can be boolean conversions, floating point or
integral conversions or promotions.
[HLSL Draft
Specification](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf)
---------
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index afe2673..8e76338 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -15676,11 +15676,18 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T, if (S.SourceMgr.isInSystemMacro(CC)) return; return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_vector_scalar); + } else if (S.getLangOpts().HLSL && + Target->castAs<VectorType>()->getNumElements() < + Source->castAs<VectorType>()->getNumElements()) { + // Diagnose vector truncation but don't return. We may also want to + // diagnose an element conversion. + DiagnoseImpCast(S, E, T, CC, diag::warn_hlsl_impcast_vector_truncation); } // If the vector cast is cast between two vectors of the same size, it is - // a bitcast, not a conversion. - if (S.Context.getTypeSize(Source) == S.Context.getTypeSize(Target)) + // a bitcast, not a conversion, except under HLSL where it is a conversion. + if (!S.getLangOpts().HLSL && + S.Context.getTypeSize(Source) == S.Context.getTypeSize(Target)) return; Source = cast<VectorType>(Source)->getElementType().getTypePtr(); |