Add an error when bitfields are used. (#1719)
This commit is contained in:
Родитель
1329fa7da3
Коммит
2ae1365f91
|
@ -7446,6 +7446,8 @@ def err_hlsl_attribute_expects_string_literal_from_list: Error<
|
||||||
"attribute %0 must have one of these values: %1">;
|
"attribute %0 must have one of these values: %1">;
|
||||||
def err_hlsl_attribute_valid_on_function_only: Error<
|
def err_hlsl_attribute_valid_on_function_only: Error<
|
||||||
"attribute is valid only on functions">;
|
"attribute is valid only on functions">;
|
||||||
|
def err_hlsl_bitfields: Error<
|
||||||
|
"bitfields are not supported in HLSL">;
|
||||||
def err_hlsl_cannot_convert: Error<
|
def err_hlsl_cannot_convert: Error<
|
||||||
"cannot %select{implicitly |}0convert %select{|output parameter }1from %2 to %3">;
|
"cannot %select{implicitly |}0convert %select{|output parameter }1from %2 to %3">;
|
||||||
def err_hlsl_half_load_store: Error<
|
def err_hlsl_half_load_store: Error<
|
||||||
|
|
|
@ -8995,7 +8995,7 @@ private:
|
||||||
mutable IdentifierInfo *Ident___float128;
|
mutable IdentifierInfo *Ident___float128;
|
||||||
|
|
||||||
// HLSL Change Starts
|
// HLSL Change Starts
|
||||||
bool DiagnoseHLSLDecl(Declarator& D, DeclContext* DC, TypeSourceInfo* TInfo, bool isParameter);
|
bool DiagnoseHLSLDecl(Declarator& D, DeclContext* DC, Expr *BitWidth, TypeSourceInfo* TInfo, bool isParameter);
|
||||||
bool DiagnoseHLSLLookup(const LookupResult &R);
|
bool DiagnoseHLSLLookup(const LookupResult &R);
|
||||||
void TransferUnusualAttributes(Declarator& D, NamedDecl* NewDecl);
|
void TransferUnusualAttributes(Declarator& D, NamedDecl* NewDecl);
|
||||||
// HLSL Change Ends
|
// HLSL Change Ends
|
||||||
|
|
|
@ -922,6 +922,7 @@ unsigned CGMSHLSLRuntime::ConstructStructAnnotation(DxilStructAnnotation *annota
|
||||||
std::string fieldSemName = "";
|
std::string fieldSemName = "";
|
||||||
|
|
||||||
QualType fieldTy = fieldDecl->getType();
|
QualType fieldTy = fieldDecl->getType();
|
||||||
|
DXASSERT(!fieldDecl->isBitField(), "We should have already ensured we have no bitfields.");
|
||||||
|
|
||||||
// Align offset.
|
// Align offset.
|
||||||
offset = AlignBaseOffset(fieldTy, offset, bDefaultRowMajor, CGM, dataLayout);
|
offset = AlignBaseOffset(fieldTy, offset, bDefaultRowMajor, CGM, dataLayout);
|
||||||
|
|
|
@ -4935,7 +4935,7 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
|
||||||
// HLSL Change Starts
|
// HLSL Change Starts
|
||||||
if (getLangOpts().HLSL) {
|
if (getLangOpts().HLSL) {
|
||||||
const bool IsParameterFalse = false;
|
const bool IsParameterFalse = false;
|
||||||
if (!DiagnoseHLSLDecl(D, DC, TInfo, IsParameterFalse)) {
|
if (!DiagnoseHLSLDecl(D, DC, /*BitWidth*/ nullptr, TInfo, IsParameterFalse)) {
|
||||||
assert(D.isInvalidType() && "otherwise DiagnoseHLSLDecl failed but "
|
assert(D.isInvalidType() && "otherwise DiagnoseHLSLDecl failed but "
|
||||||
"didn't invalidate declaration");
|
"didn't invalidate declaration");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -10271,7 +10271,7 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
|
||||||
Diag(D.getLocStart(), diag::err_hlsl_unsupported_string_decl) << selectParamIdx;
|
Diag(D.getLocStart(), diag::err_hlsl_unsupported_string_decl) << selectParamIdx;
|
||||||
D.setInvalidType();
|
D.setInvalidType();
|
||||||
}
|
}
|
||||||
if (!DiagnoseHLSLDecl(D, Context.getTranslationUnitDecl(), TInfo, IsParm)) {
|
if (!DiagnoseHLSLDecl(D, Context.getTranslationUnitDecl(), /*BitWidth*/ nullptr, TInfo, IsParm)) {
|
||||||
assert(D.isInvalidType() && "otherwise DiagnoseHLSLDecl failed but "
|
assert(D.isInvalidType() && "otherwise DiagnoseHLSLDecl failed but "
|
||||||
"didn't invalidate declaration");
|
"didn't invalidate declaration");
|
||||||
}
|
}
|
||||||
|
@ -12687,7 +12687,7 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
|
||||||
// HLSL Changes Start
|
// HLSL Changes Start
|
||||||
if (getLangOpts().HLSL) {
|
if (getLangOpts().HLSL) {
|
||||||
const bool IsParameterFalse = false;
|
const bool IsParameterFalse = false;
|
||||||
if (!DiagnoseHLSLDecl(D, CurContext, TInfo, IsParameterFalse)) {
|
if (!DiagnoseHLSLDecl(D, CurContext, BitWidth, TInfo, IsParameterFalse)) {
|
||||||
// Let the diagnostic provide errors, don't actually return nullptr here;
|
// Let the diagnostic provide errors, don't actually return nullptr here;
|
||||||
// compilation will recover, which is helpful because HLSL diagnostics
|
// compilation will recover, which is helpful because HLSL diagnostics
|
||||||
// need not interrupt the declaration processing.
|
// need not interrupt the declaration processing.
|
||||||
|
|
|
@ -11361,7 +11361,7 @@ static bool IsUsageAttributeCompatible(AttributeList::Kind kind, bool &usageIn,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diagnose valid/invalid modifiers for HLSL.
|
// Diagnose valid/invalid modifiers for HLSL.
|
||||||
bool Sema::DiagnoseHLSLDecl(Declarator &D, DeclContext *DC,
|
bool Sema::DiagnoseHLSLDecl(Declarator &D, DeclContext *DC, Expr *BitWidth,
|
||||||
TypeSourceInfo *TInfo, bool isParameter) {
|
TypeSourceInfo *TInfo, bool isParameter) {
|
||||||
assert(getLangOpts().HLSL &&
|
assert(getLangOpts().HLSL &&
|
||||||
"otherwise this is called without checking language first");
|
"otherwise this is called without checking language first");
|
||||||
|
@ -11820,6 +11820,12 @@ bool Sema::DiagnoseHLSLDecl(Declarator &D, DeclContext *DC,
|
||||||
#endif // ENABLE_SPIRV_CODEGEN
|
#endif // ENABLE_SPIRV_CODEGEN
|
||||||
// SPIRV change ends
|
// SPIRV change ends
|
||||||
|
|
||||||
|
// Disallow bitfields
|
||||||
|
if (BitWidth) {
|
||||||
|
Diag(BitWidth->getExprLoc(), diag::err_hlsl_bitfields);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate unusual annotations.
|
// Validate unusual annotations.
|
||||||
hlsl::DiagnoseUnusualAnnotationsForHLSL(*this, D.UnusualAnnotations);
|
hlsl::DiagnoseUnusualAnnotationsForHLSL(*this, D.UnusualAnnotations);
|
||||||
auto && unusualIter = D.UnusualAnnotations.begin();
|
auto && unusualIter = D.UnusualAnnotations.begin();
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
// RUN: %dxc /T ps_6_0 /E main %s | FileCheck %s
|
||||||
|
|
||||||
|
// CHECK: error: bitfields are not supported in HLSL
|
||||||
|
|
||||||
|
struct Struct { uint field : 1; };
|
||||||
|
float main() : SV_Target { return 0; }
|
|
@ -52,7 +52,7 @@ __FUNCTION__ g___FUNCTION; // expected-error {{expected unqualified-id}}
|
||||||
__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
|
__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
|
||||||
|
|
||||||
struct s_with_bitfield {
|
struct s_with_bitfield {
|
||||||
int f_bitfield : 3;
|
int f_bitfield : 3; // expected-error {{bitfields are not supported in HLSL}}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_with_friend {
|
struct s_with_friend {
|
||||||
|
|
|
@ -52,7 +52,7 @@ __FUNCTION__ g___FUNCTION; // expected-error {{expected unqualified-id}}
|
||||||
__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
|
__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
|
||||||
|
|
||||||
struct s_with_bitfield {
|
struct s_with_bitfield {
|
||||||
int f_bitfield : 3;
|
int f_bitfield : 3; // expected-error {{bitfields are not supported in HLSL}}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_with_friend {
|
struct s_with_friend {
|
||||||
|
|
|
@ -9,9 +9,6 @@ const s_arr_i_f arr_struct_one[] = { 1, 2 };
|
||||||
const s_arr_i_f arr_struct_two[] = { 1, 2, 3, 4 };
|
const s_arr_i_f arr_struct_two[] = { 1, 2, 3, 4 };
|
||||||
const int g_int;
|
const int g_int;
|
||||||
const unsigned int g_unsigned_int;
|
const unsigned int g_unsigned_int;
|
||||||
struct s_with_bitfield {
|
|
||||||
int f_bitfield : 3;
|
|
||||||
};
|
|
||||||
static int static_int() {
|
static int static_int() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,9 @@ unsigned int g_unsigned_int;
|
||||||
//__FUNCTION__ g___FUNCTION; // expected-error {{expected unqualified-id}}
|
//__FUNCTION__ g___FUNCTION; // expected-error {{expected unqualified-id}}
|
||||||
//__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
|
//__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
|
||||||
|
|
||||||
struct s_with_bitfield {
|
//struct s_with_bitfield {
|
||||||
int f_bitfield : 3;
|
// int f_bitfield : 3; // expected-error {{bitfields are not supported in HLSL}}
|
||||||
};
|
//};
|
||||||
|
|
||||||
//struct s_with_friend {
|
//struct s_with_friend {
|
||||||
// friend void some_fn(); // expected-error {{'friend' is a reserved keyword in HLSL}}
|
// friend void some_fn(); // expected-error {{'friend' is a reserved keyword in HLSL}}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче