Re: [edk2] [PATCH] MdePkg: resolve bug 741

2018-01-02 Thread Gao, Liming
I choose to disable this warning first, because there are other cases in edk2 
project. One is PI S3SaveState protocol EFI_S3_SAVE_STATE_WRITE API. This case 
needs to update PI spec. It may take more time. 

typedef
EFI_STATUS
(EFIAPI *EFI_S3_SAVE_STATE_WRITE)(
   IN CONST EFI_S3_SAVE_STATE_PROTOCOL  *This,
   IN   UINT16  OpCode,
   ...
);

Thanks
Liming
> -Original Message-
> From: Zenith432 [mailto:zenith...@users.sourceforge.net]
> Sent: Sunday, December 10, 2017 5:33 AM
> To: edk2-devel@lists.01.org; Marvin Häuser <marvin.haeu...@outlook.com>
> Cc: Kinney, Michael D <michael.d.kin...@intel.com>; Gao, Liming 
> <liming....@intel.com>
> Subject: RE: [edk2] [PATCH] MdePkg: resolve bug 741
> 
> It's the package maintainer's choice.  As a practical matter, silencing the 
> warning also works because...
> 
> 1. clang is the only compiler that complains.  Even though it complains, it 
> generates correct code because it has __builtin
> implementation of va_start that takes register argument and stack granularity 
> into account.
> 2. In MdePkg/Include/Base.h there are __builtin implementations of VA_START 
> for __CC_ARM, GCC and clang which should all work
> despite the argument promotion.
> 3. For the other architectures (i.e. Windows) there's an implementation of 
> VA_START in Base.h that uses _INT_SIZE_OF for the
> parameter always a multiple of UINTN.  The Windows compilers also have 
> builtin forms of va_start, but this non-builtin
> implementation looks ok for all arguments actually passed as variadic in EDK2.
> 
> 
> On Sat, 12/9/17, Marvin Häuser <marvin.haeu...@outlook.com> wrote:
> 
> ...
> It's your choice of course.
> ...
> 
>  Regards,
>  Marvin.
> 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg: resolve bug 741

2017-12-10 Thread Zenith432

On 10/12/2017 15:52, Gao, Liming wrote:
> For 4, 'unsigned char' goes default argument promotion to int. This 
is CLANG compiler behavior. Does GCC and VS compiler follow this rule?

>
> Disable varargs warning is the temp solution. For long term, we 
expect to figure out the compatible solution. If all supported compilers 
follow this rule, I think this is a compatible change.


It is STD C default argument promotion.  For example, C99 document n1570

section 6.5.2.2 (Function Calls)
"If the expression that denotes the called function has a type that does 
not include a prototype, the integer promotions are performed on each 
argument, and arguments that have type float are promoted to double. 
These are called the default argument promotions."


section 6.3.1.1 (Booleans, characters and integers)
"If an int can represent all values of the original type (as restricted 
by the width, for a bit-field), the value is converted to an int; 
otherwise, it is converted to an unsigned int. These are called the 
integer promotions."


section 7.16.1.4 (The va_start macro)
"If the parameter parmN is declared with the register storage class, 
with a function or array type, or with a type that is not compatible 
with the type that results after application of the default argument 
promotions, the behavior is undefined."


Technically, when there's a prototype that says the parameter is BOOLEAN 
(i.e. unsigned char), there is no "promotion" from the point of view of 
STDC.  Instead, it tries to convert the argument to BOOLEAN (if 
possible.)  Then the BOOLEAN is passed using whatever mechanism the 
implementation has to pass BOOLEANs (which is to fit them in a 4 or 
8-byte granular stack).  However, va_start wants a parameter type that 
is the outcome of a default argument promotion, and the outcome of a 
default argument promotion of 'unsigned char' is always int.


There's more discussion with longer quotes from the STD here
https://stackoverflow.com/questions/1255775/default-argument-promotions-in-c-function-calls
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg: resolve bug 741

2017-12-10 Thread Gao, Liming
For 4, 'unsigned char' goes default argument promotion to int. This is CLANG 
compiler behavior. Does GCC and VS compiler follow this rule?

