summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-04-27 12:36:59 +0800
committerGitHub <noreply@github.com>2023-04-26 21:36:59 -0700
commit3acbe8145c60f4d1e7a180b4602a94269a489df5 (patch)
tree8031e7ca897260ac3ab6d2a920864f3114bc8668 /source/core
parenta3da31c189a1cc9bdf85a42ac359b8c2777f3550 (diff)
Fix most of the disabled warnings on gcc/clang (#2839)
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-crypto.cpp7
-rw-r--r--source/core/slang-crypto.h4
-rw-r--r--source/core/slang-io.cpp2
-rw-r--r--source/core/slang-persistent-cache.cpp2
-rw-r--r--source/core/slang-platform.cpp6
-rw-r--r--source/core/slang-process.h1
-rw-r--r--source/core/slang-render-api-util.cpp6
-rw-r--r--source/core/slang-riff.cpp4
-rw-r--r--source/core/slang-secure-crt.h15
-rw-r--r--source/core/slang-stream.cpp7
-rw-r--r--source/core/slang-string-slice-pool.h9
-rw-r--r--source/core/slang-string-util.cpp4
-rw-r--r--source/core/slang-string.cpp2
-rw-r--r--source/core/slang-string.h4
-rw-r--r--source/core/slang-type-text-util.cpp2
-rw-r--r--source/core/unix/slang-unix-process.cpp4
16 files changed, 49 insertions, 30 deletions
diff --git a/source/core/slang-crypto.cpp b/source/core/slang-crypto.cpp
index dfe246c7c..138454140 100644
--- a/source/core/slang-crypto.cpp
+++ b/source/core/slang-crypto.cpp
@@ -75,10 +75,11 @@ void MD5::init()
m_d = 0x10325476;
}
-void MD5::update(const void* data, SlangInt size)
+void MD5::update(const void* data, SlangSizeT size)
{
uint32_t saved_lo;
- SlangInt used, available;
+ uint32_t used;
+ uint32_t available;
saved_lo = m_lo;
if ((m_lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
@@ -330,7 +331,7 @@ void SHA1::init()
m_state[4] = 0xc3d2e1f0;
}
-void SHA1::update(const void* data, SlangInt len)
+void SHA1::update(const void* data, SlangSizeT len)
{
if (!data || len <= 0)
{
diff --git a/source/core/slang-crypto.h b/source/core/slang-crypto.h
index 94078861b..01d6004d0 100644
--- a/source/core/slang-crypto.h
+++ b/source/core/slang-crypto.h
@@ -87,7 +87,7 @@ namespace Slang
MD5();
void init();
- void update(const void* data, SlangInt size);
+ void update(const void* data, SlangSizeT size);
Digest finalize();
static Digest compute(const void* data, SlangInt size);
@@ -110,7 +110,7 @@ namespace Slang
SHA1();
void init();
- void update(const void* data, SlangInt size);
+ void update(const void* data, SlangSizeT size);
Digest finalize();
static Digest compute(const void* data, SlangInt size);
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 52187bd47..81f0cbf87 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -822,7 +822,7 @@ namespace Slang
{
return SLANG_FAIL;
}
- if (resSize >= bufferSize)
+ if (size_t(resSize) >= bufferSize)
{
return SLANG_E_BUFFER_TOO_SMALL;
}
diff --git a/source/core/slang-persistent-cache.cpp b/source/core/slang-persistent-cache.cpp
index 2b4113e16..d934d1b26 100644
--- a/source/core/slang-persistent-cache.cpp
+++ b/source/core/slang-persistent-cache.cpp
@@ -226,7 +226,7 @@ String PersistentCache::getEntryFileName(const Key& key)
{
StringBuilder str;
str << m_cacheDirectory << "/" << key.toString();
- return str;
+ return std::move(str);
}
struct CacheIndexHeader
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index e5af0ba7e..e84f9095f 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -158,14 +158,14 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
#else // _WIN32
-/* static */SlangResult PlatformUtil::getInstancePath(StringBuilder& out)
+/* static */SlangResult PlatformUtil::getInstancePath([[maybe_unused]] StringBuilder& out)
{
// On non Windows it's typically hard to get the instance path, so we'll say not implemented.
// The meaning is also somewhat more ambiguous - is it the exe or the shared library path?
return SLANG_E_NOT_IMPLEMENTED;
}
-/* static */SlangResult PlatformUtil::appendResult(SlangResult res, StringBuilder& builderOut)
+/* static */SlangResult PlatformUtil::appendResult([[maybe_unused]] SlangResult res, [[maybe_unused]] StringBuilder& builderOut)
{
return SLANG_E_NOT_IMPLEMENTED;
}
@@ -301,7 +301,7 @@ static const PlatformFlags s_familyFlags[int(PlatformFamily::CountOf)] =
return s_familyFlags[int(family)];
}
-/* static */SlangResult PlatformUtil::outputDebugMessage(const char* text)
+/* static */SlangResult PlatformUtil::outputDebugMessage([[maybe_unused]] const char* text)
{
#ifdef _WIN32
OutputDebugStringA(text);
diff --git a/source/core/slang-process.h b/source/core/slang-process.h
index 6d86d8b14..ab54f36c9 100644
--- a/source/core/slang-process.h
+++ b/source/core/slang-process.h
@@ -21,6 +21,7 @@ public:
{
enum Enum : Flags
{
+ // Ignored on non-Windows platforms
AttachDebugger = 0x01,
};
};
diff --git a/source/core/slang-render-api-util.cpp b/source/core/slang-render-api-util.cpp
index fa39f46ee..ca58091af 100644
--- a/source/core/slang-render-api-util.cpp
+++ b/source/core/slang-render-api-util.cpp
@@ -56,7 +56,7 @@ UnownedStringSlice RenderApiUtil::getApiName(RenderApiType type)
{
using namespace Slang;
List<UnownedStringSlice> namesList;
- for (int j = 0; j < SLANG_COUNT_OF(RenderApiUtil::s_infos); j++)
+ for (Index j = 0; j < SLANG_COUNT_OF(RenderApiUtil::s_infos); j++)
{
const auto& apiInfo = RenderApiUtil::s_infos[j];
const UnownedStringSlice names(apiInfo.names);
@@ -218,7 +218,7 @@ static Token nextToken(Slang::UnownedStringSlice& textInOut, Slang::UnownedStrin
/* static */RenderApiType RenderApiUtil::findRenderApiType(const Slang::UnownedStringSlice& text)
{
using namespace Slang;
- for (int j = 0; j < SLANG_COUNT_OF(RenderApiUtil::s_infos); j++)
+ for (Index j = 0; j < SLANG_COUNT_OF(RenderApiUtil::s_infos); j++)
{
const auto& apiInfo = RenderApiUtil::s_infos[j];
if (StringUtil::indexOfInSplit(UnownedStringSlice(apiInfo.names), ',', text) >= 0)
@@ -233,7 +233,7 @@ static Token nextToken(Slang::UnownedStringSlice& textInOut, Slang::UnownedStrin
/* static */RenderApiType RenderApiUtil::findImplicitLanguageRenderApiType(const Slang::UnownedStringSlice& text)
{
using namespace Slang;
- for (int j = 0; j < SLANG_COUNT_OF(RenderApiUtil::s_infos); j++)
+ for (Index j = 0; j < SLANG_COUNT_OF(RenderApiUtil::s_infos); j++)
{
const auto& apiInfo = RenderApiUtil::s_infos[j];
if (StringUtil::indexOfInSplit(UnownedStringSlice(apiInfo.languageNames), ',', text) >= 0)
diff --git a/source/core/slang-riff.cpp b/source/core/slang-riff.cpp
index 670fed7a2..a90c65db9 100644
--- a/source/core/slang-riff.cpp
+++ b/source/core/slang-riff.cpp
@@ -278,7 +278,6 @@ struct DumpVisitor : public RiffContainer::Visitor
/* static */SlangResult RiffUtil::read(Stream* stream, RiffContainer& outContainer)
{
typedef RiffContainer::ScopeChunk ScopeChunk;
- typedef RiffContainer::ScopeChunk ScopeContainer;
outContainer.reset();
size_t remaining;
@@ -773,7 +772,8 @@ void RiffContainer::endChunk()
size_t chunkPayloadSize;
// The chunk we are popping
- Chunk* chunk = nullptr;
+ // Only keep track of this in debug builds
+ [[maybe_unused]] Chunk* chunk = nullptr;
ListChunk* parent;
if (m_dataChunk)
diff --git a/source/core/slang-secure-crt.h b/source/core/slang-secure-crt.h
index b6f6671dd..46552914a 100644
--- a/source/core/slang-secure-crt.h
+++ b/source/core/slang-secure-crt.h
@@ -6,12 +6,14 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
+#include <assert.h>
#include <wchar.h>
-inline void memcpy_s(void *dest, size_t numberOfElements, const void * src, size_t count)
+inline void memcpy_s(void *dest, [[maybe_unused]] size_t destSize, const void * src, size_t count)
{
- memcpy(dest, src, count);
+ assert(destSize >= count);
+ memcpy(dest, src, count);
}
#define _TRUNCATE ((size_t)-1)
@@ -22,9 +24,10 @@ inline void fopen_s(FILE**f, const char * fileName, const char * mode)
*f = fopen(fileName, mode);
}
-inline size_t fread_s(void * buffer, size_t bufferSize, size_t elementSize, size_t count, FILE * stream)
+inline size_t fread_s(void * buffer, [[maybe_unused]] size_t bufferSize, size_t elementSize, size_t count, FILE * stream)
{
- return fread(buffer, elementSize, count, stream);
+ assert(bufferSize >= elementSize * count);
+ return fread(buffer, elementSize, count, stream);
}
inline size_t wcsnlen_s(const wchar_t * str, size_t /*numberofElements*/)
@@ -80,13 +83,11 @@ inline void strcpy_s(char * strDestination, size_t /*numberOfElements*/, const c
inline void wcsncpy_s(wchar_t * strDestination, size_t /*numberOfElements*/, const wchar_t * strSource, size_t count)
{
- wcscpy(strDestination, strSource);
- //wcsncpy(strDestination, strSource, count);
+ wcsncpy(strDestination, strSource, count);
}
inline void strncpy_s(char * strDestination, size_t /*numberOfElements*/, const char * strSource, size_t count)
{
strncpy(strDestination, strSource, count);
- //wcsncpy(strDestination, strSource, count);
}
#endif
#endif
diff --git a/source/core/slang-stream.cpp b/source/core/slang-stream.cpp
index 47cf533eb..4b5d92228 100644
--- a/source/core/slang-stream.cpp
+++ b/source/core/slang-stream.cpp
@@ -37,7 +37,12 @@ SlangResult FileStream::init(const String& fileName, FileMode fileMode, FileAcce
return _init(fileName, fileMode, access, share);
}
-SlangResult FileStream::_init(const String& fileName, FileMode fileMode, FileAccess access, FileShare share)
+SlangResult FileStream::_init(
+ const String& fileName,
+ FileMode fileMode,
+ FileAccess access,
+ // Only used on Windows
+ [[maybe_unused]] FileShare share)
{
// Make sure it's closed to start with
close();
diff --git a/source/core/slang-string-slice-pool.h b/source/core/slang-string-slice-pool.h
index 843556296..f50ac8dde 100644
--- a/source/core/slang-string-slice-pool.h
+++ b/source/core/slang-string-slice-pool.h
@@ -85,7 +85,14 @@ public:
Index getSlicesCount() const { return m_slices.getCount(); }
/// Returns true if the handle is a default one. Only meaningful on a Style::Default.
- bool isDefaultHandle(Handle handle) const { SLANG_ASSERT(m_style == Style::Default && Index(handle) >= 0); return Index(handle) < kDefaultHandlesCount; }
+ bool isDefaultHandle(Handle handle) const
+ {
+ SLANG_ASSERT(
+ m_style == Style::Default &&
+ // TODO(C++20), use bit_cast here
+ HandleIntegral(handle) <= HandleIntegral(std::numeric_limits<Index>::max()));
+ return Index(handle) < kDefaultHandlesCount;
+ }
/// Convert a handle to and index. (A handle is just an index!)
static Index asIndex(Handle handle) { return Index(handle); }
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp
index a1f310401..29e0dad5d 100644
--- a/source/core/slang-string-util.cpp
+++ b/source/core/slang-string-util.cpp
@@ -290,7 +290,7 @@ UnownedStringSlice StringUtil::getAtInSplit(const UnownedStringSlice& in, char s
append(format, args, builder);
va_end(args);
- return builder;
+ return std::move(builder);
}
/* static */UnownedStringSlice StringUtil::getSlice(ISlangBlob* blob)
@@ -342,7 +342,7 @@ ComPtr<ISlangBlob> StringUtil::createStringBlob(const String& string)
}
builder.appendInPlace(dstChars, numChars);
- return builder;
+ return std::move(builder);
}
/* static */String StringUtil::calcCharReplaced(const String& string, char fromChar, char toChar)
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp
index 0cb034604..dd2138c83 100644
--- a/source/core/slang-string.cpp
+++ b/source/core/slang-string.cpp
@@ -367,7 +367,7 @@ namespace Slang
if (outLength)
*outLength = length;
- for(int ii = 0; ii < sizeof(wchar_t); ++ii)
+ for(size_t ii = 0; ii < sizeof(wchar_t); ++ii)
buf.add(0);
wchar_t* beginData = (wchar_t*)buf.getBuffer();
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 4c78cc32e..429a60c46 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -583,6 +583,10 @@ namespace Slang
char operator[](Index id) const
{
SLANG_ASSERT(id >= 0 && id < getLength());
+ // Silence a pedantic warning on GCC
+#if __GNUC__
+ if(id < 0) __builtin_unreachable();
+#endif
return begin()[id];
}
diff --git a/source/core/slang-type-text-util.cpp b/source/core/slang-type-text-util.cpp
index 9d2f93ba3..0d396195f 100644
--- a/source/core/slang-type-text-util.cpp
+++ b/source/core/slang-type-text-util.cpp
@@ -197,7 +197,7 @@ struct DebugInfoFormatTable
switch (type)
{
- default: /* fall-through to none */
+ default: [[fallthrough]]; /* fall-through to none */
SLANG_PASS_THROUGH_HUMAN_TEXT(SLANG_PASS_THROUGH_HUMAN_CASE)
}
}
diff --git a/source/core/unix/slang-unix-process.cpp b/source/core/unix/slang-unix-process.cpp
index e440bbb38..428bef874 100644
--- a/source/core/unix/slang-unix-process.cpp
+++ b/source/core/unix/slang-unix-process.cpp
@@ -345,7 +345,7 @@ SlangResult UnixPipeStream::write(const void* buffer, size_t length)
const ssize_t writeResult = ::write(m_fd, buffer, length);
- if (writeResult < 0 || writeResult != length)
+ if (writeResult < 0 || size_t(writeResult) != length)
{
return SLANG_FAIL;
}
@@ -389,7 +389,7 @@ static int pipeCLOEXEC(int pipefd[2])
#endif
}
-/* static */SlangResult Process::create(const CommandLine& commandLine, Process::Flags flags, RefPtr<Process>& outProcess)
+/* static */SlangResult Process::create(const CommandLine& commandLine, Process::Flags, RefPtr<Process>& outProcess)
{
const char* whatFailed = nullptr;
pid_t childPid;