Skip to content

Commit fc4c242

Browse files
authored
Fix macos CI and clang warnings. (shader-slang#4019)
* Fix macos CI. * Fix. * Fix. * Fix. * Fix clang warnings. * Fix more warnings.
1 parent 211b2ff commit fc4c242

12 files changed

+23
-26
lines changed

.github/github_test.sh

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ if [ "${ARCHITECTURE}" == "x86_64" ]; then
1818
ARCHITECTURE="x64"
1919
fi
2020

21+
if [ "${ARCHITECTURE}" == "arm64" ]; then
22+
ARCHITECTURE="aarch64"
23+
fi
24+
2125
# CONFIGURATION=release or debug
2226
if [ "${CC}" == "gcc" ] && [ "${CONFIGURATION}" == "release" ] && [ "${ARCHITECTURE}" == "x64" ]
2327
then

.github/workflows/macos.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
matrix:
1818
configuration: ['release'] # 'debug'
1919
compiler: ['clang']
20-
platform: ['x64']
21-
targetPlatform: ['x64']
20+
platform: ['aarch64']
21+
targetPlatform: ['aarch64']
2222
steps:
2323
- uses: actions/checkout@v3
2424
with:
@@ -64,7 +64,7 @@ jobs:
6464
path: |
6565
${{ steps.package.outputs.SLANG_BINARY_ARCHIVE }}
6666
- name: test
67-
if: ${{ matrix.targetPlatform != 'aarch64' }}
67+
if: ${{ matrix.targetPlatform != 'x64' }}
6868
run:
6969
CONFIGURATION=${{matrix.configuration}}
7070
CC=${{matrix.compiler}}

.github/workflows/release-macos.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
configuration: ['release'] # 'debug'
1616
compiler: ['clang']
17-
platform: ['x64']
17+
platform: ['aarch64']
1818
targetPlatform: ['x64', 'aarch64']
1919
steps:
2020
- name: Checkout code

external/stb/stb_image_write.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
773773
#ifdef __STDC_LIB_EXT1__
774774
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
775775
#else
776-
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
776+
len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
777777
#endif
778778
s->func(s->context, buffer, len);
779779

github_macos_build.sh

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ make config=${CONFIGURATION}_${ARCH} -j`sysctl -n hw.ncpu`
2121

2222
rm -rf ./bin
2323

24-
ARCH="arm64"
2524
# Create the makefile
2625
./premake5 gmake2 --cc=${CC} --enable-xlib=false --enable-embed-stdlib=true --arch=${TARGETARCH} --deps=true --build-glslang=true --no-progress=true --skip-source-generation=true --deploy-slang-llvm=false --deploy-slang-glslang=false
2726
make config=${CONFIGURATION}_${TARGETARCH} -j`sysctl -n hw.ncpu`

source/compiler-core/slang-perfect-hash.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ String perfectHashToEmbeddableCpp(
146146
w.print("bool %s(const UnownedStringSlice& str, %s& value)\n", String(funcName).getBuffer(), String(valueType).getBuffer());
147147
line("{");
148148

149-
w.print(" static const unsigned tableSalt[%ld] = {\n", hashParams.saltTable.getCount());
149+
w.print(" static const unsigned tableSalt[%d] = {\n", (int)hashParams.saltTable.getCount());
150150
w.print(" ");
151151
for (Index i = 0; i < hashParams.saltTable.getCount(); ++i)
152152
{
@@ -170,7 +170,7 @@ String perfectHashToEmbeddableCpp(
170170
w.print(" using KV = std::pair<const char*, %s>;\n", String(valueType).getBuffer());
171171
line("");
172172

173-
w.print(" static const KV words[%ld] =\n", hashParams.destTable.getCount());
173+
w.print(" static const KV words[%d] =\n", (int)hashParams.destTable.getCount());
174174
line(" {");
175175
for (Index i = 0; i < hashParams.destTable.getCount(); ++i)
176176
{
@@ -191,7 +191,7 @@ String perfectHashToEmbeddableCpp(
191191
line(" UInt32 h = salt;");
192192
line(" for (const char c : str)");
193193
line(" h = (h * 0x01000193) ^ c;");
194-
w.print(" return h %% %ld;\n", hashParams.saltTable.getCount());
194+
w.print(" return h %% %d;\n", (int)hashParams.saltTable.getCount());
195195
line(" };");
196196
line("");
197197

source/slang/glsl.meta.slang

-1
Original file line numberDiff line numberDiff line change
@@ -3236,7 +3236,6 @@ ${{{{
32363236
StringBuilder SPV_DEFAULT_SAMPLE_VAR_IF_MISSINGBuilder;
32373237

32383238
SPV_PREFIX_IMAGE_PARAMSBuilder << "$image $P";
3239-
SPV_SUFFIX_IMAGE_PARAMSBuilder;
32403239
if (targetShape.isMS)
32413240
{
32423241
SPV_SUFFIX_IMAGE_PARAMSBuilder << " Sample $sample";

source/slang/slang-emit-metal.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ void MetalSourceEmitter::emitParameterGroupImpl(IRGlobalParam* varDecl, IRUnifor
160160

161161
void MetalSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPointDecoration* entryPointDecor)
162162
{
163-
auto profile = m_effectiveProfile;
164163
auto stage = entryPointDecor->getProfile().getStage();
165164

166165
switch (stage)

source/slang/slang-emit-source-writer.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
#include "../core/slang-char-encode.h"
55

6-
// Disable warnings about sprintf
7-
#ifdef _WIN32
8-
# pragma warning(disable:4996)
9-
#endif
106

117
// Note: using C++ stdio just to get a locale-independent
128
// way to format floating-point values.
@@ -199,28 +195,28 @@ void SourceWriter::emitInt64(int64_t value)
199195
void SourceWriter::emit(Int32 value)
200196
{
201197
char buffer[16];
202-
sprintf(buffer, "%" PRId32, value);
198+
snprintf(buffer, sizeof(buffer), "%" PRId32, value);
203199
emit(buffer);
204200
}
205201

206202
void SourceWriter::emit(Int64 value)
207203
{
208204
char buffer[32];
209-
sprintf(buffer, "%" PRId64, value);
205+
snprintf(buffer, sizeof(buffer), "%" PRId64, value);
210206
emit(buffer);
211207
}
212208

213209
void SourceWriter::emit(UInt32 value)
214210
{
215211
char buffer[32];
216-
sprintf(buffer, "%" PRIu32, value);
212+
snprintf(buffer, sizeof(buffer), "%" PRIu32, value);
217213
emit(buffer);
218214
}
219215

220216
void SourceWriter::emit(UInt64 value)
221217
{
222218
char buffer[32];
223-
sprintf(buffer, "%" PRIu64, value);
219+
snprintf(buffer, sizeof(buffer), "%" PRIu64, value);
224220
emit(buffer);
225221
}
226222

@@ -463,7 +459,7 @@ void SourceWriter::_emitLineDirective(const HumaneSourceLoc& sourceLocation)
463459
emitRawText("\n#line ");
464460

465461
char buffer[16];
466-
sprintf(buffer, "%llu", (unsigned long long)sourceLocation.line);
462+
snprintf(buffer, sizeof(buffer), "%llu", (unsigned long long)sourceLocation.line);
467463
emitRawText(buffer);
468464

469465
// Only emit the path part of a `#line` directive if needed
@@ -497,7 +493,7 @@ void SourceWriter::_emitLineDirective(const HumaneSourceLoc& sourceLocation)
497493
m_mapGLSLSourcePathToID.add(path, id);
498494
}
499495

500-
sprintf(buffer, "%d", id);
496+
snprintf(buffer, sizeof(buffer), "%d", id);
501497
emitRawText(buffer);
502498
break;
503499
}

source/slang/slang-ir-glsl-legalize.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,7 @@ void getAllNullLocationRayObjectsAndUsedLocations(
27952795
for (auto inst : module->getGlobalInsts())
27962796
{
27972797
auto instOp = inst->getOp();
2798-
IRIntegerValue intLitVal = NULL;
2798+
IRIntegerValue intLitVal = 0;
27992799
if (instOp != kIROp_GlobalParam && instOp != kIROp_GlobalVar) continue;
28002800
for (auto decor : inst->getDecorations())
28012801
{
@@ -2839,7 +2839,7 @@ void assignRayPayloadHitObjectAttributeLocations(IRModule* module)
28392839
for (auto inst : nullRayObjects)
28402840
{
28412841
IRInst* location = nullptr;
2842-
IRIntegerValue intLitVal = NULL;
2842+
IRIntegerValue intLitVal = 0;
28432843
for (auto decor : inst->getDecorations())
28442844
{
28452845
switch (decor->getOp())

source/slang/slang-parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5453,7 +5453,7 @@ namespace Slang
54535453
bool lookAheadTokenAfterModifiers(Parser* parser, const char* token)
54545454
{
54555455
TokenReader tokenPreview = parser->tokenReader;
5456-
for (Index i = 0;; i++)
5456+
for (;;)
54575457
{
54585458
if (tokenPreview.peekToken().getContent() == token)
54595459
return true;

tools/slang-spirv-embed-generator/spirv-embed-generator-main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ void writeInfo(
353353
line("static bool lookupQualifiedEnum(const QualifiedEnumName& k, SpvWord& v)");
354354
line("{");
355355
line(" static_assert(sizeof(k.kind.index) == 1);");
356-
w.print(" if(k.name.getLength() > %ld)\n", maxNameLength);
356+
w.print(" if(k.name.getLength() > %d)\n", (int)maxNameLength);
357357
line(" return false;");
358-
w.print(" char name[%ld];\n", maxNameLength + 2);
358+
w.print(" char name[%d];\n", (int)maxNameLength + 2);
359359
line(" name[0] = char((k.kind.index >> 4) + 'a');");
360360
line(" name[1] = char((k.kind.index & 0xf) + 'a');");
361361
line(" memcpy(name+2, k.name.begin(), k.name.getLength());");

0 commit comments

Comments
 (0)