Work around GCC's broken -Warray-bounds warning
When building with a sufficiently high -march that GCC can use YMM
registers, its -Warray-bounds warning misfires on 32-byte arrays that
are initialized directly. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114826
Work around this by using a less safe pattern and initializing the array
with memset.
Change-Id: I3bcbdca2b749fd7a3093d5194515a04c034e7bf9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69567
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/curve25519/x25519_test.cc b/crypto/curve25519/x25519_test.cc
index c1b9e40..20472df 100644
--- a/crypto/curve25519/x25519_test.cc
+++ b/crypto/curve25519/x25519_test.cc
@@ -158,7 +158,13 @@
TEST(X25519Test, Iterated) {
// Taken from https://tools.ietf.org/html/rfc7748#section-5.2.
- uint8_t scalar[32] = {9}, point[32] = {9}, out[32];
+ uint8_t scalar[32], point[32], out[32];
+ // This could simply be `uint8_t scalar[32] = {9}`, but GCC's -Warray-bounds
+ // warning is broken. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114826.
+ OPENSSL_memset(scalar, 0, sizeof(scalar));
+ scalar[0] = 9;
+ OPENSSL_memset(point, 0, sizeof(point));
+ point[0] = 9;
for (unsigned i = 0; i < 1000; i++) {
EXPECT_TRUE(ctwrapX25519(out, scalar, point));
@@ -177,7 +183,13 @@
TEST(X25519Test, DISABLED_IteratedLarge) {
// Taken from https://tools.ietf.org/html/rfc7748#section-5.2.
- uint8_t scalar[32] = {9}, point[32] = {9}, out[32];
+ uint8_t scalar[32], point[32], out[32];
+ // This could simply be `uint8_t scalar[32] = {9}`, but GCC's -Warray-bounds
+ // warning is broken. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114826.
+ OPENSSL_memset(scalar, 0, sizeof(scalar));
+ scalar[0] = 9;
+ OPENSSL_memset(point, 0, sizeof(point));
+ point[0] = 9;
for (unsigned i = 0; i < 1000000; i++) {
EXPECT_TRUE(ctwrapX25519(out, scalar, point));