@@ -2420,47 +2420,31 @@ bool SemaHLSL::CanPerformScalarCast(QualType SrcTy, QualType DestTy) {
24202420
24212421 switch (Type::ScalarTypeKind SrcKind = SrcTy->getScalarTypeKind ()) {
24222422 case Type::STK_MemberPointer:
2423- return false ;
2424-
24252423 case Type::STK_CPointer:
24262424 case Type::STK_BlockPointer:
24272425 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." );
24442427
24452428 case Type::STK_FixedPoint:
2446- llvm_unreachable (" HLSL doesn't have fixed point types." );
2429+ llvm_unreachable (" HLSL doesn't support fixed point types." );
24472430
24482431 case Type::STK_Bool: // casting from bool is like casting from an integer
24492432 case Type::STK_Integral:
24502433 switch (DestTy->getScalarTypeKind ()) {
24512434 case Type::STK_CPointer:
24522435 case Type::STK_ObjCObjectPointer:
24532436 case Type::STK_BlockPointer:
2437+ case Type::STK_MemberPointer:
2438+ llvm_unreachable (" HLSL doesn't support pointers." );
24542439 case Type::STK_Bool:
24552440 case Type::STK_Integral:
24562441 case Type::STK_Floating:
2442+ return true ;
24572443 case Type::STK_IntegralComplex:
24582444 case Type::STK_FloatingComplex:
2459- return true ;
2445+ llvm_unreachable ( " HLSL doesn't support complex types. " ) ;
24602446 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." );
24642448 }
24652449 llvm_unreachable (" Should have returned before this" );
24662450
@@ -2469,60 +2453,30 @@ bool SemaHLSL::CanPerformScalarCast(QualType SrcTy, QualType DestTy) {
24692453 case Type::STK_Floating:
24702454 case Type::STK_Bool:
24712455 case Type::STK_Integral:
2456+ return true ;
24722457 case Type::STK_FloatingComplex:
24732458 case Type::STK_IntegralComplex:
2474- return true ;
2459+ llvm_unreachable ( " HLSL doesn't support complex types. " ) ;
24752460 case Type::STK_FixedPoint:
2476- llvm_unreachable (" HLSL doesn't have fixed point types." );
2461+ llvm_unreachable (" HLSL doesn't support fixed point types." );
24772462 case Type::STK_CPointer:
24782463 case Type::STK_ObjCObjectPointer:
24792464 case Type::STK_BlockPointer:
24802465 case Type::STK_MemberPointer:
2481- return false ;
2466+ llvm_unreachable ( " HLSL doesn't support pointers. " ) ;
24822467 }
24832468 llvm_unreachable (" Should have returned before this" );
24842469
24852470 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-
25032471 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." );
25202473 }
25212474
25222475 llvm_unreachable (" Unhandled scalar cast" );
25232476}
25242477
25252478// Can we perform an HLSL Flattened cast?
2479+ // TODO: update this code when matrices are added
25262480bool SemaHLSL::CanPerformAggregateCast (Expr *Src, QualType DestTy) {
25272481
25282482 // 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) {
25312485 if (SrcTy->isScalarType ()) // always a splat and this cast doesn't handle that
25322486 return false ;
25332487
2534- if ((DestTy-> isScalarType () || DestTy-> isVectorType () ) &&
2535- (SrcTy ->isScalarType () || SrcTy ->isVectorType ()))
2488+ if (SrcTy-> isVectorType () &&
2489+ (DestTy ->isScalarType () || DestTy ->isVectorType ()))
25362490 return false ;
25372491
25382492 llvm::SmallVector<QualType> DestTypes;
@@ -2542,18 +2496,15 @@ bool SemaHLSL::CanPerformAggregateCast(Expr *Src, QualType DestTy) {
25422496
25432497 // Usually the size of SrcTypes must be greater than or equal to the size of
25442498 // DestTypes.
2545- if (SrcTypes.size () >= DestTypes.size ()) {
2499+ if (SrcTypes.size () < DestTypes.size ())
2500+ return false ;
25462501
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 ;
25522505 }
2553- return true ;
2554- } else { // can't cast, Src is wrong size for Dest
2555- return false ;
25562506 }
2507+ return true ;
25572508}
25582509
25592510ExprResult SemaHLSL::ActOnOutParamExpr (ParmVarDecl *Param, Expr *Arg) {
0 commit comments