@@ -2962,9 +2962,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
2962
2962
}
2963
2963
}
2964
2964
2965
- if (getLangOpts().HLSL && CheckHLSLBuiltinFunctionCall(BuiltinID, TheCall)) {
2965
+ if (getLangOpts().HLSL && CheckHLSLBuiltinFunctionCall(BuiltinID, TheCall))
2966
2966
return ExprError();
2967
- }
2968
2967
2969
2968
// Since the target specific builtins for each arch overlap, only check those
2970
2969
// of the arch we are compiling for.
@@ -5166,96 +5165,6 @@ bool Sema::CheckPPCMMAType(QualType Type, SourceLocation TypeLoc) {
5166
5165
return false;
5167
5166
}
5168
5167
5169
- // Helper function for CheckHLSLBuiltinFunctionCall
5170
- // Note: UsualArithmeticConversions handles the case where at least
5171
- // one arg isn't a bool
5172
- bool PromoteBoolsToInt(Sema *S, CallExpr *TheCall) {
5173
- unsigned NumArgs = TheCall->getNumArgs();
5174
-
5175
- for (unsigned i = 0; i < NumArgs; ++i) {
5176
- ExprResult A = TheCall->getArg(i);
5177
- if (!A.get()->getType()->isBooleanType())
5178
- return false;
5179
- }
5180
- // if we got here all args are bool
5181
- for (unsigned i = 0; i < NumArgs; ++i) {
5182
- ExprResult A = TheCall->getArg(i);
5183
- ExprResult ResA = S->PerformImplicitConversion(A.get(), S->Context.IntTy,
5184
- Sema::AA_Converting);
5185
- if (ResA.isInvalid())
5186
- return true;
5187
- TheCall->setArg(i, ResA.get());
5188
- }
5189
- return false;
5190
- }
5191
-
5192
- // Helper function for CheckHLSLBuiltinFunctionCall
5193
- // Handles the CK_HLSLVectorTruncation case for builtins
5194
- void PromoteVectorArgTruncation(Sema *S, CallExpr *TheCall) {
5195
- assert(TheCall->getNumArgs() > 1);
5196
- ExprResult A = TheCall->getArg(0);
5197
- ExprResult B = TheCall->getArg(1);
5198
- QualType ArgTyA = A.get()->getType();
5199
- QualType ArgTyB = B.get()->getType();
5200
-
5201
- auto *VecTyA = ArgTyA->getAs<VectorType>();
5202
- auto *VecTyB = ArgTyB->getAs<VectorType>();
5203
- if (VecTyA == nullptr && VecTyB == nullptr)
5204
- return;
5205
- if (VecTyA == nullptr || VecTyB == nullptr)
5206
- return;
5207
- if (VecTyA->getNumElements() == VecTyB->getNumElements())
5208
- return;
5209
-
5210
- Expr *LargerArg = B.get();
5211
- Expr *SmallerArg = A.get();
5212
- int largerIndex = 1;
5213
- if (VecTyA->getNumElements() > VecTyB->getNumElements()) {
5214
- LargerArg = A.get();
5215
- SmallerArg = B.get();
5216
- largerIndex = 0;
5217
- }
5218
-
5219
- S->Diag(TheCall->getExprLoc(), diag::warn_hlsl_impcast_vector_truncation)
5220
- << LargerArg->getType() << SmallerArg->getType()
5221
- << LargerArg->getSourceRange() << SmallerArg->getSourceRange();
5222
- ExprResult ResLargerArg = S->ImpCastExprToType(
5223
- LargerArg, SmallerArg->getType(), CK_HLSLVectorTruncation);
5224
- TheCall->setArg(largerIndex, ResLargerArg.get());
5225
- return;
5226
- }
5227
-
5228
- // Helper function for CheckHLSLBuiltinFunctionCall
5229
- void CheckVectorFloatPromotion(Sema *S, ExprResult &source, QualType targetTy,
5230
- SourceRange targetSrcRange,
5231
- SourceLocation BuiltinLoc) {
5232
- auto *vecTyTarget = source.get()->getType()->getAs<VectorType>();
5233
- assert(vecTyTarget);
5234
- QualType vecElemT = vecTyTarget->getElementType();
5235
- if (!vecElemT->isFloatingType() && targetTy->isFloatingType()) {
5236
- QualType floatVecTy = S->Context.getVectorType(
5237
- S->Context.FloatTy, vecTyTarget->getNumElements(), VectorKind::Generic);
5238
-
5239
- S->Diag(BuiltinLoc, diag::warn_impcast_integer_float_precision)
5240
- << source.get()->getType() << floatVecTy
5241
- << source.get()->getSourceRange() << targetSrcRange;
5242
- source = S->SemaConvertVectorExpr(
5243
- source.get(), S->Context.CreateTypeSourceInfo(floatVecTy), BuiltinLoc,
5244
- source.get()->getBeginLoc());
5245
- }
5246
- }
5247
-
5248
- // Helper function for CheckHLSLBuiltinFunctionCall
5249
- void PromoteVectorArgSplat(Sema *S, ExprResult &source, QualType targetTy) {
5250
- QualType sourceTy = source.get()->getType();
5251
- auto *vecTyTarget = targetTy->getAs<VectorType>();
5252
- QualType vecElemT = vecTyTarget->getElementType();
5253
- if (vecElemT->isFloatingType() && sourceTy != vecElemT)
5254
- // if float vec splat wil do an unnecessary cast to double
5255
- source = S->ImpCastExprToType(source.get(), vecElemT, CK_FloatingCast);
5256
- source = S->ImpCastExprToType(source.get(), targetTy, CK_VectorSplat);
5257
- }
5258
-
5259
5168
// Helper function for CheckHLSLBuiltinFunctionCall
5260
5169
bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
5261
5170
assert(TheCall->getNumArgs() > 1);
@@ -5265,36 +5174,42 @@ bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
5265
5174
QualType ArgTyB = B.get()->getType();
5266
5175
auto *VecTyA = ArgTyA->getAs<VectorType>();
5267
5176
auto *VecTyB = ArgTyB->getAs<VectorType>();
5268
-
5177
+ SourceLocation BuiltinLoc = TheCall->getBeginLoc();
5269
5178
if (VecTyA == nullptr && VecTyB == nullptr)
5270
5179
return false;
5271
5180
5272
5181
if (VecTyA && VecTyB) {
5273
- if (VecTyA->getElementType() == VecTyB->getElementType()) {
5274
- TheCall->setType(VecTyA->getElementType());
5275
- return false;
5182
+ bool retValue = false;
5183
+ if (VecTyA->getElementType() != VecTyB->getElementType()) {
5184
+ // Note: type promotion is intended to be handeled via the intrinsics
5185
+ // and not the builtin itself.
5186
+ S->Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_incompatible_vector)
5187
+ << TheCall->getDirectCallee()
5188
+ << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc());
5189
+ retValue = true;
5190
+ }
5191
+ if (VecTyA->getNumElements() != VecTyB->getNumElements()) {
5192
+ // if we get here a HLSLVectorTruncation is needed.
5193
+ S->Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector)
5194
+ << TheCall->getDirectCallee()
5195
+ << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5196
+ TheCall->getArg(1)->getEndLoc());
5197
+ retValue = true;
5276
5198
}
5277
- // Note: type promotion is intended to be handeled via the intrinsics
5278
- // and not the builtin itself.
5279
- S->Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_incompatible_vector)
5280
- << TheCall->getDirectCallee()
5281
- << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc());
5282
- return true;
5283
- }
5284
5199
5285
- if (VecTyB) {
5286
- CheckVectorFloatPromotion(S, B, ArgTyA, A.get()->getSourceRange(),
5287
- TheCall->getBeginLoc());
5288
- PromoteVectorArgSplat(S, A, B.get()->getType());
5289
- }
5290
- if (VecTyA) {
5291
- CheckVectorFloatPromotion(S, A, ArgTyB, B.get()->getSourceRange(),
5292
- TheCall->getBeginLoc());
5293
- PromoteVectorArgSplat(S, B, A.get()->getType());
5200
+ if (retValue)
5201
+ TheCall->setType(VecTyA->getElementType());
5202
+
5203
+ return retValue;
5294
5204
}
5295
- TheCall->setArg(0, A.get());
5296
- TheCall->setArg(1, B.get());
5297
- return false;
5205
+
5206
+ // Note: if we get here one of the args is a scalar which
5207
+ // requires a VectorSplat on Arg0 or Arg1
5208
+ S->Diag(BuiltinLoc, diag::err_vec_builtin_non_vector)
5209
+ << TheCall->getDirectCallee()
5210
+ << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5211
+ TheCall->getArg(1)->getEndLoc());
5212
+ return true;
5298
5213
}
5299
5214
5300
5215
// Note: returning true in this case results in CheckBuiltinFunctionCall
@@ -5304,11 +5219,8 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
5304
5219
case Builtin::BI__builtin_hlsl_dot: {
5305
5220
if (checkArgCount(*this, TheCall, 2))
5306
5221
return true;
5307
- if (PromoteBoolsToInt(this, TheCall))
5308
- return true;
5309
5222
if (CheckVectorElementCallArgs(this, TheCall))
5310
5223
return true;
5311
- PromoteVectorArgTruncation(this, TheCall);
5312
5224
if (SemaBuiltinVectorToScalarMath(TheCall))
5313
5225
return true;
5314
5226
break;
@@ -19759,24 +19671,22 @@ bool Sema::PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall) {
19759
19671
19760
19672
bool Sema::SemaBuiltinElementwiseMath(CallExpr *TheCall) {
19761
19673
QualType Res;
19762
- bool result = SemaBuiltinVectorMath(TheCall, Res);
19763
- if (result)
19674
+ if (SemaBuiltinVectorMath(TheCall, Res))
19764
19675
return true;
19765
19676
TheCall->setType(Res);
19766
19677
return false;
19767
19678
}
19768
19679
19769
19680
bool Sema::SemaBuiltinVectorToScalarMath(CallExpr *TheCall) {
19770
19681
QualType Res;
19771
- bool result = SemaBuiltinVectorMath(TheCall, Res);
19772
- if (result)
19682
+ if (SemaBuiltinVectorMath(TheCall, Res))
19773
19683
return true;
19774
19684
19775
- if (auto *VecTy0 = Res->getAs<VectorType>()) {
19685
+ if (auto *VecTy0 = Res->getAs<VectorType>())
19776
19686
TheCall->setType(VecTy0->getElementType());
19777
- } else {
19687
+ else
19778
19688
TheCall->setType(Res);
19779
- }
19689
+
19780
19690
return false;
19781
19691
}
19782
19692
0 commit comments