public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg: Add STATIC_ASSERT macro
@ 2019-08-12 10:05 vit9696
  2019-08-12 21:12 ` [edk2-devel] " Michael D Kinney
  2019-08-13 12:28 ` Laszlo Ersek
  0 siblings, 2 replies; 5+ messages in thread
From: vit9696 @ 2019-08-12 10:05 UTC (permalink / raw)
  To: devel@edk2.groups.io


[-- Attachment #1.1.1: Type: text/plain, Size: 100 bytes --]

Implements https://bugzilla.tianocore.org/show_bug.cgi?id=2048.

Best regards,
Vitaly Cheptsov

[-- Attachment #1.1.2.1: Type: text/html, Size: 218 bytes --]

[-- Attachment #1.2: 0001-MdePkg-Add-STATIC_ASSERT-macro.patch --]
[-- Type: application/octet-stream, Size: 1287 bytes --]

From 4e388637cc9004ef8befdd7fa6c9446c96daf011 Mon Sep 17 00:00:00 2001
From: Vitaly Cheptsov <vit9696@protonmail.com>
Date: Mon, 12 Aug 2019 12:43:06 +0300
Subject: [PATCH] MdePkg: Add STATIC_ASSERT macro

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2048

Provide a macro for compile time assertions.
Equivalent to C11 static_assert macro from assert.h.

Signed-off-by: Vitaly Cheptsov <vit9696@protonmail.com>
---
 MdePkg/Include/Base.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index ce20b5f01d..0162192f71 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_VER
+  #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)


[-- Attachment #1.3: publickey - vit9696@protonmail.com - 0x44529644.asc --]
[-- Type: application/pgp-keys, Size: 1817 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 477 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] MdePkg: Add STATIC_ASSERT macro
@ 2019-08-12 10:56 vit9696
  0 siblings, 0 replies; 5+ messages in thread
From: vit9696 @ 2019-08-12 10:56 UTC (permalink / raw)
  To: devel@edk2.groups.io


[-- Attachment #1.1.1: Type: text/plain, Size: 100 bytes --]

Implements https://bugzilla.tianocore.org/show_bug.cgi?id=2048.

Best regards,
Vitaly Cheptsov

[-- Attachment #1.1.2.1: Type: text/html, Size: 2431 bytes --]

[-- Attachment #1.2: 0001-MdePkg-Add-STATIC_ASSERT-macro.patch --]
[-- Type: application/octet-stream, Size: 1287 bytes --]

From 4e388637cc9004ef8befdd7fa6c9446c96daf011 Mon Sep 17 00:00:00 2001
From: Vitaly Cheptsov <vit9696@protonmail.com>
Date: Mon, 12 Aug 2019 12:43:06 +0300
Subject: [PATCH] MdePkg: Add STATIC_ASSERT macro

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2048

Provide a macro for compile time assertions.
Equivalent to C11 static_assert macro from assert.h.

Signed-off-by: Vitaly Cheptsov <vit9696@protonmail.com>
---
 MdePkg/Include/Base.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index ce20b5f01d..0162192f71 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_VER
+  #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)


[-- Attachment #1.3: publickey - vit9696@protonmail.com - 0x44529644.asc --]
[-- Type: application/pgp-keys, Size: 1817 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 477 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [PATCH] MdePkg: Add STATIC_ASSERT macro
  2019-08-12 10:05 [PATCH] MdePkg: Add STATIC_ASSERT macro vit9696
@ 2019-08-12 21:12 ` Michael D Kinney
  2019-08-13 12:28 ` Laszlo Ersek
  1 sibling, 0 replies; 5+ messages in thread
From: Michael D Kinney @ 2019-08-12 21:12 UTC (permalink / raw)
  To: devel@edk2.groups.io, vit9696@protonmail.com, Kinney, Michael D

Hi Vitaly,

Thanks for the contribution.  I see you are using _MSC_VER.  
The rest of Base.h uses _MSC_EXTENSIONs and only if that is
defined is _MSC_VER used and _MSC_VER is only used if a specific
version value check is required.  What version of VS introduced
this feature?  We can define this macro to nothing of the
version is too small.  Also, is the mapping for both GCC and
XCODE5 the same?

For the next version of this patch, can you use the ‘git send-email’
feature instead of attaching a patch file?  A couple useful links:

https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Development-Process

https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-guide-for-edk2-contributors-and-maintainers

Thanks,

Mike



From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of via Groups.Io
Sent: Monday, August 12, 2019 3:06 AM
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH] MdePkg: Add STATIC_ASSERT macro

Implements https://bugzilla.tianocore.org/show_bug.cgi?id=2048.

Best regards,
Vitaly Cheptsov


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [PATCH] MdePkg: Add STATIC_ASSERT macro
  2019-08-12 10:05 [PATCH] MdePkg: Add STATIC_ASSERT macro vit9696
  2019-08-12 21:12 ` [edk2-devel] " Michael D Kinney
@ 2019-08-13 12:28 ` Laszlo Ersek
       [not found]   ` <45B1F80A-14DF-4300-BE67-FE408398DDEE@protonmail.com>
  1 sibling, 1 reply; 5+ messages in thread
From: Laszlo Ersek @ 2019-08-13 12:28 UTC (permalink / raw)
  To: devel, vit9696

On 08/12/19 12:05,  via Groups.Io wrote:
> Implements https://bugzilla.tianocore.org/show_bug.cgi?id=2048.
> 
> Best regards,
> Vitaly Cheptsov
> 
> 
> 
> 
> 
> 0001-MdePkg-Add-STATIC_ASSERT-macro.patch
> 
> 
> From 4e388637cc9004ef8befdd7fa6c9446c96daf011 Mon Sep 17 00:00:00 2001
> From: Vitaly Cheptsov <vit9696@protonmail.com>
> Date: Mon, 12 Aug 2019 12:43:06 +0300
> Subject: [PATCH] MdePkg: Add STATIC_ASSERT macro
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2048
> 
> Provide a macro for compile time assertions.
> Equivalent to C11 static_assert macro from assert.h.
> 
> Signed-off-by: Vitaly Cheptsov <vit9696@protonmail.com>
> ---
>  MdePkg/Include/Base.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index ce20b5f01d..0162192f71 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_VER
> +  #define STATIC_ASSERT static_assert
> +#else
> +  #define STATIC_ASSERT _Static_assert

The oldest GCC toolchain that edk2 supports is GCC48. Will
_Static_assert work with gcc-4.8?

Thanks
Laszlo

> +#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)
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [PATCH] MdePkg: Add STATIC_ASSERT macro
       [not found]   ` <45B1F80A-14DF-4300-BE67-FE408398DDEE@protonmail.com>
@ 2019-08-14 15:30     ` Laszlo Ersek
  0 siblings, 0 replies; 5+ messages in thread
From: Laszlo Ersek @ 2019-08-14 15:30 UTC (permalink / raw)
  To: vit9696@protonmail.com; +Cc: edk2-devel-groups-io

(adding back the list)

On 08/13/19 16:30, vit9696@protonmail.com wrote:
> Laszlo,
> 
> GCC implemented _Static_assert in 4.6. See its official wiki for C11 compatibility documentation:
> 
> https://gcc.gnu.org/wiki/C11Status

Awesome news!

Once this is upstreamed, we should go through all the ASSERT()s in the
code, and replace those that are compile-time checkable with
STATIC_ASSERT(). I know that I've added quite a few ASSERT()s that I
wished would be checked at build time.

Of course, I'll probably never have time for that. :/

Thanks
Laszlo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-14 15:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-12 10:05 [PATCH] MdePkg: Add STATIC_ASSERT macro vit9696
2019-08-12 21:12 ` [edk2-devel] " Michael D Kinney
2019-08-13 12:28 ` Laszlo Ersek
     [not found]   ` <45B1F80A-14DF-4300-BE67-FE408398DDEE@protonmail.com>
2019-08-14 15:30     ` Laszlo Ersek
  -- strict thread matches above, loose matches on Subject: below --
2019-08-12 10:56 vit9696

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox