فهرست منبع

Fix additional clang issues

Tom Kneiphof 1 سال پیش
والد
کامیت
c32a481dd4
3فایلهای تغییر یافته به همراه25 افزوده شده و 24 حذف شده
  1. 1 1
      test/core/core_func_integer_bit_count.cpp
  2. 7 6
      test/core/core_func_integer_find_lsb.cpp
  3. 17 17
      test/core/core_func_integer_find_msb.cpp

+ 1 - 1
test/core/core_func_integer_bit_count.cpp

@@ -176,7 +176,7 @@ static int pop9(unsigned x)
 	return static_cast<int>(y);
 }
 
-int errors;
+static int errors;
 static void error(int x, int y)
 {
 	errors = errors + 1;

+ 7 - 6
test/core/core_func_integer_find_lsb.cpp

@@ -45,7 +45,7 @@ static int ntz3(unsigned x)
 	if ((x & 0x000000FF) == 0) {n = n + 8; x = x >> 8;}
 	if ((x & 0x0000000F) == 0) {n = n + 4; x = x >> 4;}
 	if ((x & 0x00000003) == 0) {n = n + 2; x = x >> 2;}
-	return n - (x & 1);
+	return n - static_cast<int>(x & 1);
 }
 
 static int ntz4(unsigned x)
@@ -74,7 +74,7 @@ static int ntz4a(unsigned x)
 	y = x << 8;  if (y != 0) {n = n - 8;  x = y;}
 	y = x << 4;  if (y != 0) {n = n - 4;  x = y;}
 	y = x << 2;  if (y != 0) {n = n - 2;  x = y;}
-	n = n - ((x << 1) >> 31);
+	n = n - static_cast<int>((x << 1) >> 31);
 	return n;
 }
 
@@ -145,7 +145,8 @@ could then all run in parallel). */
 
 static int ntz7(unsigned x)
 {
-	unsigned y, bz, b4, b3, b2, b1, b0;
+	unsigned y;
+	int bz, b4, b3, b2, b1, b0;
 
 	y = x & -x;               // Isolate rightmost 1-bit.
 	bz = y ? 0 : 1;           // 1 if y = 0.
@@ -279,8 +280,8 @@ static int ntz11(unsigned int n) {
 #	pragma warning(pop)
 #endif
 
-int errors;
-static void error(int x, int y) {
+static int errors;
+static void error(unsigned x, int y) {
    errors = errors + 1;
    std::printf("Error for x = %08x, got %d\n", x, y);
 }
@@ -353,7 +354,7 @@ int main()
 	for(std::size_t k = 0; k < Count; ++k)
 	for(i = 0; i < n; i += 2)
 	{
-		m = test[i+1];
+		m = static_cast<int>(test[i+1]);
 		if(m > 8)
 			m = 8;
 		if(ntz5(static_cast<char>(test[i])) != m)

+ 17 - 17
test/core/core_func_integer_find_msb.cpp

@@ -39,7 +39,7 @@ static int nlz1a(unsigned x) {
    if ((x >> 24) == 0) {n = n + 8; x = x << 8;}
    if ((x >> 28) == 0) {n = n + 4; x = x << 4;}
    if ((x >> 30) == 0) {n = n + 2; x = x << 2;}
-   n = n - (x >> 31);
+   n = n - static_cast<int>(x >> 31);
    return n;
 }
 // On basic Risc, 12 to 20 instructions.
@@ -54,7 +54,7 @@ static int nlz2(unsigned x) {
    y = x >> 4;  if (y != 0) {n = n - 4;  x = y;}
    y = x >> 2;  if (y != 0) {n = n - 2;  x = y;}
    y = x >> 1;  if (y != 0) return n - 2;
-   return n - x;
+   return n - static_cast<int>(x);
 }
 
 // As above but coded as a loop for compactness:
@@ -69,15 +69,15 @@ static int nlz2a(unsigned x) {
       y = x >> c;  if (y != 0) {n = n - c;  x = y;}
       c = c >> 1;
    } while (c != 0);
-   return n - x;
+   return n - static_cast<int>(x);
 }
 
-static int nlz3(int x) {
+static int nlz3(unsigned x) {
    int y, n;
 
    n = 0;
-   y = x;
-L: if (x < 0) return n;
+   y = static_cast<int>(x);
+L: if (x > 0x7fffffff) return n;
    if (y == 0) return 32 - n;
    n = n + 1;
    x = x << 1;
@@ -98,19 +98,19 @@ static int nlz4(unsigned x) {
    n = 16 - m;          // is nonzero, set n = 0 and
    x = x >> m;          // shift x right 16.
                         // Now x is of the form 0000xxxx.
-   y = x - 0x100;       // If positions 8-15 are 0,
-   m = (y >> 16) & 8;   // add 8 to n and shift x left 8.
-   n = n + m;
+   y = static_cast<int>(x) - 0x100;
+   m = (y >> 16) & 8;   // If positions 8-15 are 0,
+   n = n + m;           // add 8 to n and shift x left 8.
    x = x << m;
 
-   y = x - 0x1000;      // If positions 12-15 are 0,
-   m = (y >> 16) & 4;   // add 4 to n and shift x left 4.
-   n = n + m;
+   y = static_cast<int>(x) - 0x1000;
+   m = (y >> 16) & 4;   // If positions 12-15 are 0,
+   n = n + m;           // add 4 to n and shift x left 4.
    x = x << m;
 
-   y = x - 0x4000;      // If positions 14-15 are 0,
-   m = (y >> 16) & 2;   // add 2 to n and shift x left 2.
-   n = n + m;
+   y = static_cast<int>(x) - 0x4000;
+   m = (y >> 16) & 2;   // If positions 14-15 are 0,
+   n = n + m;           // add 2 to n and shift x left 2.
    x = x << m;
 
    y = x >> 14;         // Set y = 0, 1, 2, or 3.
@@ -305,8 +305,8 @@ static int nlz10b(unsigned x)
 	return table[x >> 26];
 }
 
-int errors;
-static void error(int x, int y)
+static int errors;
+static void error(unsigned x, int y)
 {
 	errors = errors + 1;
 	std::printf("Error for x = %08x, got %d\n", x, y);