1From 5177b28400e03d8666dfb3e65c3016b5062ce0f7 Mon Sep 17 00:00:00 2001 2From: Chih-Hung Hsieh <[email protected]> 3Date: Thu, 15 Nov 2018 16:07:02 -0800 4Subject: [PATCH] Update asserts in mojo about int64_t's alignment 5 6The purpose of these asserts is to check that the options structs are aligned 7sufficiently that an int64_t (or similar) could be added to them. The asserts 8were added in https://codereview.chromium.org/295383012 9 10However, the alignment of int64_t on 32-bit x86 is actually 4 bytes, not 8. So 11how did this ever work? Before Clang r345419, the alignof() operator (which is what 12MOJO_ALIGNOF maps to) would return the *preferred alignment* of a type, not 13the *ABI alignment*. That's not what the C and C++ standards specify, so the 14bug was fixed and the asserts started firing. (See also 15https://llvm.org/pr26547) 16 17To fix the build, change the asserts to check that int64_t requires 8 bytes 18alignment *or less*. 19 20Bug: 900406 21Bug: 119634736 22Change-Id: Icf80cea80ac31082423faab8c192420d0b98d515 23Reviewed-on: https://chromium-review.googlesource.com/c/1318971 24Commit-Queue: Ken Rockot <[email protected]> 25Reviewed-by: Ken Rockot <[email protected]> 26Cr-Commit-Position: refs/heads/master@{#605699} 27--- 28 mojo/core/options_validation_unittest.cc | 2 +- 29 mojo/public/c/system/buffer.h | 2 +- 30 mojo/public/c/system/data_pipe.h | 2 +- 31 mojo/public/c/system/message_pipe.h | 2 +- 32 4 files changed, 4 insertions(+), 4 deletions(-) 33 34diff --git a/mojo/core/options_validation_unittest.cc b/mojo/core/options_validation_unittest.cc 35index 52e0032..b4b02dc 100644 36--- a/mojo/core/options_validation_unittest.cc 37+++ b/mojo/core/options_validation_unittest.cc 38@@ -18,7 +18,7 @@ namespace { 39 40 using TestOptionsFlags = uint32_t; 41 42-static_assert(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 43+static_assert(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 44 struct MOJO_ALIGNAS(8) TestOptions { 45 uint32_t struct_size; 46 TestOptionsFlags flags; 47diff --git a/mojo/public/c/system/buffer.h b/mojo/public/c/system/buffer.h 48index 2cc5427..83b198b 100644 49--- a/mojo/public/c/system/buffer.h 50+++ b/mojo/public/c/system/buffer.h 51@@ -30,7 +30,7 @@ struct MOJO_ALIGNAS(8) MojoCreateSharedBufferOptions { 52 // See |MojoCreateSharedBufferFlags|. 53 MojoCreateSharedBufferFlags flags; 54 }; 55-MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 56+MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 57 MOJO_STATIC_ASSERT(sizeof(MojoCreateSharedBufferOptions) == 8, 58 "MojoCreateSharedBufferOptions has wrong size"); 59 60diff --git a/mojo/public/c/system/data_pipe.h b/mojo/public/c/system/data_pipe.h 61index 3702cdb..c72f553 100644 62--- a/mojo/public/c/system/data_pipe.h 63+++ b/mojo/public/c/system/data_pipe.h 64@@ -40,7 +40,7 @@ struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions { 65 // system-dependent capacity of at least one element in size. 66 uint32_t capacity_num_bytes; 67 }; 68-MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 69+MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 70 MOJO_STATIC_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16, 71 "MojoCreateDataPipeOptions has wrong size"); 72 73diff --git a/mojo/public/c/system/message_pipe.h b/mojo/public/c/system/message_pipe.h 74index 9f222f9..0f642dd 100644 75--- a/mojo/public/c/system/message_pipe.h 76+++ b/mojo/public/c/system/message_pipe.h 77@@ -35,7 +35,7 @@ struct MOJO_ALIGNAS(8) MojoCreateMessagePipeOptions { 78 // See |MojoCreateMessagePipeFlags|. 79 MojoCreateMessagePipeFlags flags; 80 }; 81-MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 82+MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) <= 8, "int64_t has weird alignment"); 83 MOJO_STATIC_ASSERT(sizeof(MojoCreateMessagePipeOptions) == 8, 84 "MojoCreateMessagePipeOptions has wrong size"); 85 86-- 872.20.0.rc0.387.gc7a69e6b6c-goog 88 89