Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HLSL] Vector Usual Arithmetic Conversions #108659

Merged

Conversation

llvm-beanz
Copy link
Collaborator

HLSL has a different set of usual arithmetic conversions for vector types to resolve a common type for binary operator expressions.

This PR implements the current spec proposal from: microsoft/hlsl-specs#311

There is one case that may need additional handling for implicitly truncating vector<T,1> to T early to allow other transformations.

Fixes #106253

HLSL has a different set of usual arithmetic conversions for vector
types to resolve a common type for binary operator expressions.

This PR implements the current spec proposal from:
microsoft/hlsl-specs#311

There is one case that may need additional handling for implicitly
truncating `vector<T,1>` to `T` early to allow other transformations.

Fixes llvm#106253
@llvm-beanz llvm-beanz added the HLSL HLSL Language Support label Sep 13, 2024
@llvm-beanz llvm-beanz requested a review from Endilll as a code owner September 13, 2024 22:57
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-hlsl

Author: Chris B (llvm-beanz)

Changes

HLSL has a different set of usual arithmetic conversions for vector types to resolve a common type for binary operator expressions.

This PR implements the current spec proposal from: microsoft/hlsl-specs#311

There is one case that may need additional handling for implicitly truncating vector&lt;T,1&gt; to T early to allow other transformations.

Fixes #106253


Patch is 37.87 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/108659.diff

7 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3)
  • (modified) clang/include/clang/Driver/Options.td (+1-1)
  • (modified) clang/include/clang/Sema/Sema.h (+2-1)
  • (modified) clang/include/clang/Sema/SemaHLSL.h (+5)
  • (modified) clang/lib/Sema/SemaExpr.cpp (+13-2)
  • (modified) clang/lib/Sema/SemaHLSL.cpp (+188)
  • (added) clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl (+379)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index bf97d939f02ce9..ff5a742ee9bf20 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12383,6 +12383,9 @@ def err_hlsl_operator_unsupported : Error<
 
 def err_hlsl_param_qualifier_mismatch :
   Error<"conflicting parameter qualifier %0 on parameter %1">;
+def err_hlsl_vector_compound_assignment_truncation : Error<
+  "left hand operand of type %0 to compound assignment cannot be truncated "
+  "when used with right hand operand of type %1">;
 
 def warn_hlsl_impcast_vector_truncation : Warning<
   "implicit conversion truncates vector: %0 to %1">, InGroup<Conversion>;
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index dc8bfc69e9889b..f5a7e3bbc21742 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2957,7 +2957,7 @@ def flax_vector_conversions_EQ : Joined<["-"], "flax-vector-conversions=">, Grou
                     "LangOptions::LaxVectorConversionKind::Integer",
                     "LangOptions::LaxVectorConversionKind::All"]>,
   MarshallingInfoEnum<LangOpts<"LaxVectorConversions">,
-                      open_cl.KeyPath #
+                      !strconcat("(", open_cl.KeyPath, " || ", hlsl.KeyPath, ")") #
                           " ? LangOptions::LaxVectorConversionKind::None" #
                           " : LangOptions::LaxVectorConversionKind::All">;
 def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group<f_Group>,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 99eef472223a00..1762a9ab77d752 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7423,7 +7423,8 @@ class Sema final : public SemaBase {
                                               SourceLocation Loc,
                                               BinaryOperatorKind Opc);
   QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
-                                      SourceLocation Loc);
+                                      SourceLocation Loc,
+                                      BinaryOperatorKind Opc);
 
   /// Context in which we're performing a usual arithmetic conversion.
   enum ArithConvKind {
diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h
index 64b39ca7712eeb..5a18522738df2b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -62,6 +62,11 @@ class SemaHLSL : public SemaBase {
       std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages);
   void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU);
 
+  QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS,
+                                       QualType LHSType, QualType RHSType,
+                                       bool IsCompAssign);
+  void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
+
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..a43248b546e841 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10131,6 +10131,10 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
   const VectorType *RHSVecType = RHSType->getAs<VectorType>();
   assert(LHSVecType || RHSVecType);
 
+  if (getLangOpts().HLSL)
+    return HLSL().handleVectorBinOpConversion(LHS, RHS, LHSType, RHSType,
+                                              IsCompAssign);
+
   // AltiVec-style "vector bool op vector bool" combinations are allowed
   // for some operators but not others.
   if (!AllowBothBool && LHSVecType &&
@@ -12861,7 +12865,8 @@ static void diagnoseXorMisusedAsPow(Sema &S, const ExprResult &XorLHS,
 }
 
 QualType Sema::CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
-                                          SourceLocation Loc) {
+                                          SourceLocation Loc,
+                                          BinaryOperatorKind Opc) {
   // Ensure that either both operands are of the same vector type, or
   // one operand is of a vector type and the other is of its element type.
   QualType vType = CheckVectorOperands(LHS, RHS, Loc, false,
@@ -12881,6 +12886,12 @@ QualType Sema::CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
   if (!getLangOpts().CPlusPlus &&
       !(isa<ExtVectorType>(vType->getAs<VectorType>())))
     return InvalidLogicalVectorOperands(Loc, LHS, RHS);
+  if (getLangOpts().HLSL &&
+      getLangOpts().getHLSLVersion() >= LangOptionsBase::HLSL_2021) {
+    (void)InvalidOperands(Loc, LHS, RHS);
+    HLSL().emitLogicalOperatorFixIt(LHS.get(), RHS.get(), Opc);
+    return QualType();
+  }
 
   return GetSignedVectorType(LHS.get()->getType());
 }
@@ -13052,7 +13063,7 @@ inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS,
   // Check vector operands differently.
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType())
-    return CheckVectorLogicalOperands(LHS, RHS, Loc);
+    return CheckVectorLogicalOperands(LHS, RHS, Loc, Opc);
 
   bool EnumConstantInBoolContext = false;
   for (const ExprResult &HS : {LHS, RHS}) {
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 527718c8e7e324..890cfb09ab5142 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -356,6 +356,194 @@ void SemaHLSL::DiagnoseAttrStageMismatch(
       << (AllowedStages.size() != 1) << join(StageStrings, ", ");
 }
 
+template <CastKind Kind>
+static void castVector(Sema &S, ExprResult &E, QualType &Ty, unsigned Sz) {
+  if (const auto *VTy = Ty->getAs<VectorType>())
+    Ty = VTy->getElementType();
+  Ty = S.getASTContext().getExtVectorType(Ty, Sz);
+  E = S.ImpCastExprToType(E.get(), Ty, Kind);
+}
+
+template <CastKind Kind>
+static QualType castElement(Sema &S, ExprResult &E, QualType Ty) {
+  E = S.ImpCastExprToType(E.get(), Ty, Kind);
+  return Ty;
+}
+
+static QualType handleFloatVectorBinOpConversion(
+    Sema &SemaRef, ExprResult &LHS, ExprResult &RHS, QualType LHSType,
+    QualType RHSType, QualType LElTy, QualType RElTy, bool IsCompAssign) {
+  bool LHSFloat = LElTy->isRealFloatingType();
+  bool RHSFloat = RElTy->isRealFloatingType();
+
+  if (LHSFloat && RHSFloat) {
+    if (IsCompAssign ||
+        SemaRef.getASTContext().getFloatingTypeOrder(LElTy, RElTy) > 0)
+      return castElement<CK_FloatingCast>(SemaRef, RHS, LHSType);
+
+    return castElement<CK_FloatingCast>(SemaRef, LHS, RHSType);
+  }
+
+  if (LHSFloat)
+    return castElement<CK_IntegralToFloating>(SemaRef, RHS, LHSType);
+
+  assert(RHSFloat);
+  if (IsCompAssign)
+    return castElement<clang::CK_FloatingToIntegral>(SemaRef, RHS, LHSType);
+
+  return castElement<CK_IntegralToFloating>(SemaRef, LHS, RHSType);
+}
+
+static QualType handleIntegerVectorBinOpConversion(
+    Sema &SemaRef, ExprResult &LHS, ExprResult &RHS, QualType LHSType,
+    QualType RHSType, QualType LElTy, QualType RElTy, bool IsCompAssign) {
+
+  int IntOrder = SemaRef.Context.getIntegerTypeOrder(LElTy, RElTy);
+  bool LHSSigned = LElTy->hasSignedIntegerRepresentation();
+  bool RHSSigned = RElTy->hasSignedIntegerRepresentation();
+  auto &Ctx = SemaRef.getASTContext();
+
+  // If both types have the same signedness, use the higher ranked type.
+  if (LHSSigned == RHSSigned) {
+    if (IsCompAssign || IntOrder >= 0)
+      return castElement<CK_IntegralCast>(SemaRef, RHS, LHSType);
+
+    return castElement<CK_IntegralCast>(SemaRef, LHS, RHSType);
+  }
+
+  // If the unsigned type has greater than or equal rank of the signed type, use
+  // the unsigned type.
+  if (IntOrder != (LHSSigned ? 1 : -1)) {
+    if (IsCompAssign || RHSSigned)
+      return castElement<CK_IntegralCast>(SemaRef, RHS, LHSType);
+    return castElement<CK_IntegralCast>(SemaRef, LHS, RHSType);
+  }
+
+  // At this point the signed type has higher rank than the unsigned type, which
+  // means it will be the same size or bigger. If the signed type is bigger, it
+  // can represent all the values of the unsigned type, so select it.
+  if (Ctx.getIntWidth(LElTy) != Ctx.getIntWidth(RElTy)) {
+    if (IsCompAssign || LHSSigned)
+      return castElement<CK_IntegralCast>(SemaRef, RHS, LHSType);
+    return castElement<CK_IntegralCast>(SemaRef, LHS, RHSType);
+  }
+
+  // This is a bit of an odd duck case in HLSL. It shouldn't happen, but can due
+  // to C/C++ leaking through. The place this happens today is long vs long
+  // long. When arguments are vector<unsigned long, N> and vector<long long, N>,
+  // the long long has higher rank than long even though they are the same size.
+
+  // If this is a compound assignment cast the right hand side to the left hand
+  // side's type.
+  if (IsCompAssign)
+    return castElement<CK_IntegralCast>(SemaRef, RHS, LHSType);
+
+  // If this isn't a compound assignment we convert to unsigned long long.
+  QualType ElTy = Ctx.getCorrespondingUnsignedType(LHSSigned ? LElTy : RElTy);
+  QualType NewTy = Ctx.getExtVectorType(
+      ElTy, RHSType->castAs<VectorType>()->getNumElements());
+  (void)castElement<CK_IntegralCast>(SemaRef, RHS, NewTy);
+
+  return castElement<CK_IntegralCast>(SemaRef, LHS, NewTy);
+}
+
+static CastKind getScalarCastKind(ASTContext &Ctx, QualType DestTy,
+                                  QualType SrcTy) {
+  if (DestTy->isRealFloatingType() && SrcTy->isRealFloatingType())
+    return CK_FloatingCast;
+  if (DestTy->isIntegralType(Ctx) && SrcTy->isIntegralType(Ctx))
+    return CK_IntegralCast;
+  if (DestTy->isRealFloatingType())
+    return CK_IntegralToFloating;
+  assert(SrcTy->isRealFloatingType() && DestTy->isIntegralType(Ctx));
+  return CK_FloatingToIntegral;
+}
+
+QualType SemaHLSL::handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS,
+                                               QualType LHSType,
+                                               QualType RHSType,
+                                               bool IsCompAssign) {
+  const auto *LVecTy = LHSType->getAs<VectorType>();
+  const auto *RVecTy = RHSType->getAs<VectorType>();
+  auto &Ctx = getASTContext();
+
+  // If the LHS is not a vector and this is a compound assignment, we truncate
+  // the argument to a scalar then convert it to the LHS's type.
+  if (!LVecTy && IsCompAssign) {
+    QualType RElTy = RHSType->castAs<VectorType>()->getElementType();
+    RHS = SemaRef.ImpCastExprToType(RHS.get(), RElTy, CK_HLSLVectorTruncation);
+    RHSType = RHS.get()->getType();
+    if (Ctx.hasSameUnqualifiedType(LHSType, RHSType))
+      return LHSType;
+    RHS = SemaRef.ImpCastExprToType(RHS.get(), LHSType,
+                                    getScalarCastKind(Ctx, LHSType, RHSType));
+    return LHSType;
+  }
+
+  unsigned EndSz = std::numeric_limits<unsigned>::max();
+  unsigned LSz = 0;
+  if (LVecTy)
+    LSz = EndSz = LVecTy->getNumElements();
+  if (RVecTy)
+    EndSz = std::min(RVecTy->getNumElements(), EndSz);
+  assert(EndSz != std::numeric_limits<unsigned>::max() &&
+         "one of the above should have had a value");
+
+  // In a compound assignment, the left operand does not change type, the right
+  // operand is converted to the type of the left operand.
+  if (IsCompAssign && LSz != EndSz) {
+    Diag(LHS.get()->getBeginLoc(),
+         diag::err_hlsl_vector_compound_assignment_truncation)
+        << LHSType << RHSType;
+    return QualType();
+  }
+
+  if (RVecTy && RVecTy->getNumElements() > EndSz)
+    castVector<CK_HLSLVectorTruncation>(SemaRef, RHS, RHSType, EndSz);
+  if (!IsCompAssign && LVecTy && LVecTy->getNumElements() > EndSz)
+    castVector<CK_HLSLVectorTruncation>(SemaRef, LHS, LHSType, EndSz);
+
+  if (!RVecTy)
+    castVector<CK_VectorSplat>(SemaRef, RHS, RHSType, EndSz);
+  if (!IsCompAssign && !LVecTy)
+    castVector<CK_VectorSplat>(SemaRef, LHS, LHSType, EndSz);
+
+  // If we're at the same type after resizing we can stop here.
+  if (Ctx.hasSameUnqualifiedType(LHSType, RHSType))
+    return Ctx.getCommonSugaredType(LHSType, RHSType);
+
+  QualType LElTy = LHSType->castAs<VectorType>()->getElementType();
+  QualType RElTy = RHSType->castAs<VectorType>()->getElementType();
+
+  // Handle conversion for floating point vectors.
+  if (LElTy->isRealFloatingType() || RElTy->isRealFloatingType())
+    return handleFloatVectorBinOpConversion(SemaRef, LHS, RHS, LHSType, RHSType,
+                                            LElTy, RElTy, IsCompAssign);
+
+  assert(LElTy->isIntegralType(Ctx) && RElTy->isIntegralType(Ctx) &&
+         "HLSL Vectors can only contain integer or floating point types");
+  return handleIntegerVectorBinOpConversion(SemaRef, LHS, RHS, LHSType, RHSType,
+                                            LElTy, RElTy, IsCompAssign);
+}
+
+void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS,
+                                        BinaryOperatorKind Opc) {
+  assert((Opc == BO_LOr || Opc == BO_LAnd) &&
+         "Called with non-logical operator");
+  llvm::SmallVector<char, 256> Buff;
+  llvm::raw_svector_ostream OS(Buff);
+  PrintingPolicy PP(SemaRef.getLangOpts());
+  StringRef NewFnName = Opc == BO_LOr ? "or" : "and";
+  OS << NewFnName << "(";
+  LHS->printPretty(OS, nullptr, PP);
+  OS << ", ";
+  RHS->printPretty(OS, nullptr, PP);
+  OS << ")";
+  SourceRange FullRange = SourceRange(LHS->getBeginLoc(), RHS->getEndLoc());
+  SemaRef.Diag(LHS->getBeginLoc(), diag::note_function_suggestion)
+      << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str());
+}
+
 void SemaHLSL::handleNumThreadsAttr(Decl *D, const ParsedAttr &AL) {
   llvm::VersionTuple SMVersion =
       getASTContext().getTargetInfo().getTriple().getOSVersion();
diff --git a/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl b/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl
new file mode 100644
index 00000000000000..6138169e299fd7
--- /dev/null
+++ b/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl
@@ -0,0 +1,379 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type %s -DERRORS -Wconversion -Wdouble-promotion -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type %s -DERRORS -Wconversion -Wdouble-promotion -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type %s -ast-dump | FileCheck %s
+
+//----------------------------------------------------------------------------//
+// Case 1: float4 * int4 and inverse.
+//
+// In both cases here the int is converted to a float and the computation
+// produces a float value.
+//----------------------------------------------------------------------------//
+
+// CHECK-LABEL: FunctionDecl {{.*}} used f4f4i4 'float4 (float4, int4)'
+// CHECK: BinaryOperator {{.*}} 'float4':'vector<float, 4>' '*'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4':'vector<float, 4>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float4':'vector<float, 4>' lvalue ParmVar {{.*}} 'A' 'float4':'vector<float, 4>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4':'vector<float, 4>' <IntegralToFloating>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int4':'vector<int, 4>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'int4':'vector<int, 4>' lvalue ParmVar {{.*}} 'B' 'int4':'vector<int, 4>'
+export float4 f4f4i4(float4 A, int4 B) {
+  return A * B; // expected-warning{{implicit conversion from 'int4' (aka 'vector<int, 4>') to 'float4' (aka 'vector<float, 4>') may lose precision}}
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} used f4i4f4 'float4 (float4, int4)'
+// CHECK: BinaryOperator {{.*}} 'float4':'vector<float, 4>' '*'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4':'vector<float, 4>' <IntegralToFloating>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int4':'vector<int, 4>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'int4':'vector<int, 4>' lvalue ParmVar {{.*}} 'B' 'int4':'vector<int, 4>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4':'vector<float, 4>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float4':'vector<float, 4>' lvalue ParmVar {{.*}} 'A' 'float4':'vector<float, 4>'
+export float4 f4i4f4(float4 A, int4 B) {
+  return B * A; // expected-warning{{implicit conversion from 'int4' (aka 'vector<int, 4>') to 'float4' (aka 'vector<float, 4>') may lose precision}}
+}
+
+//----------------------------------------------------------------------------//
+// Case 2: float4 * int2 and inverse.
+//
+// In both cases the float vector is trunctated to a float2 and the integer
+// vector is converted to a float2.
+//----------------------------------------------------------------------------//
+
+// CHECK-LABEL: FunctionDecl {{.*}} used f2f4i2 'float2 (float4, int2)'
+// CHECK: BinaryOperator {{.*}} 'vector<float, 2>' '*'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 2>' <HLSLVectorTruncation>
+// CHECK-NEXT: ImplicitCastExpr {{.*}}'float4':'vector<float, 4>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float4':'vector<float, 4>' lvalue ParmVar {{.*}} 'A' 'float4':'vector<float, 4>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 2>' <IntegralToFloating>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int2':'vector<int, 2>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'int2':'vector<int, 2>' lvalue ParmVar {{.*}} 'B' 'int2':'vector<int, 2>'
+export float2 f2f4i2(float4 A, int2 B) {
+  // expected-warning@#f2f4i2 {{implicit conversion from 'int2' (aka 'vector<int, 2>') to 'vector<float, 2>' (vector of 2 'float' values) may lose precision}}
+  // expected-warning@#f2f4i2 {{implicit conversion truncates vector: 'float4' (aka 'vector<float, 4>') to 'vector<float, 2>' (vector of 2 'float' values)}}
+  return A * B; // #f2f4i2
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} used f2i2f4 'float2 (float4, int2)'
+// CHECK: BinaryOperator {{.*}} 'vector<float, 2>' '*'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 2>' <IntegralToFloating>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int2':'vector<int, 2>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'int2':'vector<int, 2>' lvalue ParmVar {{.*}} 'B' 'int2':'vector<int, 2>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 2>' <HLSLVectorTruncation>
+// CHECK-NEXT: ImplicitCastExpr {{.*}}'float4':'vector<float, 4>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float4':'vector<float, 4>' lvalue ParmVar {{.*}} 'A' 'float4':'vector<float, 4>'
+export float2 f2i2f4(float4 A, int2 B) {
+  // expected-warning@#f2i2f4 {{implicit conversion from 'int2' (aka 'vector<int, 2>') to 'vector<float, 2>' (vector of 2 'float' values) may lose precision}}
+  // expected-warning@#f2i2f4 {{implicit conversion truncates vector: 'float4' (aka 'vector<float, 4>') to 'vector<float, 2>' (vector of 2 'float' values)}}
+  return B * A; // #f2i2f4
+}
+
+//----------------------------------------------------------------------------//
+// Case 3: Integers of mismatched sign, equivalent size, but the unsigned type
+// has lower conversion rank.
+//
+// This is the odd-ball case for HLSL that isn't really in spec, but we should
+// handle gracefully. The lower-ranked unsigned type is converted to the
+// equivalent unsigned type of higher rank, and the signed type is also
+// converted to that unsigned type (meaning `unsigned long` becomes `unsinged
+// long long`, and `long long` becomes `unsigned long long`).
+//----------------------------------------------------------------------------//
+
+// CHECK-LABEL: FunctionDecl {{.*}} used wierdo 'int4 (vector<unsigned long, 4>, vector<long long, 4>)'
+// CHECK: BinaryOperator {{.*}} 'vector<unsigned long long, 4>' '*'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<unsigned long long, 4>' <IntegralCast>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<unsigned long, 4>' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr{{.*}} 'vector<unsigned long, 4>' lvalue ParmVar {{.*}} 'A' 'vector<unsigned long, 4>'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<unsigned long long, 4>' <IntegralCast>
+// CHECK-NEXT: ImplicitCastExpr{{.*}}> ...
[truncated]

Copy link
Contributor

@damyanp damyanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - reviewed mostly to see if I could read and get a high level gist of what it was doing. I'm afraid I've not carefully looked through the real meat of this change.

clang/lib/Sema/SemaExpr.cpp Show resolved Hide resolved
@@ -12881,6 +12886,12 @@ QualType Sema::CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
if (!getLangOpts().CPlusPlus &&
!(isa<ExtVectorType>(vType->getAs<VectorType>())))
return InvalidLogicalVectorOperands(Loc, LHS, RHS);
if (getLangOpts().HLSL &&
getLangOpts().getHLSLVersion() >= LangOptionsBase::HLSL_2021) {
(void)InvalidOperands(Loc, LHS, RHS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing away the return value here makes me uneasy, but as long as you know that InvalidOperands will always return QualType() it doesn't matter so much. I assume people working on this code have that pretty internalized as an idomatic convention.

clang/lib/Sema/SemaHLSL.cpp Show resolved Hide resolved
@llvm-beanz llvm-beanz merged commit e82b26a into llvm:main Sep 26, 2024
8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 27, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/8070

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 27, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-sles-build-only running on rocm-worker-hw-04-sles while building clang at step 6 "Add check check-clang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/7568

Here is the relevant piece of the build log for the reference
Step 6 (Add check check-clang) failure: test (failure)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 27, 2024

LLVM Buildbot has detected a new failure on builder clang-ve-ninja running on hpce-ve-main while building clang at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/12/builds/6689

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py ...' (failure)
...
[293/299] Linking CXX executable tools/clang/unittests/Serialization/SerializationTests
[294/299] Linking CXX executable tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests
[295/299] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests
[296/299] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests
[297/299] Linking CXX executable tools/clang/unittests/Interpreter/ClangReplInterpreterTests
[298/299] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests
[298/299] Running the Clang regression tests
-- Testing: 21110 tests, 48 workers --
llvm-lit: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using clang: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80..
FAIL: Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl (18730 of 21110)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
********************
Failed Tests (1):
  Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl


Testing Time: 55.24s

Total Discovered Tests: 38085
  Skipped          :    10 (0.03%)
  Unsupported      :  3778 (9.92%)
  Passed           : 34269 (89.98%)
  Expectedly Failed:    27 (0.07%)
  Failed           :     1 (0.00%)
FAILED: tools/clang/test/CMakeFiles/check-clang /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test/CMakeFiles/check-clang 
cd /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test && /home/buildbot/sandbox/bin/python3 /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/./bin/llvm-lit -sv --param USE_Z3_SOLVER=0 /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test
ninja: build stopped: subcommand failed.
make: *** [check-llvm] Error 1
['make', '-f', '/scratch/buildbot/bothome/clang-ve-ninja/llvm-zorg/zorg/buildbot/builders/annotated/ve-linux-steps.make', 'check-llvm', 'BUILDROOT=/scratch/buildbot/bothome/clang-ve-ninja/build'] exited with return code 2.
The build step threw an exception...
Traceback (most recent call last):
  File "../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py", line 47, in step
Step 8 (check-llvm) failure: check-llvm (failure)
...
[293/299] Linking CXX executable tools/clang/unittests/Serialization/SerializationTests
[294/299] Linking CXX executable tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests
[295/299] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests
[296/299] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests
[297/299] Linking CXX executable tools/clang/unittests/Interpreter/ClangReplInterpreterTests
[298/299] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests
[298/299] Running the Clang regression tests
-- Testing: 21110 tests, 48 workers --
llvm-lit: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using clang: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80..
FAIL: Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl (18730 of 21110)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
********************
Failed Tests (1):
  Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl


Testing Time: 55.24s

Total Discovered Tests: 38085
  Skipped          :    10 (0.03%)
  Unsupported      :  3778 (9.92%)
  Passed           : 34269 (89.98%)
  Expectedly Failed:    27 (0.07%)
  Failed           :     1 (0.00%)
FAILED: tools/clang/test/CMakeFiles/check-clang /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test/CMakeFiles/check-clang 
cd /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test && /home/buildbot/sandbox/bin/python3 /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/./bin/llvm-lit -sv --param USE_Z3_SOLVER=0 /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test
ninja: build stopped: subcommand failed.
make: *** [check-llvm] Error 1
['make', '-f', '/scratch/buildbot/bothome/clang-ve-ninja/llvm-zorg/zorg/buildbot/builders/annotated/ve-linux-steps.make', 'check-llvm', 'BUILDROOT=/scratch/buildbot/bothome/clang-ve-ninja/build'] exited with return code 2.
The build step threw an exception...
Traceback (most recent call last):
  File "../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py", line 47, in step

@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 27, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/6604

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 27, 2024

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building clang at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/10210

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 -internal-isystem /build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 -internal-isystem /build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 -internal-isystem /build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 -internal-isystem /build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************


llvm-beanz added a commit that referenced this pull request Sep 27, 2024
HLSL has a different set of usual arithmetic conversions for vector
types to resolve a common type for binary operator expressions.

This PR implements the current spec proposal from:
microsoft/hlsl-specs#311

There is one case that may need additional handling for implicitly
truncating vector<T,1> to T early to allow other transformations.

Fixes #106253

Re-lands #108659
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Sep 27, 2024
HLSL has a different set of usual arithmetic conversions for vector
types to resolve a common type for binary operator expressions.

This PR implements the current spec proposal from:
microsoft/hlsl-specs#311

There is one case that may need additional handling for implicitly
truncating `vector<T,1>` to `T` early to allow other transformations.

Fixes llvm#106253
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Sep 27, 2024
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 28, 2024

LLVM Buildbot has detected a new failure on builder clang-x86_64-debian-fast running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/8505

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 28, 2024

LLVM Buildbot has detected a new failure on builder llvm-x86_64-debian-dylib running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-clang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/8762

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-clang) failure: test (failure)
******************** TEST 'Clang :: SemaHLSL/Language/UsualArithmeticConversions.hlsl' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -finclude-default-header -fnative-half-type /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
RUN: at line 2: /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
+ /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.3-library -std=hlsl2018 -finclude-default-header -fnative-half-type /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/SemaHLSL/Language/UsualArithmeticConversions.hlsl -DERRORS -Wconversion -Wdouble-promotion -verify
error: 'expected-warning' diagnostics seen but not expected: 
  (frontend): support for HLSL language version hlsl2018 is incomplete, recommend using hlsl202x instead
1 error generated.

--

********************


puja2196 pushed a commit to puja2196/LLVM-tutorial that referenced this pull request Sep 30, 2024
puja2196 pushed a commit to puja2196/LLVM-tutorial that referenced this pull request Oct 2, 2024
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
HLSL has a different set of usual arithmetic conversions for vector
types to resolve a common type for binary operator expressions.

This PR implements the current spec proposal from:
microsoft/hlsl-specs#311

There is one case that may need additional handling for implicitly
truncating `vector<T,1>` to `T` early to allow other transformations.

Fixes llvm#106253
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
HLSL has a different set of usual arithmetic conversions for vector
types to resolve a common type for binary operator expressions.

This PR implements the current spec proposal from:
microsoft/hlsl-specs#311

There is one case that may need additional handling for implicitly
truncating vector<T,1> to T early to allow other transformations.

Fixes llvm#106253

Re-lands llvm#108659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[HLSL] bitcasts emitted instead of vector conversions in binary operators
5 participants