Commit a6b5da2f17dab8afd754ec9625f1789951288035

Steffen Jaeckel 2019-04-24T22:20:39

Merge pull request #225 from minad/travis/compiler-versions Test against multiple specific clang/gcc versions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
diff --git a/.gitignore b/.gitignore
index 4072e6a..6f24fa7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,6 +74,8 @@ libtommath.pc
 gcc_errors_*.txt
 test_*.txt
 
+.#*
+*~
 *.bak
 *.orig
 *.asc
diff --git a/.travis.yml b/.travis.yml
index 047939d..56d4a60 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,15 +31,15 @@ branches:
   only:
     - master
     - develop
-    - /^release\/.*$/
+    - /^release/
+    - /^travis/
 
-# Additional installs are Valgrind for the memory-tests
-# and gcc-multilib for the compilation of the different
-# architectures.
+# Additional installs: Valgrind for memory tests.
 install:
   - sudo apt-get update -qq
   - sudo apt-get install valgrind
-  - sudo apt-get install gcc-multilib
+  - apt-cache search gcc | grep '^gcc-[0-9\.]* '
+  - apt-cache search clang | grep compiler
 
 # The language is C and it will load the respective dependencies
 language: c
@@ -66,60 +66,90 @@ matrix:
         apt:
           packages:
             - astyle
-      sudo: required
 
     # GCC for the 32-bit architecture (no valgrind yet)
-    - env: BUILDOPTIONS='--with-cc=gcc --with-m32'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --with-m32'
       addons:
         apt:
           packages:
             - libc6-dev-i386
-      sudo: required
+            - gcc-multilib
 
     # clang for the 32-bit architecture (no valgrind yet)
-    - env: BUILDOPTIONS='--with-cc=clang --with-m32'
+    - env: BUILDOPTIONS='--with-cc=clang-7 --with-m32'
       addons:
         apt:
           packages:
             - libc6-dev-i386
-      sudo: required
+            - gcc-multilib
 
     # GCC for the x64_32 architecture (32-bit longs and 32-bit pointers)
     # TODO: Probably not possible to run anything in x32 in Travis
     #       but needs to be checked to be sure.
-    - env: BUILDOPTIONS='--with-cc=gcc --with-mx32'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --with-mx32'
       addons:
         apt:
           packages:
             - libc6-dev-x32
-      sudo: required
+            - gcc-multilib
 
     # GCC for the x86-64 architecture (64-bit longs and 64-bit pointers)
-    - env:  BUILDOPTIONS='--with-cc=gcc --with-m64 --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=gcc-4.7 --with-m64 --with-valgrind'
+      addons:
+        apt:
+          packages:
+            - gcc-4.7
+    - env: BUILDOPTIONS='--with-cc=gcc-4.8 --with-m64 --with-valgrind'
+      addons:
+        apt:
+          packages:
+            - gcc-4.8
+    - env: BUILDOPTIONS='--with-cc=gcc-4.9 --with-m64 --with-valgrind'
+      addons:
+        apt:
+          packages:
+            - gcc-4.9
+
     # clang for x86-64 architecture (64-bit longs and 64-bit pointers)
-    - env:  BUILDOPTIONS='--with-cc=clang --with-m64 --with-valgrind'
+    - env: CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=clang-6.0 --with-m64 --with-valgrind'
+      addons:
+        apt:
+          packages:
+            - clang-6.0
+    - env: BUILDOPTIONS='--with-cc=clang-5.0 --with-m64 --with-valgrind'
+      addons:
+        apt:
+          packages:
+            - clang-5.0
+    - env: BUILDOPTIONS='--with-cc=clang-4.0 --with-m64 --with-valgrind'
+      addons:
+        apt:
+          packages:
+            - clang-4.0
 
     # GCC for the x86-64 architecture with restricted limb sizes
     # formerly started with the option "--with-low-mp" to testme.sh
     # but testing all three in one run took to long and timed out.
-    - env:  BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_8BIT  --with-valgrind'
-    - env:  BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-valgrind'
-    - env:  BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_8BIT  --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_32BIT --with-valgrind'
 
     # clang for the x86-64 architecture with restricted limb sizes
-    - env:  BUILDOPTIONS='--with-cc=clang --cflags=-DMP_8BIT  --with-valgrind'
-    - env:  BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-valgrind'
-    - env:  BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_8BIT  --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_16BIT --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_32BIT --with-valgrind'
 
     # GCC for the x86-64 architecture testing against a different Bigint-implementation
     # with 333333 different inputs.
-    - env:  BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --with-valgrind'
-    - env:  BUILDOPTIONS='--with-cc=clang --test-vs-mtest=333333 --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=clang-7 --test-vs-mtest=333333 --with-valgrind'
 
     # clang for the x86-64 architecture testing against a different Bigint-implementation
     # with a better random source.
