Fix clang issue when casting negative int32_t to int64_t

Resolve COMPMID-4898

Signed-off-by: Giorgio Arena <giorgio.arena@arm.com>
Change-Id: I657e53883c10dc50a59815e527159567315d0aeb
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/c/VisualCompute/ComputeLibrary/+/370574
Tested-by: bsgcomp <bsgcomp@arm.com>
Reviewed-by: Gunes Bayir <gunes.bayir@arm.com>
Comments-Addressed: bsgcomp <bsgcomp@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6546
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Pablo Marquez Tello <pablo.tello@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
diff --git a/tests/validation/reference/UtilsQuantizedAsymm.h b/tests/validation/reference/UtilsQuantizedAsymm.h
index 1f593bb..e5ecc66 100644
--- a/tests/validation/reference/UtilsQuantizedAsymm.h
+++ b/tests/validation/reference/UtilsQuantizedAsymm.h
@@ -32,6 +32,22 @@
 {
 namespace validation
 {
+namespace
+{
+#if __clang__
+// This has been tested on clang 7.0.2 (__clang_major__ == 7 && __clang_minor__ == 0 && __clang_patchlevel__ == 2)
+inline int64_t to_int64(int32_t val)
+{
+    return static_cast<int64_t>(val) | ((val < 0) ? (((1ll << 32) - 1) << 32) : 0);
+}
+#else  // __clang__
+inline int64_t to_int64(int32_t val)
+{
+    return static_cast<int64_t>(val);
+}
+#endif // __clang__
+} // namespace
+
 /** Rounded to nearest division by a power-of-two. */
 inline int32_t asymm_rounding_divide_by_pow2(int32_t x, int exponent)
 {
@@ -43,12 +59,12 @@
 /** Multiplication of two integers. The same as ARMv7 Arm® Neon™ VQRDMULH instruction. */
 inline int32_t asymm_int_mult(int32_t a, int32_t b)
 {
-    bool    overflow = a == b && a == std::numeric_limits<int32_t>::min();
-    int64_t a_64(a);
-    int64_t b_64(b);
-    int64_t ab_64        = a_64 * b_64;
-    int32_t nudge        = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30));
-    int32_t ab_x2_high32 = static_cast<int32_t>((ab_64 + nudge) / (1ll << 31));
+    const bool    overflow     = a == b && a == std::numeric_limits<int32_t>::min();
+    const int64_t a_64         = to_int64(a);
+    const int64_t b_64         = to_int64(b);
+    const int64_t ab_64        = a_64 * b_64;
+    const int32_t nudge        = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30));
+    const int32_t ab_x2_high32 = static_cast<int32_t>((ab_64 + nudge) / (1ll << 31));
     return overflow ? std::numeric_limits<int32_t>::max() : ab_x2_high32;
 }