summaryrefslogtreecommitdiff
path: root/absl/base
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2022-09-01 10:08:26 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-09-01 10:09:08 -0700
commitfa108c444f18f6345b78090af47ec5fb4a7c2c36 (patch)
treeb85fec244098d41964f1d2b5709c45bbd5638a2b /absl/base
parent847fa56a5422c20a6f471e67ac0bca004ff5eac5 (diff)
Rollback of fix "unsafe narrowing" warnings in absl, 8/n.
Addresses failures with the following, in some files: -Wshorten-64-to-32 -Wimplicit-int-conversion -Wsign-compare -Wsign-conversion -Wtautological-unsigned-zero-compare (This specific CL focuses on .cc files in */internal/.) Bug: chromium:1292951 PiperOrigin-RevId: 471561809 Change-Id: I7abd6d83706f5ca135f1ce3458192a498a6280b9
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/internal/direct_mmap.h3
-rw-r--r--absl/base/internal/low_level_alloc.cc2
-rw-r--r--absl/base/internal/sysinfo.cc15
3 files changed, 9 insertions, 11 deletions
diff --git a/absl/base/internal/direct_mmap.h b/absl/base/internal/direct_mmap.h
index 815b8d23..e492bb00 100644
--- a/absl/base/internal/direct_mmap.h
+++ b/absl/base/internal/direct_mmap.h
@@ -97,8 +97,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd,
#ifdef __BIONIC__
// SYS_mmap2 has problems on Android API level <= 16.
// Workaround by invoking __mmap2() instead.
- return __mmap2(start, length, prot, flags, fd,
- static_cast<size_t>(offset / pagesize));
+ return __mmap2(start, length, prot, flags, fd, offset / pagesize);
#else
return reinterpret_cast<void*>(
syscall(SYS_mmap2, start, length, prot, flags, fd,
diff --git a/absl/base/internal/low_level_alloc.cc b/absl/base/internal/low_level_alloc.cc
index 662167b0..aa6c3c3c 100644
--- a/absl/base/internal/low_level_alloc.cc
+++ b/absl/base/internal/low_level_alloc.cc
@@ -332,7 +332,7 @@ size_t GetPageSize() {
#elif defined(__wasm__) || defined(__asmjs__)
return getpagesize();
#else
- return static_cast<size_t>(sysconf(_SC_PAGESIZE));
+ return sysconf(_SC_PAGESIZE);
#endif
}
diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc
index d820ce38..a3e08b93 100644
--- a/absl/base/internal/sysinfo.cc
+++ b/absl/base/internal/sysinfo.cc
@@ -136,7 +136,7 @@ static int GetNumCPUs() {
// Other possibilities:
// - Read /sys/devices/system/cpu/online and use cpumask_parse()
// - sysconf(_SC_NPROCESSORS_ONLN)
- return static_cast<int>(std::thread::hardware_concurrency());
+ return std::thread::hardware_concurrency();
#endif
}
@@ -194,7 +194,7 @@ static bool ReadLongFromFile(const char *file, long *value) {
char line[1024];
char *err;
memset(line, '\0', sizeof(line));
- ssize_t len = read(fd, line, sizeof(line) - 1);
+ int len = read(fd, line, sizeof(line) - 1);
if (len <= 0) {
ret = false;
} else {
@@ -376,7 +376,7 @@ pid_t GetTID() {
#endif
pid_t GetTID() {
- return static_cast<pid_t>(syscall(SYS_gettid));
+ return syscall(SYS_gettid);
}
#elif defined(__akaros__)
@@ -429,11 +429,11 @@ static constexpr int kBitsPerWord = 32; // tid_array is uint32_t.
// Returns the TID to tid_array.
static void FreeTID(void *v) {
intptr_t tid = reinterpret_cast<intptr_t>(v);
- intptr_t word = tid / kBitsPerWord;
+ int word = tid / kBitsPerWord;
uint32_t mask = ~(1u << (tid % kBitsPerWord));
absl::base_internal::SpinLockHolder lock(&tid_lock);
assert(0 <= word && static_cast<size_t>(word) < tid_array->size());
- (*tid_array)[static_cast<size_t>(word)] &= mask;
+ (*tid_array)[word] &= mask;
}
static void InitGetTID() {
@@ -455,7 +455,7 @@ pid_t GetTID() {
intptr_t tid = reinterpret_cast<intptr_t>(pthread_getspecific(tid_key));
if (tid != 0) {
- return static_cast<pid_t>(tid);
+ return tid;
}
int bit; // tid_array[word] = 1u << bit;
@@ -476,8 +476,7 @@ pid_t GetTID() {
while (bit < kBitsPerWord && (((*tid_array)[word] >> bit) & 1) != 0) {
++bit;
}
- tid =
- static_cast<intptr_t>((word * kBitsPerWord) + static_cast<size_t>(bit));
+ tid = (word * kBitsPerWord) + bit;
(*tid_array)[word] |= 1u << bit; // Mark the TID as allocated.
}