-    - env:  BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
-    - env:  BUILDOPTIONS='--with-cc=clang --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
+    - env: BUILDOPTIONS='--with-cc=clang-7 --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
 
 # Notifications go to
 # An email address is also possible.
@@ -132,5 +162,4 @@ notifications:
 # seem to be the max and 20 the default if travis_wait is called without
 # any options.
 script:
-  - ./testme.sh  ${BUILDOPTIONS}
-
+  - ./testme.sh ${BUILDOPTIONS}
diff --git a/demo/opponent.c b/demo/opponent.c
index d701325..7f02252 100644
--- a/demo/opponent.c
+++ b/demo/opponent.c
@@ -79,7 +79,7 @@ int mtest_opponent(void)
          FGETS(buf, 4095, stdin);
          mp_read_radix(&b, buf, 64);
 
-         mp_mul_2d(&a, rr, &a);
+         mp_mul_2d(&a, (int)rr, &a);
          a.sign = b.sign;
          if (mp_cmp(&a, &b) != MP_EQ) {
             printf("mul2d failed, rr == %u\n", rr);
@@ -96,7 +96,7 @@ int mtest_opponent(void)
          FGETS(buf, 4095, stdin);
          mp_read_radix(&b, buf, 64);
 
-         mp_div_2d(&a, rr, &a, &e);
+         mp_div_2d(&a, (int)rr, &a, &e);
          a.sign = b.sign;
          if ((a.used == b.used) && (a.used == 0)) {
             a.sign = b.sign = MP_ZPOS;
@@ -128,10 +128,10 @@ int mtest_opponent(void)
 
          /* test the sign/unsigned storage functions */
 
-         rr = mp_signed_bin_size(&c);
+         rr = (unsigned)mp_signed_bin_size(&c);
          mp_to_signed_bin(&c, (unsigned char *) cmd);
-         memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
-         mp_read_signed_bin(&d, (unsigned char *) cmd, rr);
+         memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
+         mp_read_signed_bin(&d, (unsigned char *) cmd, (int)rr);
          if (mp_cmp(&c, &d) != MP_EQ) {
             printf("mp_signed_bin failure!\n");
             draw(&c);
@@ -140,10 +140,10 @@ int mtest_opponent(void)
          }
 
 
-         rr = mp_unsigned_bin_size(&c);
+         rr = (unsigned)mp_unsigned_bin_size(&c);
          mp_to_unsigned_bin(&c, (unsigned char *) cmd);
-         memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
-         mp_read_unsigned_bin(&d, (unsigned char *) cmd, rr);
+         memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
+         mp_read_unsigned_bin(&d, (unsigned char *) cmd, (int)rr);
          if (mp_cmp_mag(&c, &d) != MP_EQ) {
             printf("mp_unsigned_bin failure!\n");
             draw(&c);
@@ -343,7 +343,7 @@ int mtest_opponent(void)
          sscanf(buf, "%d", &ix);
          FGETS(buf, 4095, stdin);
          mp_read_radix(&b, buf, 64);
-         mp_add_d(&a, ix, &c);
+         mp_add_d(&a, (mp_digit)ix, &c);
          if (mp_cmp(&b, &c) != MP_EQ) {
             printf("add_d %lu failure\n", add_d_n);
             draw(&a);
@@ -360,7 +360,7 @@ int mtest_opponent(void)
          sscanf(buf, "%d", &ix);
          FGETS(buf, 4095, stdin);
          mp_read_radix(&b, buf, 64);
-         mp_sub_d(&a, ix, &c);
+         mp_sub_d(&a, (mp_digit)ix, &c);
          if (mp_cmp(&b, &c) != MP_EQ) {
             printf("sub_d %lu failure\n", sub_d_n);
             draw(&a);
diff --git a/demo/test.c b/demo/test.c
index 3aa1a22..208ab7f 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -103,7 +103,7 @@ static int test_mp_jacobi(void)
       mp_set_int(&b, jacobi[cnt].n);
       /* only test positive values of a */
       for (n = -5; n <= 10; ++n) {
-         mp_set_int(&a, abs(n));
+         mp_set_int(&a, (unsigned int)abs(n));
          should = MP_OKAY;
          if (n < 0) {
             mp_neg(&a, &a);
@@ -221,14 +221,14 @@ static int test_mp_complement(void)
    }
 
    for (i = 0; i < 1000; ++i) {
-      int l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&a, labs(l));
+      long l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
+      mp_set_long(&a, (unsigned long)labs(l));
       if (l < 0)
          mp_neg(&a, &a);
       mp_complement(&a, &b);
 
       l = ~l;
-      mp_set_int(&c, labs(l));
+      mp_set_long(&c, (unsigned long)labs(l));
       if (l < 0)
          mp_neg(&c, &c);
 
@@ -255,16 +255,17 @@ static int test_mp_tc_div_2d(void)
    }
 
    for (i = 0; i < 1000; ++i) {
-      int l, em;
+      long l;
+      int em;
 
       l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&a, labs(l));
+      mp_set_long(&a, (unsigned long)labs(l));
       if (l < 0)
          mp_neg(&a, &a);
 
       em = rand() % 32;
 
-      mp_set_int(&d, labs(l >> em));
+      mp_set_long(&d, (unsigned long)labs(l >> em));
       if ((l >> em) < 0)
          mp_neg(&d, &d);
 
@@ -296,16 +297,16 @@ static int test_mp_tc_xor(void)
       int l, em;
 
       l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&a, labs(l));
+      mp_set_int(&a, (unsigned long)labs(l));
       if (l < 0)
          mp_neg(&a, &a);
 
       em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&b, labs(em));
+      mp_set_int(&b, (unsigned long)labs(em));
       if (em < 0)
          mp_neg(&b, &b);
 
-      mp_set_int(&d, labs(l ^ em));
+      mp_set_int(&d, (unsigned long)labs(l ^ em));
       if ((l ^ em) < 0)
          mp_neg(&d, &d);
 
@@ -334,19 +335,19 @@ static int test_mp_tc_or(void)
    }
 
    for (i = 0; i < 1000; ++i) {
-      int l, em;
+      long l, em;
 
       l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&a, labs(l));
+      mp_set_long(&a, (unsigned long)labs(l));
       if (l < 0)
          mp_neg(&a, &a);
 
       em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&b, labs(em));
+      mp_set_long(&b, (unsigned long)labs(em));
       if (em < 0)
          mp_neg(&b, &b);
 
-      mp_set_int(&d, labs(l | em));
+      mp_set_long(&d, (unsigned long)labs(l | em));
       if ((l | em) < 0)
          mp_neg(&d, &d);
 
@@ -374,19 +375,19 @@ static int test_mp_tc_and(void)
    }
 
    for (i = 0; i < 1000; ++i) {
-      int l, em;
+      long l, em;
 
       l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&a, labs(l));
