diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index 82cb82a1a4e..f9b4c86c7d7 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -112,13 +112,13 @@ function(set_default_compile_options target) -Wno-invalid-offsetof -Wno-newline-eof -Wno-return-std-move + # Allow unused variables with a pattern of `if (auto v = as<...>(...))`. + # This pattern is very common in Slang code base. + -Wno-unused-but-set-variable # Allowed warnings: # If a function returns an address/reference to a local, we want it to # produce an error, because it probably means something very bad. -Werror=return-local-addr - # Allow unused variables with a pattern of `if (auto v = as<...>(...))`. - # This pattern is very common in Slang code base. - -Wno-error=unused-but-set-variable # Some warnings which are on by default in MSVC -Wnarrowing ) @@ -135,7 +135,6 @@ function(set_default_compile_options target) -Wno-sign-compare -Wno-unused-function -Wno-unused-value - -Wno-unused-but-set-variable -Wno-implicit-fallthrough -Wno-missing-field-initializers -Wno-strict-aliasing diff --git a/examples/mlp-training-coopvec/mlp-training-coopvec.cpp b/examples/mlp-training-coopvec/mlp-training-coopvec.cpp index 9b5dde53148..8bd6a8e0e79 100644 --- a/examples/mlp-training-coopvec/mlp-training-coopvec.cpp +++ b/examples/mlp-training-coopvec/mlp-training-coopvec.cpp @@ -165,7 +165,7 @@ struct ExampleProgram : public TestBase std::vector inputBufferData; for (int i = 0; i < inputCount; i++) { - inputBufferData.push_back((float)rand() / RAND_MAX); + inputBufferData.push_back(rand() / static_cast(RAND_MAX)); } auto inputBuffer = createBuffer(inputCount * sizeof(float), inputBufferData.data()); diff --git a/examples/mlp-training/mlp-training.cpp b/examples/mlp-training/mlp-training.cpp index 38090578f8b..44bbbe58455 100644 --- a/examples/mlp-training/mlp-training.cpp +++ b/examples/mlp-training/mlp-training.cpp @@ -164,7 +164,7 @@ struct ExampleProgram : public TestBase std::vector inputBufferData; for (int i = 0; i < inputCount; i++) { - inputBufferData.push_back((float)rand() / RAND_MAX); + inputBufferData.push_back(rand() / static_cast(RAND_MAX)); } auto inputBuffer = createBuffer(inputCount * sizeof(float), inputBufferData.data()); diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 52ad2cf3cea..2391bc25f63 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2303,8 +2303,7 @@ IRConstant* IRBuilder::_findOrEmitConstant(IRConstant& keyInst) IRInst* IRBuilder::getBoolValue(bool inValue) { - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; keyInst.m_op = kIROp_BoolLit; keyInst.typeUse.usedValue = getBoolType(); keyInst.value.intVal = IRIntegerValue(inValue); @@ -2318,8 +2317,7 @@ IRInst* IRBuilder::getIntValue(IRIntegerValue value) IRInst* IRBuilder::getIntValue(IRType* type, IRIntegerValue inValue) { - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; keyInst.m_op = kIROp_IntLit; keyInst.typeUse.usedValue = type; // Truncate the input value based on `type`. @@ -2356,8 +2354,7 @@ IRInst* IRBuilder::getIntValue(IRType* type, IRIntegerValue inValue) IRInst* IRBuilder::getFloatValue(IRType* type, IRFloatingPointValue inValue) { - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; keyInst.m_op = kIROp_FloatLit; keyInst.typeUse.usedValue = type; // Truncate the input value based on `type`. @@ -2379,12 +2376,10 @@ IRInst* IRBuilder::getFloatValue(IRType* type, IRFloatingPointValue inValue) IRStringLit* IRBuilder::getStringValue(const UnownedStringSlice& inSlice) { - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; // Mark that this is on the stack... - IRDecoration stackDecoration; - memset(&stackDecoration, 0, sizeof(stackDecoration)); + IRDecoration stackDecoration{}; stackDecoration.m_op = kIROp_TransitoryDecoration; stackDecoration.insertAtEnd(&keyInst); @@ -2400,8 +2395,7 @@ IRStringLit* IRBuilder::getStringValue(const UnownedStringSlice& inSlice) IRBlobLit* IRBuilder::getBlobValue(ISlangBlob* blob) { - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; char* buffer = (char*)(getModule()->getMemoryArena().allocate(blob->getBufferSize())); if (!buffer) @@ -2413,8 +2407,7 @@ IRBlobLit* IRBuilder::getBlobValue(ISlangBlob* blob) UnownedStringSlice inSlice(buffer, blob->getBufferSize()); // Mark that this is on the stack... - IRDecoration stackDecoration; - memset(&stackDecoration, 0, sizeof(stackDecoration)); + IRDecoration stackDecoration{}; stackDecoration.m_op = kIROp_TransitoryDecoration; stackDecoration.insertAtEnd(&keyInst); @@ -2430,8 +2423,7 @@ IRBlobLit* IRBuilder::getBlobValue(ISlangBlob* blob) IRPtrLit* IRBuilder::getPtrValue(IRType* type, void* data) { - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; keyInst.m_op = kIROp_PtrLit; keyInst.typeUse.usedValue = type; keyInst.value.ptrVal = data; @@ -2440,8 +2432,7 @@ IRPtrLit* IRBuilder::getPtrValue(IRType* type, void* data) IRPtrLit* IRBuilder::getNullPtrValue(IRType* type) { - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; keyInst.m_op = kIROp_PtrLit; keyInst.typeUse.usedValue = type; keyInst.value.ptrVal = nullptr; @@ -2452,8 +2443,7 @@ IRVoidLit* IRBuilder::getVoidValue() { IRType* type = getVoidType(); - IRConstant keyInst; - memset(&keyInst, 0, sizeof(keyInst)); + IRConstant keyInst{}; keyInst.m_op = kIROp_VoidLit; keyInst.typeUse.usedValue = type; keyInst.value.intVal = 0; diff --git a/tools/slang-fiddle/slang-fiddle-lua.cpp b/tools/slang-fiddle/slang-fiddle-lua.cpp index adebf555c44..882289ca492 100644 --- a/tools/slang-fiddle/slang-fiddle-lua.cpp +++ b/tools/slang-fiddle/slang-fiddle-lua.cpp @@ -1,5 +1,10 @@ // slang-fiddle-lua.cpp - +#include "slang.h" #define MAKE_LIB 1 + +#if SLANG_UNIX_FAMILY +#define LUA_USE_POSIX +#endif + #include "lua/onelua.c"