OK,
quick test with clang shows that it considers enum as INT32.
---------
int A = sizeof(EFI_MEMORY_TYPE);
printf("Hello World!\n sizeof(EFI_MEMORY_TYPE) = %d\n", A);
---------
result = 4 even it compiled as x86_64
On 12.01.2013, at 1:08, Kinney, Michael D wrote:
> Nikolai,
>
> Based Section 2.3 of the UEFI Spec section on Calling Convention and Data
> Types, my proposed code change for compatibility should use UINT32 instead of
> UINTN:
>
> if ((PoolType >= EfiMaxMemoryType && (UINT32)PoolType <= 0x7fffffff) ||
>
> Does this code change resolve the clang compiler warning/error?
>
> UEFI Spec defines EFI_MEMORY_TYPE as an enum, and ANSI C allows compilers to
> have flexibility for enums to be signed or unsigned. Details from UEFI Spec
> shown below. This means we cannot change the declaration of EFI_MEMORY_TYPE
> to be a UINT32 and we cannot make any assumptions about EFI_MEMORY_TYPE being
> signed or unsigned.
>
> UEFI Specification Section 6.2 - Memory Allocation Services - AllocatePages()
> defines EFI_MEMORY_TYPE to be an enum.:
>
> //*******************************************************
> //EFI_MEMORY_TYPE
> //*******************************************************
> // These type values are discussed in Table 24 and Table 25.
> typedef enum {
> EfiReservedMemoryType,
> EfiLoaderCode,
> EfiLoaderData,
> EfiBootServicesCode,
> EfiBootServicesData,
> EfiRuntimeServicesCode,
> EfiRuntimeServicesData,
> EfiConventionalMemory,
> EfiUnusableMemory,
> EfiACPIReclaimMemory,
> EfiACPIMemoryNVS,
> EfiMemoryMappedIO,
> EfiMemoryMappedIOPortSpace,
> EfiPalCode,
> EfiMaxMemoryType
> } EFI_MEMORY_TYPE;
>
>
> UEFI Specification Section 2.3.1 - Data Types - Table 6 has the following
> entry for enumerated types:
>
> <Enumerated Type>
>
> Element of a standard ANSI C enum type declaration. Type INT32 or
> UINT32.
> ANSI C does not define the size of sign of an enum so they should never
> be used in
> structures. ANSI C integer promotion rules make INT32 or UINT32
> interchangeable
> when passed as an argument to a function.
>
> The issue is that some compilers treat enums as signed and others as
> unsigned. The EDK II implementation attempts to be compatible with both
> types of compilers.
>
> Best regards,
>
> Mike
>
> -----Original Message-----
> From: Nikolai Saoukh [mailto:n...@otdel-1.org]
> Sent: Friday, January 11, 2013 9:32 AM
> To: edk2-devel@lists.sourceforge.net
> Subject: Re: [edk2] clang compilation error
>
> Well, what is wrong with UINT32 as type for EFI_MEMORY_TYPE?
> Why EFI_MEMORY_TYPE should be signed?
>
> On Fri, Jan 11, 2013 at 9:00 PM, Kinney, Michael D
> <michael.d.kin...@intel.com> wrote:
>> Sergey,
>>
>>
>>
>> The comparison against 0x7fffffff is required due to a UEFI Spec
>> requirement. UEFI Specification 2.3.1 Section 6.2 AllocatePages() and
>> AllocatePool() both have a MemoryType parameter that is defined as follows:
>>
>>
>>
>> MemoryType
>>
>>
>>
>> The type of memory to allocate. The type EFI_MEMORY_TYPE is defined in
>> “Related Definitions” below. These memory types are also described in more
>> detail in Table 24 and Table 25. Normal allocations (that is, allocations by
>> any UEFI application) are of type EfiLoaderData. MemoryType values in the
>> range 0x80000000..0xFFFFFFFF are reserved for use by UEFI OS loaders that
>> are provided by operating system vendors. The only illegal memory type
>> values are those in the range EfiMaxMemoryType..0x7FFFFFFF.
>>
>>
>>
>> Since we have to be compatible with both 32-bit and 64-bit CPUs, we cannot
>> implement logic that depends on an enum being a 32-bit signed value.
>>
>>
>>
>> There are two ways to address this compiler error:
>>
>>
>>
>> 1) Disable this compiler warning for this one compiler in tools_def.txt
>>
>> 2) Update the sources to perform an unsigned comparison such as:
>>
>>
>>
>> if ((PoolType >= EfiMaxMemoryType && (UINTN)PoolType <= 0x7fffffff) ||
>>
>> Best regards,
>>
>>
>>
>> Mike
>>
>>
>>
>> From: Sergey Isakov [mailto:isakov...@bk.ru]
>> Sent: Friday, January 11, 2013 2:15 AM
>> To: edk2-devel@lists.sourceforge.net
>> Subject: Re: [edk2] clang compilation error
>>
>>
>>
>> Ok, UEFI spec is wrong and as we have to follow them we should exclude the
>> comparison.
>>
>>
>>
>> 11.01.2013, в 11:58, Tim Lewis написал(а):
>>
>>
>>
>> Sergey –
>>
>>
>>
>> It is an enum in the UEFI specification.
>>
>>
>>
>> Why not just remove the second comparison? Since the enum is an int (for
>> UEFI cases), if it is more than or equal to EfiMaxMemoryType, it must be
>> less than 0x7fffffff (if it is an int). Otherwise it would be less than 0.
>>
>>
>>
>> Tim
>>
>>
>>
>> From: Sergey Isakov [mailto:isakov...@bk.ru]
>> Sent: Thursday, January 10, 2013 11:54 PM
>> To: edk2-devel@lists.sourceforge.net
>> Subject: [edk2] clang compilation error
>>
>>
>>
>> Hi,
>>
>> with clang 3.3 one has the follow
>>
>> ----------
>>
>> /edk2/MdeModulePkg/Core/Dxe/Mem/Pool.c:188:49: error: comparison of constant
>> 2147483647 with expression of type 'EFI_MEMORY_TYPE' is always true
>> [-Werror,-Wtautological-constant-out-of-range-compare] if ((PoolType >=
>> EfiMaxMemoryType && PoolType <= 0x7fffffff) ||
>> ~~~~~~~~ ^ ~~~~~~~~~~
>> 1 error generated.
>>
>> ----------
>>
>> Again, it is enum and sholud not be compared.
>>
>> I will propose to make this as UINT32 and change enum list by a set of
>> definitions like
>>
>> #define EfiACPIMemoryNVS 0x0A
>>
>>
>>
>> It will be better then mix enum and integer.
>>
>> ------------------------------------------------------------------------------
>> Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
>> much more. Get web development skills now with LearnDevNow -
>> 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
>> SALE $99.99 this month only -- learn more at:
>> http://p.sf.net/sfu/learnmore_122812_______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
>> much more. Get web development skills now with LearnDevNow -
>> 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
>> SALE $99.99 this month only -- learn more at:
>> http://p.sf.net/sfu/learnmore_122812
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>>
>
> ------------------------------------------------------------------------------
> Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
> much more. Get web development skills now with LearnDevNow -
> 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
> SALE $99.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122812
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
> ------------------------------------------------------------------------------
> Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
> much more. Get web development skills now with LearnDevNow -
> 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
> SALE $99.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122812
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel