Commit 16035729 authored by Hans Wennborg's avatar Hans Wennborg Committed by Commit Bot

Update asserts in mojo about int64_t's alignment

The purpose of these asserts is to check that the options structs are aligned
sufficiently that an int64_t (or similar) could be added to them. The asserts
were added in https://codereview.chromium.org/295383012

However, the alignment of int64_t on 32-bit x86 is actually 4 bytes, not 8. So
how did this ever work? Before Clang r345419, the alignof() operator (which is what
MOJO_ALIGNOF maps to) would return the *preferred alignment* of a type, not
the *ABI alignment*. That's not what the C and C++ standards specify, so the
bug was fixed and the asserts started firing. (See also
https://llvm.org/pr26547)

To fix the build, change the asserts to check that int64_t requires 8 bytes
alignment *or less*.

Bug: 900406
Change-Id: Icf80cea80ac31082423faab8c192420d0b98d515
Reviewed-on: https://chromium-review.googlesource.com/c/1318971
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#605699}
parent 211d4b75
......@@ -18,7 +18,7 @@ namespace {
using TestOptionsFlags = uint32_t;
static_assert(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
static_assert(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment");
struct MOJO_ALIGNAS(8) TestOptions {
uint32_t struct_size;
TestOptionsFlags flags;
......
......@@ -30,7 +30,7 @@ struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions {
// See |MojoCreateSharedBufferFlags|.
MojoCreateSharedBufferFlags flags;
};
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8,
"MojoCreateSharedBufferOptions has wrong size");
......
......@@ -40,7 +40,7 @@ struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions {
// system-dependent capacity of at least one element in size.
uint32_t capacity_num_bytes;
};
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16,
"MojoCreateDataPipeOptions has wrong size");
......
......@@ -35,7 +35,7 @@ struct MOJO_ALIGNAS(8) MojoCreateMessagePipeOptions {
// See |MojoCreateMessagePipeFlags|.
MojoCreateMessagePipeFlags flags;
};
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment");
MOJO_STATIC_ASSERT(sizeof(MojoCreateMessagePipeOptions) == 8,
"MojoCreateMessagePipeOptions has wrong size");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment