llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Balaji V. Iyer. (bviyer) <details> <summary>Changes</summary> Fixes https://github.com/llvm/llvm-project/issues/154713 --- Full diff: https://github.com/llvm/llvm-project/pull/172399.diff 2 Files Affected: - (modified) clang/lib/AST/ExprConstant.cpp (+4) - (added) clang/test/AST/array-overflow-index.c (+9) ``````````diff diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 11c5e1c6e90f4..fb85119b137ab 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9749,6 +9749,10 @@ bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { if (Success) { Result.setFrom(Info.Ctx, Val); + // If Index cannot be represented as a 64 bit integer, return unsuccessful. + if (!Index.tryExtValue().has_value()) + return Error(E); + HandleLValueVectorElement(Info, E, Result, VT->getElementType(), VT->getNumElements(), Index.getExtValue()); } diff --git a/clang/test/AST/array-overflow-index.c b/clang/test/AST/array-overflow-index.c new file mode 100644 index 0000000000000..8a43cfbb01f91 --- /dev/null +++ b/clang/test/AST/array-overflow-index.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify %s + +// ref-no-diagnostics +// expected-no-diagnostics + +int __attribute__((vector_size(4))) test_vector = {1}; +int get_last_element(void) { + return test_vector[~0UL]; +} `````````` </details> https://github.com/llvm/llvm-project/pull/172399 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
