Add an error when bitfields are used. (#1719)

This commit is contained in:
Tristan Labelle 2018-11-19 15:46:50 -08:00 коммит произвёл GitHub
Родитель 1329fa7da3
Коммит 2ae1365f91
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 25 добавлений и 13 удалений

Просмотреть файл

@ -7446,6 +7446,8 @@ def err_hlsl_attribute_expects_string_literal_from_list: Error<
"attribute %0 must have one of these values: %1">;
def err_hlsl_attribute_valid_on_function_only: Error<
"attribute is valid only on functions">;
def err_hlsl_bitfields: Error<
"bitfields are not supported in HLSL">;
def err_hlsl_cannot_convert: Error<
"cannot %select{implicitly |}0convert %select{|output parameter }1from %2 to %3">;
def err_hlsl_half_load_store: Error<

Просмотреть файл

@ -8995,7 +8995,7 @@ private:
mutable IdentifierInfo *Ident___float128;
// 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);
void TransferUnusualAttributes(Declarator& D, NamedDecl* NewDecl);
// HLSL Change Ends

Просмотреть файл

@ -922,6 +922,7 @@ unsigned CGMSHLSLRuntime::ConstructStructAnnotation(DxilStructAnnotation *annota
std::string fieldSemName = "";
QualType fieldTy = fieldDecl->getType();
DXASSERT(!fieldDecl->isBitField(), "We should have already ensured we have no bitfields.");
// Align offset.
offset = AlignBaseOffset(fieldTy, offset, bDefaultRowMajor, CGM, dataLayout);

Просмотреть файл

@ -4935,7 +4935,7 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
// HLSL Change Starts
if (getLangOpts().HLSL) {
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 "
"didn't invalidate declaration");
return 0;
@ -10271,7 +10271,7 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
Diag(D.getLocStart(), diag::err_hlsl_unsupported_string_decl) << selectParamIdx;
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 "
"didn't invalidate declaration");
}
@ -12687,7 +12687,7 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
// HLSL Changes Start
if (getLangOpts().HLSL) {
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;
// compilation will recover, which is helpful because HLSL diagnostics
// need not interrupt the declaration processing.

Просмотреть файл

@ -11361,7 +11361,7 @@ static bool IsUsageAttributeCompatible(AttributeList::Kind kind, bool &usageIn,
}
// 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) {
assert(getLangOpts().HLSL &&
"otherwise this is called without checking language first");
@ -11820,6 +11820,12 @@ bool Sema::DiagnoseHLSLDecl(Declarator &D, DeclContext *DC,
#endif // ENABLE_SPIRV_CODEGEN
// SPIRV change ends
// Disallow bitfields
if (BitWidth) {
Diag(BitWidth->getExprLoc(), diag::err_hlsl_bitfields);
result = false;
}
// Validate unusual annotations.
hlsl::DiagnoseUnusualAnnotationsForHLSL(*this, D.UnusualAnnotations);
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__'}}
struct s_with_bitfield {
int f_bitfield : 3;
int f_bitfield : 3; // expected-error {{bitfields are not supported in HLSL}}
};
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__'}}
struct s_with_bitfield {
int f_bitfield : 3;
int f_bitfield : 3; // expected-error {{bitfields are not supported in HLSL}}
};
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 int g_int;
const unsigned int g_unsigned_int;
struct s_with_bitfield {
int f_bitfield : 3;
};
static int static_int() {
return 1;
}

Просмотреть файл

@ -51,9 +51,9 @@ unsigned int g_unsigned_int;
//__FUNCTION__ g___FUNCTION; // expected-error {{expected unqualified-id}}
//__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
struct s_with_bitfield {
int f_bitfield : 3;
};
//struct s_with_bitfield {
// int f_bitfield : 3; // expected-error {{bitfields are not supported in HLSL}}
//};
//struct s_with_friend {
// friend void some_fn(); // expected-error {{'friend' is a reserved keyword in HLSL}}