Make the array out of bounds error conditional on the HLSL version. (#2096)

This commit is contained in:
Tristan Labelle 2019-04-02 14:55:16 -07:00 коммит произвёл GitHub
Родитель c4e9191dd0 ecfa00c8e3
Коммит 61a7876742
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 18 добавлений и 5 удалений

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

@ -7441,7 +7441,7 @@ def err_opencl_constant_no_init : Error<
// HLSL Change Starts
let CategoryName = "HLSL Issue" in {
def err_hlsl_array_element_index_out_of_bounds: Error<
"array element index '%0' is out of bounds">;
"array index %0 is out of bounds">;
def err_hlsl_attribute_expects_string_literal: Error<
"attribute %0 must have a string literal argument">;
def err_hlsl_attribute_expects_string_literal_from_list: Error<

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

@ -8469,7 +8469,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
}
// HLSL Change Starts
if (getLangOpts().HLSL) {
if (getLangOpts().HLSL && getLangOpts().HLSLVersion > 2016) {
DiagRuntimeBehavior(BaseExpr->getLocStart(), BaseExpr,
PDiag(diag::err_hlsl_array_element_index_out_of_bounds) << index.toString(10, true));
}
@ -8488,7 +8488,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
} // HLSL Change
} else {
// HLSL Change Starts
if (getLangOpts().HLSL) {
if (getLangOpts().HLSL && getLangOpts().HLSLVersion > 2016) {
DiagRuntimeBehavior(BaseExpr->getLocStart(), BaseExpr,
PDiag(diag::err_hlsl_array_element_index_out_of_bounds) << index.toString(10, true));
}

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

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -Wno-unused-value -fsyntax-only -ffreestanding -HV 2016 -verify -verify-ignore-unexpected=note %s
void dead()
{
int array[2];
array[-1] = 0; /* expected-warning {{array index -1 is before the beginning of the array}} fxc-pass */
array[0] = 0;
array[1] = 0;
array[2] = 0; /* expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}} fxc-pass */
}
void main() {}

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

@ -3,8 +3,8 @@
void main()
{
int array[2];
array[-1] = 0; /* expected-error {{array element index '-1' is out of bounds}} fxc-error {{X3504: array index out of bounds}} */
array[-1] = 0; /* expected-error {{array index -1 is out of bounds}} fxc-error {{X3504: array index out of bounds}} */
array[0] = 0;
array[1] = 0;
array[2] = 0; /* expected-error {{array element index '2' is out of bounds}} fxc-error {{X3504: array index out of bounds}} */
array[2] = 0; /* expected-error {{array index 2 is out of bounds}} fxc-error {{X3504: array index out of bounds}} */
}

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

@ -140,6 +140,7 @@ public:
TEST_F(VerifierTest, RunArrayIndexOutOfBounds) {
CheckVerifiesHLSL(L"array-index-out-of-bounds.hlsl");
CheckVerifiesHLSL(L"array-index-out-of-bounds-HV-2016.hlsl");
}
TEST_F(VerifierTest, RunArrayLength) {