Change default type for 1<<x to int. (#3400)
This commit is contained in:
Родитель
d08b307146
Коммит
5a90ffd72b
|
@ -786,4 +786,5 @@ def HLSLAttributeType : DiagGroup<"attribute-type">;
|
|||
def HLSLSpecifierOverride : DiagGroup<"specifier-override">;
|
||||
def HLSLPackOffsetOverride : DiagGroup<"packoffset-override">;
|
||||
def HLSLCommaInInit : DiagGroup<"comma-in-init">;
|
||||
def HLSLAmbigLitShift : DiagGroup<"ambig-lit-shift">;
|
||||
// HLSL Change Ends
|
||||
|
|
|
@ -7624,6 +7624,9 @@ def warn_hlsl_narrowing : Warning<
|
|||
def warn_hlsl_sema_minprecision_promotion : Warning <
|
||||
"%0 is promoted to %1">,
|
||||
InGroup<Conversion>, DefaultWarn;
|
||||
def warn_hlsl_ambiguous_literal_shift : Warning <
|
||||
"ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast">,
|
||||
InGroup<HLSLAmbigLitShift>, DefaultWarn;
|
||||
def warn_hlsl_implicit_vector_truncation : Warning<
|
||||
"implicit truncation of vector type">,
|
||||
InGroup<Conversion>, DefaultWarn;
|
||||
|
|
|
@ -9104,7 +9104,11 @@ void HLSLExternalSource::CheckBinOpForHLSL(
|
|||
rightElementKind != AR_BASIC_LITERAL_INT &&
|
||||
rightElementKind != AR_BASIC_LITERAL_FLOAT) {
|
||||
// For case like 1<<x.
|
||||
m_sema->Diag(OpLoc, diag::warn_hlsl_ambiguous_literal_shift);
|
||||
if (rightElementKind == AR_BASIC_UINT32)
|
||||
resultElementKind = AR_BASIC_UINT32;
|
||||
else
|
||||
resultElementKind = AR_BASIC_INT32;
|
||||
} else if (resultElementKind == AR_BASIC_BOOL &&
|
||||
BinaryOperatorKindRequiresBoolAsNumeric(Opc)) {
|
||||
resultElementKind = AR_BASIC_INT32;
|
||||
|
|
|
@ -35,6 +35,12 @@ uint64_t overload2(uint64_t v1, uint64_t v2) { return (uint64_t)700; } /* fxc-e
|
|||
min16float m16f;
|
||||
min16float4x4 m16f4x4;
|
||||
|
||||
|
||||
int i;
|
||||
uint u;
|
||||
min16int m16i;
|
||||
min16uint m16u;
|
||||
|
||||
float test() {
|
||||
// Ambiguous due to literal int and literal float:
|
||||
VERIFY_TYPES(float, overload1(1.5)); /* expected-error {{call to 'overload1' is ambiguous}} fxc-error {{X3067: 'overload1': ambiguous function call}} */
|
||||
|
@ -186,5 +192,17 @@ float test() {
|
|||
VERIFY_TYPE_CONVERSION(min16int, 1UL); /* fxc-warning {{X3205: conversion from larger type to smaller, possible loss of data}} */
|
||||
VERIFY_TYPE_CONVERSION(min16int, 1LL); /* fxc-error {{X3000: syntax error: unexpected token 'L'}} */
|
||||
|
||||
// Type depends on LHS
|
||||
VERIFY_TYPES(int, 1L << u);
|
||||
VERIFY_TYPES(uint, 1U << i);
|
||||
// FXC behavior: pick uint if RHS is uint, otherwise, pick int
|
||||
// DXC: Warn for ambiguous literal LHS, then match FXC for type
|
||||
VERIFY_TYPES(int, 1 << i);/* expected-warning {{ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast}} */
|
||||
VERIFY_TYPES(uint, 1 << u);/* expected-warning {{ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast}} */
|
||||
VERIFY_TYPES(int, 1 << m16i);/* expected-warning {{ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast}} */
|
||||
VERIFY_TYPES(int, 1 << m16u);/* expected-warning {{ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast}} */
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
int half_btf(int w,int bit) { return (w + (1<<bit)) >> bit; } /* expected-warning {{ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast}} */
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// RUN: %dxc -E main -T ps_6_0 -DDEFAULT %s | FileCheck %s -check-prefix=DEFAULT
|
||||
// RUN: %dxc -E main -T ps_6_0 -DUINT_SHIFT %s | FileCheck %s -check-prefix=UINT
|
||||
// RUN: %dxc -E main -T ps_6_0 -DINT_SHIFT %s | FileCheck %s -check-prefix=INT
|
||||
|
||||
// Make sure generate ashr and lshr
|
||||
// DEFAULT:ashr
|
||||
// UINT:lshr
|
||||
// INT:ashr
|
||||
|
||||
int i;
|
||||
|
||||
#ifdef DEFAULT
|
||||
int half_btf(int w,int bit) { return (w + (1<<bit)) >> bit; }
|
||||
#endif
|
||||
|
||||
#ifdef UINT_SHIFT
|
||||
int half_btf(int w,int bit) { return (w + (1U<<bit)) >> bit; }
|
||||
#endif
|
||||
|
||||
#ifdef INT_SHIFT
|
||||
int half_btf(int w,int bit) { return (w + (1L<<bit)) >> bit; }
|
||||
#endif
|
||||
|
||||
int main(int w:W) : SV_Target {
|
||||
return half_btf(i,12);
|
||||
}
|
Загрузка…
Ссылка в новой задаче