================ @@ -4559,6 +4559,134 @@ void CodeGenFunction::EmitCountedByBoundsChecking( } } +/// Emit array bounds constraints using llvm.assume for optimization hints. +/// +/// C Standard (ISO/IEC 9899:2011 - C11) +/// Section J.2 (Undefined behavior): An array subscript is out of range, even +/// if an object is apparently accessible with the given subscript (as in the +/// lvalue expression a[1][7] given the declaration int a[4][5]) (6.5.6). +/// +/// Section 6.5.6 (Additive operators): If both the pointer operand and the +/// result point to elements of the same array object, or one past the last +/// element of the array object, the evaluation shall not produce an overflow; +/// otherwise, the behavior is undefined. +/// +/// C++ Standard (ISO/IEC 14882 - 2017) +/// Section 8.7 (Additive operators): +/// 4 When an expression that has integral type is added to or subtracted from a +/// pointer, the result has the type of the pointer operand. If the expression +/// P points to element x[i] of an array object x with n elements,^86 the +/// expressions P + J and J + P (where J has the value j) point to the +/// (possibly-hypothetical) element x[i + j] if 0 ≤ i + j ≤ n; otherwise, the +/// behavior is undefined. Likewise, the expression P - J points to the +/// (possibly-hypothetical) element x[i − j] if 0 ≤ i − j ≤ n; otherwise, the +/// behavior is undefined. +/// ^86 A pointer past the last element of an array x of n elements is ---------------- sjoerdmeijer wrote:
Drive-by nit: is `^86` an unrecognised character after a copy-paste? https://github.com/llvm/llvm-project/pull/159046 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
