summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoj Gupta <manojgupta@google.com>2019-08-27 15:45:39 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-28 19:37:14 +0000
commitafd52397565311166a97f7681209c2f9d3a2d37a (patch)
tree42b978dbc7e0dfa1729cf3c8de7e842915eb9648
parent090279951f8cd0f23bf38c4fb72c2b1f3a465ddf (diff)
downloadvboot-afd52397565311166a97f7681209c2f9d3a2d37a.tar.gz
Fix fall through warning reported by ToT clang.
Clang is diagnosing implicit fallthrough in C code past https://reviews.llvm.org/rL369414. Detect the support for the fallthrough attributes in gcc/clang and enable it as VBOOT_FALLTHROUGH (copied from boringssl). This is needed to fix ToT clang builds. Note: GCC apparently does not diagnose fallthrough to another case with break but clang does (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91432). And clang does not detect the fallthrough based on code comments. Bug: chromium:997709 Test: CQ Change-Id: Id8b4be4deabca2d0f1b2efd80efa72a485a5dc8c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1772474 Tested-by: Manoj Gupta <manojgupta@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@chromium.org> Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
-rw-r--r--firmware/2lib/include/2common.h21
-rw-r--r--firmware/lib/cgptlib/cgptlib.c2
-rw-r--r--firmware/lib/vboot_ui.c4
-rw-r--r--futility/cmd_dump_fmap.c4
-rw-r--r--futility/cmd_sign.c2
-rw-r--r--host/lib/crossystem.c1
6 files changed, 28 insertions, 6 deletions
diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h
index d49074f8..600dffbe 100644
--- a/firmware/2lib/include/2common.h
+++ b/firmware/2lib/include/2common.h
@@ -53,6 +53,27 @@ struct vb2_public_key;
#endif
#endif
+// Have a generic fall-through for different versions of C/C++.
+// Taken from boringssl.
+#if defined(__cplusplus) && __cplusplus >= 201703L
+#define VBOOT_FALLTHROUGH [[fallthrough]]
+#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__clang__)
+#define VBOOT_FALLTHROUGH [[clang::fallthrough]]
+#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__GNUC__) && \
+ __GNUC__ >= 7
+#define VBOOT_FALLTHROUGH [[gnu::fallthrough]]
+#elif defined(__GNUC__) && __GNUC__ >= 7 // gcc 7
+#define VBOOT_FALLTHROUGH __attribute__ ((fallthrough))
+#elif defined(__clang__)
+#if __has_attribute(fallthrough)
+#define VBOOT_FALLTHROUGH __attribute__ ((fallthrough))
+#else // clang versions that do not support fallthrough.
+#define VBOOT_FALLTHROUGH
+#endif
+#else // C++11 on gcc 6, and all other cases
+#define VBOOT_FALLTHROUGH
+#endif
+
/**
* Round up a number to a multiple of VB2_WORKBUF_ALIGN
*
diff --git a/firmware/lib/cgptlib/cgptlib.c b/firmware/lib/cgptlib/cgptlib.c
index f8b3cb40..25a2fe27 100644
--- a/firmware/lib/cgptlib/cgptlib.c
+++ b/firmware/lib/cgptlib/cgptlib.c
@@ -145,7 +145,7 @@ int GptUpdateKernelWithEntry(GptData *gpt, GptEntry *e, uint32_t update_type)
}
/* Out of tries, so drop through and mark partition bad. */
}
- /* fall through */
+ VBOOT_FALLTHROUGH;
case GPT_UPDATE_ENTRY_BAD: {
/* Giving up on this partition entirely. */
if (!GetEntrySuccessful(e)) {
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index ee770ccd..ec0b812c 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -272,7 +272,7 @@ static vb2_error_t vb2_enter_vendor_data_ui(struct vb2_context *ctx,
return VB2_SUCCESS;
case 'a'...'z':
key = toupper(key);
- /* fall through */
+ VBOOT_FALLTHROUGH;
case '0'...'9':
case 'A'...'Z':
if ((len > 0 && is_vowel(key)) ||
@@ -608,7 +608,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx)
/* Only disable virtual dev switch if allowed by GBB */
if (!(gbb->flags & VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM))
break;
- /* fall through */
+ VBOOT_FALLTHROUGH;
case ' ':
/* See if we should disable virtual dev-mode switch. */
VB2_DEBUG("shared->flags=0x%x\n", shared->flags);
diff --git a/futility/cmd_dump_fmap.c b/futility/cmd_dump_fmap.c
index 2ed0ff6b..170889b8 100644
--- a/futility/cmd_dump_fmap.c
+++ b/futility/cmd_dump_fmap.c
@@ -444,7 +444,7 @@ static int do_dump_fmap(int argc, char *argv[])
break;
case 'H':
opt_gaps = 1;
- /* fallthrough */
+ VBOOT_FALLTHROUGH;
case 'h':
opt_format = FMT_HUMAN;
opt_overlap++;
@@ -507,7 +507,7 @@ static int do_dump_fmap(int argc, char *argv[])
case FMT_NORMAL:
printf("hit at 0x%08x\n",
(uint32_t) ((char *)fmap - (char *)base_of_rom));
- /* fallthrough */
+ VBOOT_FALLTHROUGH;
default:
retval = normal_fmap(fmap,
argc - optind - 1,
diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c
index 9393cdaa..f221141a 100644
--- a/futility/cmd_sign.c
+++ b/futility/cmd_sign.c
@@ -721,7 +721,7 @@ static int do_sign(int argc, char *argv[])
break;
case OPT_FV:
sign_option.fv_specified = 1;
- /* fallthrough */
+ VBOOT_FALLTHROUGH;
case OPT_INFILE:
sign_option.inout_file_count++;
infile = optarg;
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index 061d4b71..9b89fdc1 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -424,6 +424,7 @@ static int GetVdatInt(VdatIntField field)
break;
case VDAT_INT_FW_BOOT2:
value = (sh->flags & VBSD_BOOT_FIRMWARE_VBOOT2 ? 1 : 0);
+ VBOOT_FALLTHROUGH;
default:
break;
}