From: Zenith432 <zenith432@users.sourceforge.net>
To: "Gao, Liming" <liming.gao@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH] MdePkg: resolve bug 741
Date: Sun, 10 Dec 2017 16:41:07 +0200 [thread overview]
Message-ID: <05ee2c7d-b11e-8766-f6e9-fe8d4ae47019@users.sourceforge.net> (raw)
In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E18E292@SHSMSX104.ccr.corp.intel.com>
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
next prev parent reply other threads:[~2017-12-10 14:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <541697813.1899563.1512848632833.ref@mail.yahoo.com>
2017-12-09 19:43 ` [PATCH] MdePkg: resolve bug 741 Zenith432
2017-12-09 20:22 ` Marvin H?user
2017-12-10 13:52 ` Gao, Liming
2017-12-10 14:41 ` Zenith432 [this message]
[not found] <1822489314.1922023.1512852000221.ref@mail.yahoo.com>
2017-12-09 20:40 ` Zenith432
2017-12-09 20:57 ` Marvin Häuser
[not found] <617598899.1906935.1512855198518.ref@mail.yahoo.com>
2017-12-09 21:33 ` Zenith432
2018-01-03 2:06 ` Gao, Liming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=05ee2c7d-b11e-8766-f6e9-fe8d4ae47019@users.sourceforge.net \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox