Message ID | 20171207173800.26730-1-leif.lindholm@linaro.org |
---|---|
State | Accepted |
Commit | 978779d7b50cc30cad64b79e24224efa3c6082dc |
Headers | show |
Series | [edk2,v2] BaseTools: align ERROR/WARNING/RETURN macros with MdePkg versions | expand |
Reviewed-by: Liming Gao <liming.gao@intel.com> > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Leif Lindholm > Sent: Friday, December 8, 2017 1:38 AM > To: edk2-devel@lists.01.org > Cc: Gao, Liming <liming.gao@intel.com> > Subject: [edk2] [PATCH v2] BaseTools: align ERROR/WARNING/RETURN macros with MdePkg versions > > BaseTools' BaseTypes.h defined the ENCODE_ERROR macro as > #define ENCODE_ERROR(a) ((RETURN_STATUS)(MAX_BIT | (a))) > whereas MdePkg defines it as > #define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode))) > > When building with GCC 6.3 (at least) the former triggers > "error: overflow in implicit constant conversion [-Werror=overflow]" > Resolve this by aligning it with the latter one. > > This also requires aligning the BaseTools typedef of RETURN_STATUS with > the MdePkg one: INTN -> UINTN. > > While at it, update adjacent ENCODE_WARNING and RETURN_ERROR as well. > > Add an explicit initialization of *Alignment to 0 in GenFfs.c > GetAlignmentFromFile to get rid of a warning occuring with GCC after > this change (-Werror=maybe-uninitialized). > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> > --- > > v2 updated for ENCODE_WARNING and RETURN_ERROR, as requested > by Liming. > > BaseTools/Source/C/GenFfs/GenFfs.c | 1 + > BaseTools/Source/C/Include/Common/BaseTypes.h | 8 ++++---- > 2 files changed, 5 insertions(+), 4 deletions(-) > > diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c > index e2fb3e0d1e..3b4a9b7761 100644 > --- a/BaseTools/Source/C/GenFfs/GenFfs.c > +++ b/BaseTools/Source/C/GenFfs/GenFfs.c > @@ -529,6 +529,7 @@ GetAlignmentFromFile(char *InFile, UINT32 *Alignment) > > InFileHandle = NULL; > PeFileBuffer = NULL; > + *Alignment = 0; > > memset (&ImageContext, 0, sizeof (ImageContext)); > > diff --git a/BaseTools/Source/C/Include/Common/BaseTypes.h b/BaseTools/Source/C/Include/Common/BaseTypes.h > index 198647ab95..08b60bae11 100644 > --- a/BaseTools/Source/C/Include/Common/BaseTypes.h > +++ b/BaseTools/Source/C/Include/Common/BaseTypes.h > @@ -170,15 +170,15 @@ > // EFI Error Codes common to all execution phases > // > > -typedef INTN RETURN_STATUS; > +typedef UINTN RETURN_STATUS; > > /// > /// Set the upper bit to indicate EFI Error. > /// > -#define ENCODE_ERROR(a) (MAX_BIT | (a)) > +#define ENCODE_ERROR(a) ((RETURN_STATUS)(MAX_BIT | (a))) > > -#define ENCODE_WARNING(a) (a) > -#define RETURN_ERROR(a) ((a) < 0) > +#define ENCODE_WARNING(a) ((RETURN_STATUS)(a)) > +#define RETURN_ERROR(a) (((INTN)(RETURN_STATUS)(a)) < 0) > > #define RETURN_SUCCESS 0 > #define RETURN_LOAD_ERROR ENCODE_ERROR (1) > -- > 2.11.0 > > _______________________________________________ > 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
On Fri, Dec 08, 2017 at 12:52:56AM +0000, Gao, Liming wrote: > Reviewed-by: Liming Gao <liming.gao@intel.com> Thanks. Pushed as 978779d7b5. > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Leif Lindholm > > Sent: Friday, December 8, 2017 1:38 AM > > To: edk2-devel@lists.01.org > > Cc: Gao, Liming <liming.gao@intel.com> > > Subject: [edk2] [PATCH v2] BaseTools: align ERROR/WARNING/RETURN macros with MdePkg versions > > > > BaseTools' BaseTypes.h defined the ENCODE_ERROR macro as > > #define ENCODE_ERROR(a) ((RETURN_STATUS)(MAX_BIT | (a))) > > whereas MdePkg defines it as > > #define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode))) > > > > When building with GCC 6.3 (at least) the former triggers > > "error: overflow in implicit constant conversion [-Werror=overflow]" > > Resolve this by aligning it with the latter one. > > > > This also requires aligning the BaseTools typedef of RETURN_STATUS with > > the MdePkg one: INTN -> UINTN. > > > > While at it, update adjacent ENCODE_WARNING and RETURN_ERROR as well. > > > > Add an explicit initialization of *Alignment to 0 in GenFfs.c > > GetAlignmentFromFile to get rid of a warning occuring with GCC after > > this change (-Werror=maybe-uninitialized). > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> > > --- > > > > v2 updated for ENCODE_WARNING and RETURN_ERROR, as requested > > by Liming. > > > > BaseTools/Source/C/GenFfs/GenFfs.c | 1 + > > BaseTools/Source/C/Include/Common/BaseTypes.h | 8 ++++---- > > 2 files changed, 5 insertions(+), 4 deletions(-) > > > > diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c > > index e2fb3e0d1e..3b4a9b7761 100644 > > --- a/BaseTools/Source/C/GenFfs/GenFfs.c > > +++ b/BaseTools/Source/C/GenFfs/GenFfs.c > > @@ -529,6 +529,7 @@ GetAlignmentFromFile(char *InFile, UINT32 *Alignment) > > > > InFileHandle = NULL; > > PeFileBuffer = NULL; > > + *Alignment = 0; > > > > memset (&ImageContext, 0, sizeof (ImageContext)); > > > > diff --git a/BaseTools/Source/C/Include/Common/BaseTypes.h b/BaseTools/Source/C/Include/Common/BaseTypes.h > > index 198647ab95..08b60bae11 100644 > > --- a/BaseTools/Source/C/Include/Common/BaseTypes.h > > +++ b/BaseTools/Source/C/Include/Common/BaseTypes.h > > @@ -170,15 +170,15 @@ > > // EFI Error Codes common to all execution phases > > // > > > > -typedef INTN RETURN_STATUS; > > +typedef UINTN RETURN_STATUS; > > > > /// > > /// Set the upper bit to indicate EFI Error. > > /// > > -#define ENCODE_ERROR(a) (MAX_BIT | (a)) > > +#define ENCODE_ERROR(a) ((RETURN_STATUS)(MAX_BIT | (a))) > > > > -#define ENCODE_WARNING(a) (a) > > -#define RETURN_ERROR(a) ((a) < 0) > > +#define ENCODE_WARNING(a) ((RETURN_STATUS)(a)) > > +#define RETURN_ERROR(a) (((INTN)(RETURN_STATUS)(a)) < 0) > > > > #define RETURN_SUCCESS 0 > > #define RETURN_LOAD_ERROR ENCODE_ERROR (1) > > -- > > 2.11.0 > > > > _______________________________________________ > > 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
diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c index e2fb3e0d1e..3b4a9b7761 100644 --- a/BaseTools/Source/C/GenFfs/GenFfs.c +++ b/BaseTools/Source/C/GenFfs/GenFfs.c @@ -529,6 +529,7 @@ GetAlignmentFromFile(char *InFile, UINT32 *Alignment) InFileHandle = NULL; PeFileBuffer = NULL; + *Alignment = 0; memset (&ImageContext, 0, sizeof (ImageContext)); diff --git a/BaseTools/Source/C/Include/Common/BaseTypes.h b/BaseTools/Source/C/Include/Common/BaseTypes.h index 198647ab95..08b60bae11 100644 --- a/BaseTools/Source/C/Include/Common/BaseTypes.h +++ b/BaseTools/Source/C/Include/Common/BaseTypes.h @@ -170,15 +170,15 @@ // EFI Error Codes common to all execution phases // -typedef INTN RETURN_STATUS; +typedef UINTN RETURN_STATUS; /// /// Set the upper bit to indicate EFI Error. /// -#define ENCODE_ERROR(a) (MAX_BIT | (a)) +#define ENCODE_ERROR(a) ((RETURN_STATUS)(MAX_BIT | (a))) -#define ENCODE_WARNING(a) (a) -#define RETURN_ERROR(a) ((a) < 0) +#define ENCODE_WARNING(a) ((RETURN_STATUS)(a)) +#define RETURN_ERROR(a) (((INTN)(RETURN_STATUS)(a)) < 0) #define RETURN_SUCCESS 0 #define RETURN_LOAD_ERROR ENCODE_ERROR (1)
BaseTools' BaseTypes.h defined the ENCODE_ERROR macro as #define ENCODE_ERROR(a) ((RETURN_STATUS)(MAX_BIT | (a))) whereas MdePkg defines it as #define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode))) When building with GCC 6.3 (at least) the former triggers "error: overflow in implicit constant conversion [-Werror=overflow]" Resolve this by aligning it with the latter one. This also requires aligning the BaseTools typedef of RETURN_STATUS with the MdePkg one: INTN -> UINTN. While at it, update adjacent ENCODE_WARNING and RETURN_ERROR as well. Add an explicit initialization of *Alignment to 0 in GenFfs.c GetAlignmentFromFile to get rid of a warning occuring with GCC after this change (-Werror=maybe-uninitialized). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> --- v2 updated for ENCODE_WARNING and RETURN_ERROR, as requested by Liming. BaseTools/Source/C/GenFfs/GenFfs.c | 1 + BaseTools/Source/C/Include/Common/BaseTypes.h | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel