dotnet3.1/corefx-42900-clang-10.patch

71 lines
2.9 KiB
Diff
Raw Normal View History

From 58d6cd09bd2d5b1085c6572c1d97b8533cf8294b Mon Sep 17 00:00:00 2001
From: Omair Majid <omajid@redhat.com>
Date: Fri, 3 Apr 2020 13:53:09 -0400
Subject: [PATCH] Fix corefx to build on clang 10
Clang 10 adds/enables new warnings, some of which is affecting
the corefx code.
Clang 10 has added -Walloca to warn about uses of alloca. This commit
replaces the only non-compliant use of that with a single fixed
stack-allocated buffer.
Clang 10 has also added -Wimplicit-int-float-conversion. This commit
uses explicit casts to double to avoid the warnings.
This is a backport of dotnet/runtime#33734 to corefx.
After this commit, I can build all of corefx with Clang 10.
---
src/Native/Unix/System.Native/pal_io.c | 20 +++++++++++---------
src/Native/Unix/System.Native/pal_time.c | 2 +-
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/Native/Unix/System.Native/pal_io.c b/src/Native/Unix/System.Native/pal_io.c
index 2d51edacf5ee..c7c42eb3e72b 100644
--- a/src/Native/Unix/System.Native/pal_io.c
+++ b/src/Native/Unix/System.Native/pal_io.c
@@ -906,18 +906,20 @@ int32_t SystemNative_Poll(PollEvent* pollEvents, uint32_t eventCount, int32_t mi
return Error_EINVAL;
}
- size_t bufferSize;
- if (!multiply_s(sizeof(struct pollfd), (size_t)eventCount, &bufferSize))
+ struct pollfd stackBuffer[(uint32_t)(2048/sizeof(struct pollfd))];
+ int useStackBuffer = eventCount <= (sizeof(stackBuffer)/sizeof(stackBuffer[0]));
+ struct pollfd* pollfds = NULL;
+ if (useStackBuffer)
{
- return SystemNative_ConvertErrorPlatformToPal(EOVERFLOW);
+ pollfds = (struct pollfd*)&stackBuffer[0];
}
-
-
- int useStackBuffer = bufferSize <= 2048;
- struct pollfd* pollfds = (struct pollfd*)(useStackBuffer ? alloca(bufferSize) : malloc(bufferSize));
- if (pollfds == NULL)
+ else
{
- return Error_ENOMEM;
+ pollfds = (struct pollfd*)calloc(eventCount, sizeof(*pollfds));
+ if (pollfds == NULL)
+ {
+ return Error_ENOMEM;
+ }
}
for (uint32_t i = 0; i < eventCount; i++)
diff --git a/src/Native/Unix/System.Native/pal_time.c b/src/Native/Unix/System.Native/pal_time.c
index 1a7c862749d1..54ebde60a83b 100644
--- a/src/Native/Unix/System.Native/pal_time.c
+++ b/src/Native/Unix/System.Native/pal_time.c
@@ -169,7 +169,7 @@ int32_t SystemNative_GetCpuUtilization(ProcessCpuInformation* previousCpuInfo)
uint64_t resolution = SystemNative_GetTimestampResolution();
uint64_t timestamp = SystemNative_GetTimestamp();
- uint64_t currentTime = (uint64_t)(timestamp * ((double)SecondsToNanoSeconds / resolution));
+ uint64_t currentTime = (uint64_t)((double)timestamp * ((double)SecondsToNanoSeconds / (double)resolution));
uint64_t lastRecordedCurrentTime = previousCpuInfo->lastRecordedCurrentTime;
uint64_t lastRecordedKernelTime = previousCpuInfo->lastRecordedKernelTime;