From 1a8216b7cd6f272253e7381bc520c65b7dd38b24 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 26 Oct 2023 03:22:01 +0800 Subject: Fix warnings for gcc 12.3 (#3286) * Silence a few gcc out of bounds warnings * Search upwards from executable for prelude directory instead of assuming depth * comment wording * Check return values of read and write * Correct path to vulkan headers in gfx * Correct diagnostic on missing file in slang-embed * Do not use absolute path to libraries in test-context.cpp --------- Co-authored-by: Yong He --- source/core/slang-blob.h | 1 + source/core/slang-io.cpp | 3 ++- source/core/slang-test-tool-util.cpp | 19 ++++++++++++++----- source/core/slang-test-tool-util.h | 2 +- source/core/unix/slang-unix-process.cpp | 3 ++- source/slang/slang-emit-spirv.cpp | 1 + 6 files changed, 21 insertions(+), 8 deletions(-) (limited to 'source') diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h index 7a2c4d967..e678680aa 100644 --- a/source/core/slang-blob.h +++ b/source/core/slang-blob.h @@ -129,6 +129,7 @@ public: /// Allocate size including a 0 byte at `size`. void* allocateTerminated(size_t size) { + SLANG_ASSUME(size != std::numeric_limits::max()); uint8_t* data = (uint8_t*)allocate(size + 1); data[size] = 0; m_sizeInBytes = size; diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 8a2243b15..4ef5ecc2d 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -126,7 +126,8 @@ namespace Slang List buffer; auto copySize = builder.getLength(); buffer.setCount(copySize + 1); - SLANG_ASSERT(copySize < PTRDIFF_MAX); // Shhh gcc, it's ok, we're not copying 9000 Petabytes + // Satisfy GCC + SLANG_ASSUME(copySize < PTRDIFF_MAX && copySize > 0); ::memcpy(buffer.getBuffer(), builder.getBuffer(), copySize); buffer[copySize] = 0; diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp index 68673a29f..487ea89ac 100644 --- a/source/core/slang-test-tool-util.cpp +++ b/source/core/slang-test-tool-util.cpp @@ -103,12 +103,21 @@ static SlangResult _addCUDAPrelude(const String& rootPath, slang::IGlobalSession String parentPath; SLANG_RETURN_ON_FAIL(getExeDirectoryPath(inExePath, parentPath)); - // From directory to the root is ../../.. - // Work out the relative path to the root - String rootRelPath = Path::combine(parentPath, "../../../"); + // Work out the relative path to the root, we will search upwards until we + // find a directory containing 'prelude/slang-cpp-prelude.h' + String rootRelPath; + SLANG_RETURN_ON_FAIL(Path::getCanonical(parentPath, rootRelPath)); + do + { + if(File::exists(Path::combine(rootRelPath, "prelude/slang-cpp-prelude.h"))) + break; + + rootRelPath = Path::getParentDirectory(rootRelPath); + if(rootRelPath == "") + return SLANG_E_NOT_AVAILABLE; + } while(1); - // We want the absolute path to the root - SLANG_RETURN_ON_FAIL(Path::getCanonical(rootRelPath, outExePath)); + outExePath = std::move(rootRelPath); return SLANG_OK; } diff --git a/source/core/slang-test-tool-util.h b/source/core/slang-test-tool-util.h index 186003a62..1e56500d2 100644 --- a/source/core/slang-test-tool-util.h +++ b/source/core/slang-test-tool-util.h @@ -53,7 +53,7 @@ struct TestToolUtil /// Given the exePath, give return the absolute path to the directory the exe is in static SlangResult getExeDirectoryPath(const char* exePath, String& outExeDirectoryPath); - /// Sets the default preludes on the session based on the executable path + /// Sets the default preludes on the session based on an explicit path static SlangResult setSessionDefaultPreludeFromRootPath(const String& rootPath, slang::IGlobalSession* session); /// Calculates the path that is the combination of parentPath, and relPath diff --git a/source/core/unix/slang-unix-process.cpp b/source/core/unix/slang-unix-process.cpp index 3ab113d83..ee5484fd8 100644 --- a/source/core/unix/slang-unix-process.cpp +++ b/source/core/unix/slang-unix-process.cpp @@ -516,7 +516,8 @@ static int pipeCLOEXEC(int pipefd[2]) // Signal the failure to our parent int execErr = errno; - ::write(execWatchPipe[1], &execErr, sizeof(execErr)); + if(::write(execWatchPipe[1], &execErr, sizeof(execErr))) + fprintf(stderr, "error: `exec` watch pipe write failed\n"); // NOTE! Because we have dup2 into STDERR_FILENO, this error will *not* generally appear on // the terminal but in the stderrPipe. diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 3274c3223..0eae87a10 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -323,6 +323,7 @@ struct SpvLiteralBits char* dst = (char*)(result.value.getBuffer()); // Copy the text + SLANG_ASSUME(textCount >= 0); memcpy(dst, text.begin(), textCount); // Set terminating 0, and remaining buffer 0s -- cgit v1.2.3