@@ -2420,47 +2420,31 @@ bool SemaHLSL::CanPerformScalarCast(QualType SrcTy, QualType DestTy) {
2420
2420
2421
2421
switch (Type::ScalarTypeKind SrcKind = SrcTy->getScalarTypeKind ()) {
2422
2422
case Type::STK_MemberPointer:
2423
- return false ;
2424
-
2425
2423
case Type::STK_CPointer:
2426
2424
case Type::STK_BlockPointer:
2427
2425
case Type::STK_ObjCObjectPointer:
2428
- switch (DestTy->getScalarTypeKind ()) {
2429
- case Type::STK_CPointer:
2430
- case Type::STK_BlockPointer:
2431
- case Type::STK_ObjCObjectPointer:
2432
- case Type::STK_Bool:
2433
- case Type::STK_Integral:
2434
- return true ;
2435
- case Type::STK_Floating:
2436
- case Type::STK_FloatingComplex:
2437
- case Type::STK_IntegralComplex:
2438
- case Type::STK_MemberPointer:
2439
- return false ;
2440
- case Type::STK_FixedPoint:
2441
- llvm_unreachable (" HLSL doesn't have fixed point types." );
2442
- }
2443
- llvm_unreachable (" Should have returned before this" );
2426
+ llvm_unreachable (" HLSL doesn't support pointers." );
2444
2427
2445
2428
case Type::STK_FixedPoint:
2446
- llvm_unreachable (" HLSL doesn't have fixed point types." );
2429
+ llvm_unreachable (" HLSL doesn't support fixed point types." );
2447
2430
2448
2431
case Type::STK_Bool: // casting from bool is like casting from an integer
2449
2432
case Type::STK_Integral:
2450
2433
switch (DestTy->getScalarTypeKind ()) {
2451
2434
case Type::STK_CPointer:
2452
2435
case Type::STK_ObjCObjectPointer:
2453
2436
case Type::STK_BlockPointer:
2437
+ case Type::STK_MemberPointer:
2438
+ llvm_unreachable (" HLSL doesn't support pointers." );
2454
2439
case Type::STK_Bool:
2455
2440
case Type::STK_Integral:
2456
2441
case Type::STK_Floating:
2442
+ return true ;
2457
2443
case Type::STK_IntegralComplex:
2458
2444
case Type::STK_FloatingComplex:
2459
- return true ;
2445
+ llvm_unreachable ( " HLSL doesn't support complex types. " ) ;
2460
2446
case Type::STK_FixedPoint:
2461
- llvm_unreachable (" HLSL doesn't have fixed point types." );
2462
- case Type::STK_MemberPointer:
2463
- return false ;
2447
+ llvm_unreachable (" HLSL doesn't support fixed point types." );
2464
2448
}
2465
2449
llvm_unreachable (" Should have returned before this" );
2466
2450
@@ -2469,60 +2453,30 @@ bool SemaHLSL::CanPerformScalarCast(QualType SrcTy, QualType DestTy) {
2469
2453
case Type::STK_Floating:
2470
2454
case Type::STK_Bool:
2471
2455
case Type::STK_Integral:
2456
+ return true ;
2472
2457
case Type::STK_FloatingComplex:
2473
2458
case Type::STK_IntegralComplex:
2474
- return true ;
2459
+ llvm_unreachable ( " HLSL doesn't support complex types. " ) ;
2475
2460
case Type::STK_FixedPoint:
2476
- llvm_unreachable (" HLSL doesn't have fixed point types." );
2461
+ llvm_unreachable (" HLSL doesn't support fixed point types." );
2477
2462
case Type::STK_CPointer:
2478
2463
case Type::STK_ObjCObjectPointer:
2479
2464
case Type::STK_BlockPointer:
2480
2465
case Type::STK_MemberPointer:
2481
- return false ;
2466
+ llvm_unreachable ( " HLSL doesn't support pointers. " ) ;
2482
2467
}
2483
2468
llvm_unreachable (" Should have returned before this" );
2484
2469
2485
2470
case Type::STK_FloatingComplex:
2486
- switch (DestTy->getScalarTypeKind ()) {
2487
- case Type::STK_FloatingComplex:
2488
- case Type::STK_IntegralComplex:
2489
- case Type::STK_Floating:
2490
- case Type::STK_Bool:
2491
- case Type::STK_Integral:
2492
- return true ;
2493
- case Type::STK_CPointer:
2494
- case Type::STK_ObjCObjectPointer:
2495
- case Type::STK_BlockPointer:
2496
- case Type::STK_MemberPointer:
2497
- return false ;
2498
- case Type::STK_FixedPoint:
2499
- llvm_unreachable (" HLSL doesn't have fixed point types." );
2500
- }
2501
- llvm_unreachable (" Should have returned before this" );
2502
-
2503
2471
case Type::STK_IntegralComplex:
2504
- switch (DestTy->getScalarTypeKind ()) {
2505
- case Type::STK_FloatingComplex:
2506
- case Type::STK_IntegralComplex:
2507
- case Type::STK_Integral:
2508
- case Type::STK_Bool:
2509
- case Type::STK_Floating:
2510
- return true ;
2511
- case Type::STK_CPointer:
2512
- case Type::STK_ObjCObjectPointer:
2513
- case Type::STK_BlockPointer:
2514
- case Type::STK_MemberPointer:
2515
- return false ;
2516
- case Type::STK_FixedPoint:
2517
- llvm_unreachable (" HLSL doesn't have fixed point types." );
2518
- }
2519
- llvm_unreachable (" Should have returned before this" );
2472
+ llvm_unreachable (" HLSL doesn't support complex types." );
2520
2473
}
2521
2474
2522
2475
llvm_unreachable (" Unhandled scalar cast" );
2523
2476
}
2524
2477
2525
2478
// Can we perform an HLSL Flattened cast?
2479
+ // TODO: update this code when matrices are added
2526
2480
bool SemaHLSL::CanPerformAggregateCast (Expr *Src, QualType DestTy) {
2527
2481
2528
2482
// Don't handle casts where LHS and RHS are any combination of scalar/vector
@@ -2531,8 +2485,8 @@ bool SemaHLSL::CanPerformAggregateCast(Expr *Src, QualType DestTy) {
2531
2485
if (SrcTy->isScalarType ()) // always a splat and this cast doesn't handle that
2532
2486
return false ;
2533
2487
2534
- if ((DestTy-> isScalarType () || DestTy-> isVectorType () ) &&
2535
- (SrcTy ->isScalarType () || SrcTy ->isVectorType ()))
2488
+ if (SrcTy-> isVectorType () &&
2489
+ (DestTy ->isScalarType () || DestTy ->isVectorType ()))
2536
2490
return false ;
2537
2491
2538
2492
llvm::SmallVector<QualType> DestTypes;
@@ -2542,18 +2496,15 @@ bool SemaHLSL::CanPerformAggregateCast(Expr *Src, QualType DestTy) {
2542
2496
2543
2497
// Usually the size of SrcTypes must be greater than or equal to the size of
2544
2498
// DestTypes.
2545
- if (SrcTypes.size () >= DestTypes.size ()) {
2499
+ if (SrcTypes.size () < DestTypes.size ())
2500
+ return false ;
2546
2501
2547
- unsigned i;
2548
- for (i = 0 ; i < DestTypes.size () && i < SrcTypes.size (); i++) {
2549
- if (!CanPerformScalarCast (SrcTypes[i], DestTypes[i])) {
2550
- return false ;
2551
- }
2502
+ for (unsigned i = 0 ; i < DestTypes.size () && i < SrcTypes.size (); i++) {
2503
+ if (!CanPerformScalarCast (SrcTypes[i], DestTypes[i])) {
2504
+ return false ;
2552
2505
}
2553
- return true ;
2554
- } else { // can't cast, Src is wrong size for Dest
2555
- return false ;
2556
2506
}
2507
+ return true ;
2557
2508
}
2558
2509
2559
2510
ExprResult SemaHLSL::ActOnOutParamExpr (ParmVarDecl *Param, Expr *Arg) {
0 commit comments