Author: Hans Wennborg Date: 2025-03-12T12:31:37+01:00 New Revision: 76cf895717e9eba4d2a158d5bc3e48f2f7794181
URL: https://github.com/llvm/llvm-project/commit/76cf895717e9eba4d2a158d5bc3e48f2f7794181 DIFF: https://github.com/llvm/llvm-project/commit/76cf895717e9eba4d2a158d5bc3e48f2f7794181.diff LOG: Revert "[HLSL] error on out of bounds vector accesses (#128952)" This caused false-positive errors, see comment on the PR. > Add Sema checking and diagnostics to error on out of bounds vector > accesses > Add tests > Closes #91640 This reverts commit f1e36759d2e6c26d2d5825f955c51fd595909b52. Added: Modified: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaChecking.cpp clang/test/CodeGenCXX/x86_64-arguments.cpp Removed: clang/test/SemaHLSL/Language/VectorOutOfRange-errors.hlsl ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c89ea878905c0..f6e4d6a34e5dc 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -236,8 +236,6 @@ Improvements to Clang's diagnostics under the subgroup ``-Wunsafe-buffer-usage-in-libc-call``. - Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with ``-Wno-error=parentheses``. -- Adds an error diagnostic for out of bounds vector accesses; produces an error - for compile time statically provable out of bounds vector accesses. - The ``-Wshift-bool`` warning has been added to warn about shifting a boolean. (#GH28334) - Fixed diagnostics adding a trailing ``::`` when printing some source code constructs, like base classes. diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4bdbb797c2b86..8e6e6e892cdd7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10688,9 +10688,6 @@ def err_block_on_vm : Error< def err_sizeless_nonlocal : Error< "non-local variable with sizeless type %0">; -def err_vector_index_out_of_range : Error< - "vector element index %0 is out of bounds">; - def err_vec_builtin_non_vector : Error< "%select{first two|all}1 arguments to %0 must be vectors">; def err_vec_builtin_incompatible_vector : Error< diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index c034de0e633da..9ac26d8728446 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2468,7 +2468,6 @@ class Sema final : public SemaBase { const ArraySubscriptExpr *ASE = nullptr, bool AllowOnePastEnd = true, bool IndexNegated = false); void CheckArrayAccess(const Expr *E); - void CheckVectorAccess(const Expr *BaseExpr, const Expr *IndexExpr); bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, const FunctionProtoType *Proto); diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 3a24bcf1c7094..9bcb014ab9bfc 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -14055,23 +14055,6 @@ void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) { << TRange << Op->getSourceRange(); } -void Sema::CheckVectorAccess(const Expr *BaseExpr, const Expr *IndexExpr) { - const auto *VTy = BaseExpr->getType()->getAs<VectorType>(); - if (!VTy) - return; - - Expr::EvalResult Result; - if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects)) - return; - - unsigned DiagID = diag::err_vector_index_out_of_range; - - llvm::APSInt index = Result.Val.getInt(); - if (index.isNegative() || index >= VTy->getNumElements()) - Diag(BaseExpr->getBeginLoc(), DiagID) << toString(index, 10, true); - return; -} - void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, const ArraySubscriptExpr *ASE, bool AllowOnePastEnd, bool IndexNegated) { @@ -14086,12 +14069,6 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, const Type *EffectiveType = BaseExpr->getType()->getPointeeOrArrayElementType(); BaseExpr = BaseExpr->IgnoreParenCasts(); - - if (BaseExpr->getType()->isVectorType()) { - CheckVectorAccess(BaseExpr, IndexExpr); - return; - } - const ConstantArrayType *ArrayTy = Context.getAsConstantArrayType(BaseExpr->getType()); diff --git a/clang/test/CodeGenCXX/x86_64-arguments.cpp b/clang/test/CodeGenCXX/x86_64-arguments.cpp index 6915e5d6761dd..ebeba7fd65495 100644 --- a/clang/test/CodeGenCXX/x86_64-arguments.cpp +++ b/clang/test/CodeGenCXX/x86_64-arguments.cpp @@ -215,6 +215,6 @@ union U { float f1; char __attribute__((__vector_size__(1))) f2; }; -int f(union U u) { return u.f2[0]; } +int f(union U u) { return u.f2[1]; } // CHECK-LABEL: define{{.*}} i32 @_ZN6test111fENS_1UE(i32 } diff --git a/clang/test/SemaHLSL/Language/VectorOutOfRange-errors.hlsl b/clang/test/SemaHLSL/Language/VectorOutOfRange-errors.hlsl deleted file mode 100644 index b4d423fb24bd2..0000000000000 --- a/clang/test/SemaHLSL/Language/VectorOutOfRange-errors.hlsl +++ /dev/null @@ -1,19 +0,0 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -verify - -export void fn1() { - int2 A = {1,2}; - int X = A[-1]; - // expected-error@-1 {{vector element index -1 is out of bounds}} -} - -export void fn2() { - int4 A = {1,2,3,4}; - int X = A[4]; - // expected-error@-1 {{vector element index 4 is out of bounds}} -} - -export void fn3() { - bool2 A = {true,true}; - bool X = A[-1]; - // expected-error@-1 {{vector element index -1 is out of bounds}} -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits