Skip to content

Commit 426ff37

Browse files
cmd/cgo, runtime/cgo: avoid GCC/clang conversion warnings
Add explicit conversions to avoid warnings from -Wsign-conversion and -Wshorten-64-to-32. Also avoid runtime errors from -fsanitize=undefined. Fixes #48121 Change-Id: I29dc8d976884fc42826392c10f1e1759bb1a3989 Reviewed-on: https://go-review.googlesource.com/c/go/+/348739 Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 73483df commit 426ff37

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/cmd/cgo/out.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,10 +1458,10 @@ const gccProlog = `
14581458
(have a negative array count) and an inscrutable error will come
14591459
out of the compiler and hopefully mention "name".
14601460
*/
1461-
#define __cgo_compile_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1];
1461+
#define __cgo_compile_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2UL+1UL];
14621462
14631463
/* Check at compile time that the sizes we use match our expectations. */
1464-
#define __cgo_size_assert(t, n) __cgo_compile_assert_eq(sizeof(t), n, _cgo_sizeof_##t##_is_not_##n)
1464+
#define __cgo_size_assert(t, n) __cgo_compile_assert_eq(sizeof(t), (size_t)n, _cgo_sizeof_##t##_is_not_##n)
14651465
14661466
__cgo_size_assert(char, 1)
14671467
__cgo_size_assert(short, 2)

src/runtime/cgo/gcc_sigaction.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
4949
sigemptyset(&act.sa_mask);
5050
for (i = 0; i < 8 * sizeof(goact->mask); i++) {
5151
if (goact->mask & ((uint64_t)(1)<<i)) {
52-
sigaddset(&act.sa_mask, i+1);
52+
sigaddset(&act.sa_mask, (int)(i+1));
5353
}
5454
}
55-
act.sa_flags = goact->flags & ~SA_RESTORER;
55+
act.sa_flags = (int)(goact->flags & ~(uint64_t)SA_RESTORER);
5656
}
5757

58-
ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);
58+
ret = sigaction((int)signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);
5959
if (ret == -1) {
6060
// runtime.rt_sigaction expects _cgo_sigaction to return errno on error.
6161
_cgo_tsan_release();
@@ -70,11 +70,11 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
7070
}
7171
oldgoact->mask = 0;
7272
for (i = 0; i < 8 * sizeof(oldgoact->mask); i++) {
73-
if (sigismember(&oldact.sa_mask, i+1) == 1) {
73+
if (sigismember(&oldact.sa_mask, (int)(i+1)) == 1) {
7474
oldgoact->mask |= (uint64_t)(1)<<i;
7575
}
7676
}
77-
oldgoact->flags = oldact.sa_flags;
77+
oldgoact->flags = (uint64_t)oldact.sa_flags;
7878
}
7979

8080
_cgo_tsan_release();

0 commit comments

Comments
 (0)