+      mp_set_long(&a, (unsigned long)labs(l));
       if (l < 0)
          mp_neg(&a, &a);
 
       em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
-      mp_set_int(&b, labs(em));
+      mp_set_long(&b, (unsigned long)labs(em));
       if (em < 0)
          mp_neg(&b, &b);
 
-      mp_set_int(&d, labs(l & em));
+      mp_set_long(&d, (unsigned long)labs(l & em));
       if ((l & em) < 0)
          mp_neg(&d, &d);
 
@@ -554,9 +555,9 @@ static int test_mp_get_long(void)
    }
 
    for (i = 0; i < ((int)(sizeof(unsigned long)*CHAR_BIT) - 1); ++i) {
-      t = (1ULL << (i+1)) - 1;
+      t = (1UL << (i+1)) - 1;
       if (!t)
-         t = -1;
+         t = ~0UL;
       printf(" t = 0x%lx i = %d\r", t, i);
       do {
          if (mp_set_long(&a, t) != MP_OKAY) {
@@ -592,7 +593,7 @@ static int test_mp_get_long_long(void)
    for (i = 0; i < ((int)(sizeof(unsigned long long)*CHAR_BIT) - 1); ++i) {
       r = (1ULL << (i+1)) - 1;
       if (!r)
-         r = -1;
+         r = ~0ULL;
       printf(" r = 0x%llx i = %d\r", r, i);
       do {
          if (mp_set_long_long(&a, r) != MP_OKAY) {
@@ -1345,7 +1346,7 @@ static int test_mp_ilogb(void)
       }
       /* radix_size includes the memory needed for '\0', too*/
       size -= 2;
-      if (mp_cmp_d(&lb, size) != MP_EQ) {
+      if (mp_cmp_d(&lb, (mp_digit)size) != MP_EQ) {
          goto LBL_ERR;
       }
    }
@@ -1365,7 +1366,7 @@ static int test_mp_ilogb(void)
          goto LBL_ERR;
       }
       size -= 2;
-      if (mp_cmp_d(&lb, size) != MP_EQ) {
+      if (mp_cmp_d(&lb, (mp_digit)size) != MP_EQ) {
          goto LBL_ERR;
       }
    }
diff --git a/makefile_include.mk b/makefile_include.mk
index 1b57833..ccc785f 100644
--- a/makefile_include.mk
+++ b/makefile_include.mk
@@ -51,10 +51,14 @@ CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
 
 ifndef NO_ADDTL_WARNINGS
 # additional warnings
-CFLAGS += -Wsystem-headers
 CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
 CFLAGS += -Wstrict-prototypes -Wpointer-arith
-#CFLAGS += -Wconversion -Wsign-conversion
+endif
+
+ifdef CONV_WARNINGS
+CFLAGS += -Wconversion -Wsign-conversion
+else
+CFLAGS += -Wsystem-headers
 endif
 
 ifdef COMPILE_DEBUG