From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: michael.d.kinney@intel.com) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by groups.io with SMTP; Wed, 14 Aug 2019 08:47:23 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Aug 2019 08:47:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,385,1559545200"; d="scan'208";a="205583901" Received: from orsmsx102.amr.corp.intel.com ([10.22.225.129]) by fmsmga002.fm.intel.com with ESMTP; 14 Aug 2019 08:47:22 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.177]) by ORSMSX102.amr.corp.intel.com ([169.254.3.11]) with mapi id 14.03.0439.000; Wed, 14 Aug 2019 08:47:22 -0700 From: "Michael D Kinney" To: "devel@edk2.groups.io" , "Gao, Liming" , "vit9696@protonmail.com" , "Kinney, Michael D" Subject: Re: [edk2-devel] [PATCH v2 1/1] MdePkg: Add STATIC_ASSERT macro Thread-Topic: [edk2-devel] [PATCH v2 1/1] MdePkg: Add STATIC_ASSERT macro Thread-Index: AQHVUbKarQboXB8rYEaaNG3pkStHNqb7IGiA//+oeuA= Date: Wed, 14 Aug 2019 15:47:22 +0000 Message-ID: References: <20190813081644.53963-1-vit9696@protonmail.com> <20190813081644.53963-2-vit9696@protonmail.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E4D0EC7@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E4D0EC7@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Liming, I think a good candidate to demonstrate this feature are the checks made in MdePkg/Include/Base.h. The current implementation forces a divide by 0=20 in the C pre-processor to break the build. STATIC_ASSERT() would be a better way to do this. I would also remove unused externs from the builds. /** Verifies the storage size of a given data type. This macro generates a divide by zero error or a zero size array declara= tion in the preprocessor if the size is incorrect. These are declared as "exter= n" so the space for these arrays will not be in the modules. @param TYPE The date type to determine the size of. @param Size The expected size for the TYPE. **/ #define VERIFY_SIZE_OF(TYPE, Size) extern UINT8 _VerifySizeof##TYPE[(sizeo= f(TYPE) =3D=3D (Size)) / (sizeof(TYPE) =3D=3D (Size))] // // Verify that ProcessorBind.h produced UEFI Data Types that are compliant= with // Section 2.3.1 of the UEFI 2.3 Specification. // VERIFY_SIZE_OF (BOOLEAN, 1); VERIFY_SIZE_OF (INT8, 1); VERIFY_SIZE_OF (UINT8, 1); VERIFY_SIZE_OF (INT16, 2); VERIFY_SIZE_OF (UINT16, 2); VERIFY_SIZE_OF (INT32, 4); VERIFY_SIZE_OF (UINT32, 4); VERIFY_SIZE_OF (INT64, 8); VERIFY_SIZE_OF (UINT64, 8); VERIFY_SIZE_OF (CHAR8, 1); VERIFY_SIZE_OF (CHAR16, 2); // // The following three enum types are used to verify that the compiler // configuration for enum types is compliant with Section 2.3.1 of the // UEFI 2.3 Specification. These enum types and enum values are not // intended to be used. A prefix of '__' is used avoid conflicts with // other types. // typedef enum { __VerifyUint8EnumValue =3D 0xff } __VERIFY_UINT8_ENUM_SIZE; typedef enum { __VerifyUint16EnumValue =3D 0xffff } __VERIFY_UINT16_ENUM_SIZE; typedef enum { __VerifyUint32EnumValue =3D 0xffffffff } __VERIFY_UINT32_ENUM_SIZE; VERIFY_SIZE_OF (__VERIFY_UINT8_ENUM_SIZE, 4); VERIFY_SIZE_OF (__VERIFY_UINT16_ENUM_SIZE, 4); VERIFY_SIZE_OF (__VERIFY_UINT32_ENUM_SIZE, 4); A couple examples. Do all the compilers support the message parameter too= ? STATIC_ASSERT (sizeof (BOOLEAN) =3D=3D 1, "sizeof (BOOLEAN) does not meet = UEFI Specification Data Type requirements") STATIC_ASSERT (sizeof (UINT16) =3D=3D 2, "sizeof (UINT16) does not meet U= EFI Specification Data Type requirements") STATIC_ASSERT (sizeof (INT32) =3D=3D 4, "sizeof (INT32) does not meet UE= FI Specification Data Type requirements") STATIC_ASSERT (sizeof (CHAR16) =3D=3D 2, "sizeof (CHAR16) does not meet U= EFI Specification Data Type requirements") STATIC_ASSERT (sizeof (__VERIFY_UINT8_ENUM_SIZE) =3D=3D 4, "Size of enum d= oes not meet UEFI Specification Data Type requirements") STATIC_ASSERT (sizeof (__VERIFY_UINT32_ENUM_SIZE) =3D=3D 4, "Size of enum = does not meet UEFI Specification Data Type requirements") Thanks, Mike > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] > On Behalf Of Liming Gao > Sent: Wednesday, August 14, 2019 6:50 AM > To: devel@edk2.groups.io; vit9696@protonmail.com > Subject: Re: [edk2-devel] [PATCH v2 1/1] MdePkg: Add > STATIC_ASSERT macro >=20 > Can you add the sample usage of new macro STATIC_ASSERT? >=20 > Or, give the link of static_assert or _Static_assert. >=20 > If so, the developer knows how to use them in source > code. >=20 > Thanks > Liming > > -----Original Message----- > > From: devel@edk2.groups.io > [mailto:devel@edk2.groups.io] On Behalf Of > > vit9696 via Groups.Io > > Sent: Tuesday, August 13, 2019 4:17 PM > > To: devel@edk2.groups.io > > Subject: [edk2-devel] [PATCH v2 1/1] MdePkg: Add > STATIC_ASSERT macro > > > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2048 > > > > Provide a macro for compile time assertions. > > Equivalent to C11 static_assert macro from assert.h. > > > > Signed-off-by: Vitaly Cheptsov > > > --- > > MdePkg/Include/Base.h | 11 +++++++++++ > > 1 file changed, 11 insertions(+) > > > > diff --git a/MdePkg/Include/Base.h > b/MdePkg/Include/Base.h index > > ce20b5f01dce..f85f7028a262 100644 > > --- a/MdePkg/Include/Base.h > > +++ b/MdePkg/Include/Base.h > > @@ -843,6 +843,17 @@ typedef UINTN *BASE_LIST; > #define > > OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field)) > #endif > > > > +/// > > +/// Portable definition for compile time assertions. > > +/// Equivalent to C11 static_assert macro from > assert.h. > > +/// Takes condtion and error message as its > arguments. > > +/// > > +#ifdef _MSC_EXTENSIONS > > + #define STATIC_ASSERT static_assert #else > > + #define STATIC_ASSERT _Static_assert #endif > > + > > /** > > Macro that returns a pointer to the data structure > that contains a specified field of > > that data structure. This is a lightweight method > to hide > > information by placing a > > -- > > 2.20.1 (Apple Git-117) > > > > > > -=3D-=3D-=3D-=3D-=3D-=3D > > Groups.io Links: You receive all messages sent to this > group. > > > > View/Reply Online (#45503): > > https://edk2.groups.io/g/devel/message/45503 > > Mute This Topic: https://groups.io/mt/32850582/1759384 > > Group Owner: devel+owner@edk2.groups.io > > Unsubscribe: https://edk2.groups.io/g/devel/unsub > > [liming.gao@intel.com] -=3D-=3D-=3D-=3D-=3D-=3D >=20 >=20 >=20