The commit resolve the VS IA32 NOOPT target build failure for modules
that use the BaseSafeIntLib.

More specifically, corresponding BaseLib APIs should be used when
performing shift & mulitiplication operations with signed/unsigned
64-bit operands.

Cc: Michael D Kinney <michael.d.kin...@intel.com>
Cc: Sean Brogan <sean.bro...@microsoft.com>
Cc: Jiewen Yao <jiewen....@intel.com>
Cc: Liming Gao <liming....@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a...@intel.com>
---
 MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf |  3 +++
 MdePkg/Library/BaseSafeIntLib/SafeIntLib.c       | 13 +++++++++----
 MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c     |  3 ++-
 MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c    |  3 ++-
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf 
b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
index 20a83ed97b..8fbdafe748 100644
--- a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+++ b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
@@ -56,3 +56,6 @@
 
 [Packages]
   MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  BaseLib
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c 
b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
index d846160ba0..64b8bc4ad8 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
@@ -28,6 +28,7 @@
 
 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>
 
 
 //
@@ -3373,8 +3374,8 @@ SafeUint64Mult (
   // b * c must be less than 2^32 or there would be bits in the high 64-bits
   // then there must be no overflow of the resulting values summed up.
   //
-  DwordA = (UINT32)(Multiplicand >> 32);
-  DwordC = (UINT32)(Multiplier >> 32);
+  DwordA = (UINT32)RShiftU64 (Multiplicand, 32);
+  DwordC = (UINT32)RShiftU64 (Multiplier, 32);
 
   //
   // common case -- if high dwords are both zero, no chance for overflow
@@ -3409,7 +3410,11 @@ SafeUint64Mult (
           // now sum them all up checking for overflow.
           // shifting is safe because we already checked for overflow above
           //
-          if (!RETURN_ERROR (SafeUint64Add (ProductBC << 32, ProductAD << 32, 
&UnsignedResult))) {
+          if (!RETURN_ERROR (SafeUint64Add (
+                               LShiftU64 (ProductBC, 32),
+                               LShiftU64 (ProductAD, 32),
+                               &UnsignedResult
+                               ))) {
             //
             // b * d
             //
@@ -4011,7 +4016,7 @@ SafeInt32Mult (
   OUT INT32  *Result
   )
 {
-  return SafeInt64ToInt32 (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+  return SafeInt64ToInt32 (MultS64x64 ((INT64)Multiplicand, 
(INT64)Multiplier), Result);
 }
 
 /**
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c 
b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
index 18bfb9e413..b3b7b802a1 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib32.c
@@ -28,6 +28,7 @@
 
 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>
 
 /**
   INT32 -> UINTN conversion
@@ -549,6 +550,6 @@ SafeIntnMult (
   OUT INTN  *Result
   )
 {
-  return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result);
+  return SafeInt64ToIntn (MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier), 
Result);
 }
 
diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c 
b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
index 4478957b7e..e810ba59ef 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLibEbc.c
@@ -28,6 +28,7 @@
 
 #include <Base.h>
 #include <Library/SafeIntLib.h>
+#include <Library/BaseLib.h>
 
 /**
   INT32 -> UINTN conversion
@@ -607,7 +608,7 @@ SafeIntnMult (
   )
 {
   if (sizeof (UINTN) == sizeof (UINT32)) {
-    return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), 
Result);
+    return SafeInt64ToIntn (MultS64x64 ((INT64)Multiplicand, 
(INT64)Multiplier), Result);
   }
   return SafeInt64Mult ((INT64)Multiplicand, (INT64)Multiplier, (INT64 
*)Result);
 }
-- 
2.12.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to