blob: 46ec9ad489ca46892c2ff08d0861210d20befe25 [file] [log] [blame]
Backport boringssl patches to fix clang fall through warnings.
https://boringssl-review.googlesource.com/c/boringssl/+/37244
https://boringssl-review.googlesource.com/c/boringssl/+/37247
Author: Manoj Gupta <manojgupta@google.com>
Date: Mon Aug 26 09:13:58 2019 -0700
Add Fallthru support for clang 10.
clang has gained supoprted for __attribute__ ((fallthrough))
in https://reviews.llvm.org/rL369414.
Detect the support in clang and enable it as OPENSSL_FALLTHROUGH.
This is needed to fix ToT clang builds.
Bug: chromium:997709
Test: CQ
Change-Id: Iefa17687f6b5e8c95f359f167e9049d9a69c5302
diff --git a/crypto/internal.h b/crypto/internal.h
index 52799e899..92f5313f1 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -187,6 +187,12 @@ typedef __uint128_t uint128_t;
#define OPENSSL_FALLTHROUGH [[gnu::fallthrough]]
#elif defined(__GNUC__) && __GNUC__ >= 7 // gcc 7
#define OPENSSL_FALLTHROUGH __attribute__ ((fallthrough))
+#elif defined(__clang__)
+#if __has_attribute(fallthrough)
+#define OPENSSL_FALLTHROUGH __attribute__ ((fallthrough))
+#else // clang versions that do not support fallthrough.
+#define OPENSSL_FALLTHROUGH
+#endif
#else // C++11 on gcc 6, and all other cases
#define OPENSSL_FALLTHROUGH
#endif
diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c
index d89ec8a73..3722a5191 100644
--- a/crypto/asn1/tasn_enc.c
+++ b/crypto/asn1/tasn_enc.c
@@ -192,7 +192,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
/* Use indefinite length constructed if requested */
if (aclass & ASN1_TFLG_NDEF)
ndef = 2;
- /* fall through */
+ OPENSSL_FALLTHROUGH;
case ASN1_ITYPE_SEQUENCE:
i = asn1_enc_restore(&seqcontlen, out, pval, it);
diff --git a/crypto/fipsmodule/cipher/cipher.c b/crypto/fipsmodule/cipher/cipher.c
index 39e038beb..d0682ab37 100644
--- a/crypto/fipsmodule/cipher/cipher.c
+++ b/crypto/fipsmodule/cipher/cipher.c
@@ -191,7 +191,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
case EVP_CIPH_CFB_MODE:
ctx->num = 0;
- // fall-through
+ OPENSSL_FALLTHROUGH;
case EVP_CIPH_CBC_MODE:
assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof(ctx->iv));