Disable varargs warning is the temp solution. For long term, we expect to 
figure out the compatible solution. If all supported compilers follow this 
rule, I think this is a compatible change. 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Zenith432
> Sent: Sunday, December 10, 2017 3:44 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH] MdePkg: resolve bug 741
> 
> This is a proposal to resolve bug 741: UefiLib.c compilation failure with 
> clang
> error: passing an object that undergoes default argument promotion to 
> 'va_start' has undefined behavior [-Werror,-Wvarargs]"
> 
> Rationale:
> 1. Default argument promotion causes the sizeof a function's argument to be 
> different than the corresponding
> parameter's sizeof.  This may break a permissible implemenation of stdarg.h, 
> which is why it is considered
> undefined behavior in C.  The condition should be repaired rather than 
> silenced with -Wno-varargs.
> 2. The warning is due to the last non-variadic parameter of GetBestLanguage 
> having type BOOLEAN.
> 3. BOOLEAN is typedef'd to 'unsigned char' in all ProcessorBind.h.
> 4. 'unsigned char' goes default argument promotion to int.
> 5. All ProcessorBind.h typedef the type INT32 to either 'int' or some 32-bit 
> equivalent.
> 6. As a result it is safe to replace the type of the parameter from BOOLEAN 
> to INT32 in all
> current supported architectures.
> 7. The change is consistent with the BOOLEAN argument being converted to 
> INT32 at the caller site. The
> function GetBestLanguage currently converts the argument from INT32 back to 
> BOOLEAN, however
> the function's logic is not disturbed by treating the argument as an INT32.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Zenith432 <zenith...@users.sourceforge.net>
> ---
>  MdePkg/Include/Library/UefiLib.h | 2 +-
>  MdePkg/Library/UefiLib/UefiLib.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/MdePkg/Include/Library/UefiLib.h 
> b/MdePkg/Include/Library/UefiLib.h
> index 0b14792a..5d98eb26 100644
> --- a/MdePkg/Include/Library/UefiLib.h
> +++ b/MdePkg/Include/Library/UefiLib.h
> @@ -818,7 +818,7 @@ CHAR8 *
>  EFIAPI
>  GetBestLanguage (
>IN CONST CHAR8  *SupportedLanguages,
> -  IN BOOLEAN  Iso639Language,
> +  IN INT32Iso639Language,
>...
>);
> 
> diff --git a/MdePkg/Library/UefiLib/UefiLib.c 
> b/MdePkg/Library/UefiLib/UefiLib.c
> index a7eee012..57236511 100644
> --- a/MdePkg/Library/UefiLib/UefiLib.c
> +++ b/MdePkg/Library/UefiLib/UefiLib.c
> @@ -1514,7 +1514,7 @@ CHAR8 *
>  EFIAPI
>  GetBestLanguage (
>IN CONST CHAR8  *SupportedLanguages,
> -  IN BOOLEAN  Iso639Language,
> +  IN INT32Iso639Language,
>...
>)
>  {
> --
> 2.14.3 (Apple Git-98)
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg: resolve bug 741

2017-12-09 Thread Zenith432
It's the package maintainer's choice.  As a practical matter, silencing the 
warning also works because...

1. clang is the only compiler that complains.  Even though it complains, it 
generates correct code because it has __builtin implementation of va_start that 
takes register argument and stack granularity into account.
2. In MdePkg/Include/Base.h there are __builtin implementations of VA_START for 
__CC_ARM, GCC and clang which should all work despite the argument promotion.
3. For the other architectures (i.e. Windows) there's an implementation of 
VA_START in Base.h that uses _INT_SIZE_OF for the parameter always a multiple 
of UINTN.  The Windows compilers also have builtin forms of va_start, but this 
non-builtin implementation looks ok for all arguments actually passed as 
variadic in EDK2.


On Sat, 12/9/17, Marvin Häuser  wrote:

...
It's your choice of course.
...

 Regards,
 Marvin.
 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg: resolve bug 741

2017-12-09 Thread Marvin Häuser
I prefer my route because it preserves BOOLEAN (descriptive) and fixes the 
issue obviously (the last named parameter is what is passed). It's your choice 
of course.

By the way, all of your other patch e-mails do not CC the package maintainer. 
They may not see them this way, so I suggest resending CC'ing the package 
maintainers.

Regards,
Marvin.

> -Original Message-
> From: Zenith432 [mailto:zenith...@users.sourceforge.net]
> Sent: Saturday, December 9, 2017 9:40 PM
> To: edk2-devel@lists.01.org; Marvin H?user
> <marvin.haeu...@outlook.com>
> Cc: michael.d.kin...@intel.com; liming@intel.com
> Subject: RE: [edk2] [PATCH] MdePkg: resolve bug 741
> 
> FWIW, I tried another solution by replacing the statement
> 
> VA_START (Args, Iso639Language);
> 
> with
> 
> VA_START (Args, *(int*));
> 
> in an attempt to get an lvalue with the same address-of as Iso639Language
> and correct sizeof the promoted argument, but clang doesn't like that either
> 
> error: second argument to 'va_start' is not the last named parameter [-
> Werror,-Wvarargs]
> 
> 
> On Sat, 12/9/17, Marvin H?user <marvin.haeu...@outlook.com> wrote:
> 
>  Subject: RE: [edk2] [PATCH] MdePkg: resolve bug 741
>  To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
>  Cc: "Zenith432" <zenith...@users.sourceforge.net>,
> "michael.d.kin...@intel.com" <michael.d.kin...@intel.com>,
> "liming@intel.com" <liming@intel.com>
>  Date: Saturday, December 9, 2017, 10:22 PM
> 
>  For code style purposes, I suggest to declare  the first member of the
> language list as a third argument,  process it, and then use it to get the
> following from the  VA.
>  Also, I think you forgot to CC the
>  MdePkg maintainers, so I did with this mail.
> 
>  Regards,
>  Marvin.
> 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdePkg: resolve bug 741

2017-12-09 Thread Zenith432
This is a proposal to resolve bug 741: UefiLib.c compilation failure with clang
error: passing an object that undergoes default argument promotion to 
'va_start' has undefined behavior [-Werror,-Wvarargs]"

Rationale:
1. Default argument promotion causes the sizeof a function's argument to be 
different than the corresponding
parameter's sizeof.  This may break a permissible implemenation of stdarg.h, 
which is why it is considered
undefined behavior in C.  The condition should be repaired rather than silenced 
with -Wno-varargs.
2. The warning is due to the last non-variadic parameter of GetBestLanguage 
having type BOOLEAN.
3. BOOLEAN is typedef'd to 'unsigned char' in all ProcessorBind.h.
4. 'unsigned char' goes default argument promotion to int.
5. All ProcessorBind.h typedef the type INT32 to either 'int' or some 32-bit 
equivalent.
6. As a result it is safe to replace the type of the parameter from BOOLEAN to 
INT32 in all
current supported architectures.
7. The change is consistent with the BOOLEAN argument being converted to INT32 
at the caller site. The
function GetBestLanguage currently converts the argument from INT32 back to 
BOOLEAN, however
the function's logic is not disturbed by treating the argument as an INT32.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zenith432 
---
 MdePkg/Include/Library/UefiLib.h | 2 +-
 MdePkg/Library/UefiLib/UefiLib.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h
index 0b14792a..5d98eb26 100644
--- a/MdePkg/Include/Library/UefiLib.h
+++ b/MdePkg/Include/Library/UefiLib.h
@@ -818,7 +818,7 @@ CHAR8 *
 EFIAPI
 GetBestLanguage (
   IN CONST CHAR8  *SupportedLanguages, 
-  IN BOOLEAN  Iso639Language,
+  IN INT32Iso639Language,
   ...
   );
 
diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c
index a7eee012..57236511 100644
--- a/MdePkg/Library/UefiLib/UefiLib.c
+++ b/MdePkg/Library/UefiLib/UefiLib.c
@@ -1514,7 +1514,7 @@ CHAR8 *
 EFIAPI
 GetBestLanguage (
   IN CONST CHAR8  *SupportedLanguages, 
-  IN BOOLEAN  Iso639Language,
+  IN INT32Iso639Language,
   ...
   )
 {
-- 
2.14.3 (Apple Git-98)
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel