Re: [Edk2 Dev] We are having a few portability issues with enums...

Subject: Re: [Edk2 Dev] We are having a few portability issues with enums...

From: Andrew Fish <afish@apple.com>

To: dev@edk2.tianocore.org

Date: 2008-05-28 22:05:24

Randy,

We are using the iPhone SDK gcc.

*_CC_FLAGS =3D -arch armv6 -mthumb -mabi=3Daapcs -mapcs -Os -save-temps =
-=20
combine -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-missing-=20=

braces -fomit-frame-pointer -c -include AutoGen.h

It looks like the error is very sensitive to the -mthumb -mabi=3Daapcs =20=

switches.  We only see this specific error with the ARM -arch and the =20=

two switches I mentioned. We don't see the error with the compiler you =20=

were using, i686-apple-darwin9-gcc-4.0.1.

Andrew Fish
afish@apple.com
Work iPhone: 360-259-7562




On May 28, 2008, at 1:08 PM, Randy Thelen wrote:

> Andrew Fish wrote:
>
>> When we throw a new GCC  compiler  version at this library function =20=

>> we
>> get the following error:
>> warning: comparison is always true due to limited range of data type
>>
>> EFI_STATUS
>> IpIoGetIcmpErrStatus (
>>  IN  ICMP_ERROR  IcmpError,
>>  OUT BOOLEAN     *IsHard, OPTIONAL
>>  OUT BOOLEAN     *Notify OPTIONAL
>>  )
>> {
>>  ASSERT ((IcmpError >=3D ICMP_ERR_UNREACH_NET) && (IcmpError <=3D
>> ICMP_ERR_PARAMPROB));
>
> I presume you're using either the Edk1/Sample/Universal/Network/=20
> Library/IcmpIo.h or the Edk2/edk2/MdeModulePkg/Include/Library/=20
> IpIoLib.h version of the ICMP_ERROR definition; both appear to be =20
> the same.  Which looks like:
>
> typedef enum {
>  ICMP_ERR_UNREACH_NET      =3D 0,
>  ICMP_ERR_UNREACH_HOST,
>  ICMP_ERR_UNREACH_PROTOCOL,
>  ICMP_ERR_UNREACH_PORT,
>  ICMP_ERR_MSGSIZE,
>  ICMP_ERR_UNREACH_SRCFAIL,
>  ICMP_ERR_TIMXCEED_INTRANS,
>  ICMP_ERR_TIMXCEED_REASS,
>  ICMP_ERR_QUENCH,
>  ICMP_ERR_PARAMPROB
> } ICMP_ERROR;
>
> In that case, I grabbed that enum and jammed it into a small =20
> function and compiled it:
>
> $ cat test.c
> #include 
>
> typedef enum {
>  ICMP_ERR_UNREACH_NET      =3D 0,
>  ICMP_ERR_UNREACH_HOST,
>  ICMP_ERR_PARAMPROB
> } ICMP_ERROR;
>
> static void testme(ICMP_ERROR a) {
>  if ((a >=3D ICMP_ERR_UNREACH_NET) && (a <=3D ICMP_ERR_PARAMPROB)) {
>    printf("Hello there\n");
>  }
> }
>
> int main(void)
> {
>  testme(ICMP_ERR_UNREACH_HOST);
>  return 0;
> }
>
> $ cc -Wall test.c
> $ cc -Wall -Wextra test.c
> test.c: In function =91testme=92:
> test.c:10: warning: comparison of unsigned expression >=3D 0 is always =
=20
> true
> $
>
> In my example, possibly using a slightly different compiler than =20
> yours (mine: i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. =20
> build 5465)), I got an error because enums are unsigned ints, and =20
> the >=3D 0 test is pointless.
>
> Your error, however, seems to stem from a different issue.  A google =20=

> search coughed up examples where bit fields whose contents are enums =20=

> could generate your error if the bit field's width is smaller than =20
> that required for the range of the enum.
>
> Could you give a small example of how to reproduce your error?  And, =20=

> include the specific compiler version you're using?  And include the =20=

> compiler options.
>
>
>> We also see this problem in the DXE Core:
>>
>> STATIC
>> EFI_STATUS
>> CoreAllocateSpace (
>>  IN     UINTN                  Operation,
>>  IN     EFI_GCD_ALLOCATE_TYPE  GcdAllocateType,
>>  IN     EFI_GCD_MEMORY_TYPE    GcdMemoryType,
>>  IN     EFI_GCD_IO_TYPE        GcdIoType,
>>  IN     UINTN                  Alignment,
>>  IN     UINT64                 Length,
>>  IN OUT EFI_PHYSICAL_ADDRESS   *BaseAddress,
>>  IN     EFI_HANDLE             ImageHandle,
>>  IN     EFI_HANDLE             DeviceHandle OPTIONAL
>>  )
>> {
>>  EFI_STATUS            Status;
>>  EFI_PHYSICAL_ADDRESS  AlignmentMask;
>>  EFI_PHYSICAL_ADDRESS  MaxAddress;
>>  LIST_ENTRY            *Map;
>>  LIST_ENTRY            *Link;
>>  LIST_ENTRY            *SubLink;
>>  EFI_GCD_MAP_ENTRY     *Entry;
>>  EFI_GCD_MAP_ENTRY     *TopEntry;
>>  EFI_GCD_MAP_ENTRY     *BottomEntry;
>>  LIST_ENTRY            *StartLink;
>>  LIST_ENTRY            *EndLink;
>>  BOOLEAN               Found;
>>
>>  //
>>  // Make sure parameters are valid
>>  //
>>  if (GcdAllocateType < 0 || GcdAllocateType >=3D
>> EfiGcdMaxAllocateType) {
>>    return EFI_INVALID_PARAMETER;
>>  }
>>  if (GcdMemoryType < 0 || GcdMemoryType >=3D EfiGcdMemoryTypeMaximum) =
{
>>    return EFI_INVALID_PARAMETER;
>>  }
>>  if (GcdIoType < 0 || GcdIoType >=3D EfiGcdIoTypeMaximum) {
>>    return EFI_INVALID_PARAMETER;
>>  }
>>
>> Seems the compiler is pointing out if the parameter is really a valid
>> enum it would never be out of range.
>
> The error message is the same as above?  Again, could you give a =20
> reproducible, small snippet of code on this one?  I'd be willing to =20=

> try and reproduce it here to see if I can help nail down the problem.
>
>> Any one got an idea on how to fix this? The only thing I can think of
>> is not using enums are parameters.
>
> Don't go there yet.  Passing enums is a Good Idea.  The tests may be =20=

> the error.
>
> -- Randy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@edk2.tianocore.org
> For additional commands, e-mail: dev-help@edk2.tianocore.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@edk2.tianocore.org
For additional commands, e-mail: dev-help@edk2.tianocore.org