Skip to content

Commit 56d7fe7

Browse files
committed
C library: fix _Static_assert for MSVC
Visual Studio knows static_assert, but not the standardised _Static_assert.
1 parent 085068c commit 56d7fe7

File tree

1 file changed

+105
-45
lines changed

1 file changed

+105
-45
lines changed

src/ansi-c/library/math.c

+105-45
Original file line numberDiff line numberDiff line change
@@ -2575,9 +2575,13 @@ double exp(double x)
25752575
__CPROVER_assume(result >= lower);
25762576
__CPROVER_assume(result <= upper);
25772577

2578-
_Static_assert(
2579-
sizeof(double) == 2 * sizeof(int32_t),
2580-
"bit width of double is 2x bit width of int32_t");
2578+
#ifndef _MSC_VER
2579+
_Static_assert
2580+
#else
2581+
static_assert
2582+
#endif
2583+
(sizeof(double) == 2 * sizeof(int32_t),
2584+
"bit width of double is 2x bit width of int32_t");
25812585
union U
25822586
{
25832587
double d;
@@ -2642,9 +2646,13 @@ float expf(float x)
26422646
__CPROVER_assume(result >= lower);
26432647
__CPROVER_assume(result <= upper);
26442648

2645-
_Static_assert(
2646-
sizeof(float) == sizeof(int32_t),
2647-
"bit width of float and int32_t should match");
2649+
#ifndef _MSC_VER
2650+
_Static_assert
2651+
#else
2652+
static_assert
2653+
#endif
2654+
(sizeof(float) == sizeof(int32_t),
2655+
"bit width of float and int32_t should match");
26482656
union U
26492657
{
26502658
float f;
@@ -2713,9 +2721,13 @@ long double expl(long double x)
27132721
__CPROVER_assume(result >= lower);
27142722
__CPROVER_assume(result <= upper);
27152723

2716-
_Static_assert(
2717-
sizeof(long double) % sizeof(int32_t) == 0,
2718-
"bit width of long double is a multiple of bit width of int32_t");
2724+
# ifndef _MSC_VER
2725+
_Static_assert
2726+
# else
2727+
static_assert
2728+
# endif
2729+
(sizeof(long double) % sizeof(int32_t) == 0,
2730+
"bit width of long double is a multiple of bit width of int32_t");
27192731
union
27202732
{
27212733
long double l;
@@ -2772,9 +2784,13 @@ double log(double x)
27722784
#pragma CPROVER check pop
27732785
}
27742786

2775-
_Static_assert(
2776-
sizeof(double) == 2 * sizeof(int32_t),
2777-
"bit width of double is 2x bit width of int32_t");
2787+
#ifndef _MSC_VER
2788+
_Static_assert
2789+
#else
2790+
static_assert
2791+
#endif
2792+
(sizeof(double) == 2 * sizeof(int32_t),
2793+
"bit width of double is 2x bit width of int32_t");
27782794
// https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
27792795
union
27802796
{
@@ -2833,9 +2849,13 @@ float logf(float x)
28332849
#pragma CPROVER check pop
28342850
}
28352851

2836-
_Static_assert(
2837-
sizeof(float) == sizeof(int32_t),
2838-
"bit width of float and int32_t should match");
2852+
#ifndef _MSC_VER
2853+
_Static_assert
2854+
#else
2855+
static_assert
2856+
#endif
2857+
(sizeof(float) == sizeof(int32_t),
2858+
"bit width of float and int32_t should match");
28392859
// https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
28402860
union
28412861
{
@@ -2898,9 +2918,13 @@ long double logl(long double x)
28982918
#if LDBL_MAX_EXP == DBL_MAX_EXP
28992919
return log(x);
29002920
#else
2901-
_Static_assert(
2902-
sizeof(long double) % sizeof(int32_t) == 0,
2903-
"bit width of long double is a multiple of bit width of int32_t");
2921+
# ifndef _MSC_VER
2922+
_Static_assert
2923+
# else
2924+
static_assert
2925+
# endif
2926+
(sizeof(long double) % sizeof(int32_t) == 0,
2927+
"bit width of long double is a multiple of bit width of int32_t");
29042928
union
29052929
{
29062930
long double l;
@@ -2962,9 +2986,13 @@ double log2(double x)
29622986
#pragma CPROVER check pop
29632987
}
29642988

2965-
_Static_assert(
2966-
sizeof(double) == 2 * sizeof(int32_t),
2967-
"bit width of double is 2x bit width of int32_t");
2989+
#ifndef _MSC_VER
2990+
_Static_assert
2991+
#else
2992+
static_assert
2993+
#endif
2994+
(sizeof(double) == 2 * sizeof(int32_t),
2995+
"bit width of double is 2x bit width of int32_t");
29682996
union
29692997
{
29702998
double d;
@@ -3022,9 +3050,13 @@ float log2f(float x)
30223050
#pragma CPROVER check pop
30233051
}
30243052

3025-
_Static_assert(
3026-
sizeof(float) == sizeof(int32_t),
3027-
"bit width of float and int32_t should match");
3053+
#ifndef _MSC_VER
3054+
_Static_assert
3055+
#else
3056+
static_assert
3057+
#endif
3058+
(sizeof(float) == sizeof(int32_t),
3059+
"bit width of float and int32_t should match");
30283060
union
30293061
{
30303062
float f;
@@ -3086,9 +3118,13 @@ long double log2l(long double x)
30863118
#if LDBL_MAX_EXP == DBL_MAX_EXP
30873119
return log2(x);
30883120
#else
3089-
_Static_assert(
3090-
sizeof(long double) % sizeof(int32_t) == 0,
3091-
"bit width of long double is a multiple of bit width of int32_t");
3121+
# ifndef _MSC_VER
3122+
_Static_assert
3123+
# else
3124+
static_assert
3125+
# endif
3126+
(sizeof(long double) % sizeof(int32_t) == 0,
3127+
"bit width of long double is a multiple of bit width of int32_t");
30923128
union
30933129
{
30943130
long double l;
@@ -3150,9 +3186,13 @@ double log10(double x)
31503186
#pragma CPROVER check pop
31513187
}
31523188

3153-
_Static_assert(
3154-
sizeof(double) == 2 * sizeof(int32_t),
3155-
"bit width of double is 2x bit width of int32_t");
3189+
#ifndef _MSC_VER
3190+
_Static_assert
3191+
#else
3192+
static_assert
3193+
#endif
3194+
(sizeof(double) == 2 * sizeof(int32_t),
3195+
"bit width of double is 2x bit width of int32_t");
31563196
// https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
31573197
union
31583198
{
@@ -3213,9 +3253,13 @@ float log10f(float x)
32133253
#pragma CPROVER check pop
32143254
}
32153255

3216-
_Static_assert(
3217-
sizeof(float) == sizeof(int32_t),
3218-
"bit width of float and int32_t should match");
3256+
#ifndef _MSC_VER
3257+
_Static_assert
3258+
#else
3259+
static_assert
3260+
#endif
3261+
(sizeof(float) == sizeof(int32_t),
3262+
"bit width of float and int32_t should match");
32193263
// https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
32203264
union
32213265
{
@@ -3279,9 +3323,13 @@ long double log10l(long double x)
32793323
#if LDBL_MAX_EXP == DBL_MAX_EXP
32803324
return log10(x);
32813325
#else
3282-
_Static_assert(
3283-
sizeof(long double) % sizeof(int32_t) == 0,
3284-
"bit width of long double is a multiple of bit width of int32_t");
3326+
# ifndef _MSC_VER
3327+
_Static_assert
3328+
# else
3329+
static_assert
3330+
# endif
3331+
(sizeof(long double) % sizeof(int32_t) == 0,
3332+
"bit width of long double is a multiple of bit width of int32_t");
32853333
union
32863334
{
32873335
long double l;
@@ -3404,9 +3452,13 @@ double pow(double x, double y)
34043452
return 0.0 / 0.0;
34053453
#pragma CPROVER check pop
34063454

3407-
_Static_assert(
3408-
sizeof(double) == 2 * sizeof(int32_t),
3409-
"bit width of double is 2x bit width of int32_t");
3455+
#ifndef _MSC_VER
3456+
_Static_assert
3457+
#else
3458+
static_assert
3459+
#endif
3460+
(sizeof(double) == 2 * sizeof(int32_t),
3461+
"bit width of double is 2x bit width of int32_t");
34103462
// https://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
34113463
union
34123464
{
@@ -3545,9 +3597,13 @@ float powf(float x, float y)
35453597
return 0.0f / 0.0f;
35463598
#pragma CPROVER check pop
35473599

3548-
_Static_assert(
3549-
sizeof(float) == sizeof(int32_t),
3550-
"bit width of float and int32_t should match");
3600+
#ifndef _MSC_VER
3601+
_Static_assert
3602+
#else
3603+
static_assert
3604+
#endif
3605+
(sizeof(float) == sizeof(int32_t),
3606+
"bit width of float and int32_t should match");
35513607
union
35523608
{
35533609
float f;
@@ -3684,9 +3740,13 @@ long double powl(long double x, long double y)
36843740
#if LDBL_MAX_EXP == DBL_MAX_EXP
36853741
return pow(x, y);
36863742
#else
3687-
_Static_assert(
3688-
sizeof(long double) % sizeof(int32_t) == 0,
3689-
"bit width of long double is a multiple of bit width of int32_t");
3743+
# ifndef _MSC_VER
3744+
_Static_assert
3745+
# else
3746+
static_assert
3747+
# endif
3748+
(sizeof(long double) % sizeof(int32_t) == 0,
3749+
"bit width of long double is a multiple of bit width of int32_t");
36903750
union U
36913751
{
36923752
long double l;

0 commit comments

Comments
 (0)