Skip to content

Commit 1450598

Browse files
maxwbuckleyclaude
andcommitted
Add Clang compatibility and fix remaining Clang-specific warnings
- Add Clang-specific suppression for -Wvariadic-macro-arguments-omitted (triggered by CUDA toolkit headers) and -Wsign-conversion (not part of GCC's -Wconversion) - Fix deprecated literal operator syntax (remove space before _GiB etc.) - Fix Clang -Wdouble-promotion: use lroundf() instead of lround() for float args, explicit casts for long double expressions - Fix Clang -Wfloat-conversion: use explicit != 0.0F instead of implicit float-to-bool - Fix Clang -Wsign-conversion: add static_cast<size_t>() for int-to- size_t conversions in sample code Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent be38965 commit 1450598

8 files changed

Lines changed: 53 additions & 41 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ if(NOT MSVC)
264264
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2 -Wimplicit-fallthrough")
265265
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
266266
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
267+
268+
# Clang-specific suppressions
269+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
270+
# CUDA toolkit headers trigger variadic macro warnings
271+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macro-arguments-omitted")
272+
# Clang's -Wpedantic enables -Wsign-conversion (GCC does not)
273+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-conversion")
274+
endif()
267275
else()
268276
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBUILD_SYSTEM=cmake_oss")
269277
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")

plugin/groupNormalizationPlugin/groupNormalizationPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int32_t GroupNormalizationPlugin::enqueue(nvinfer1::PluginTensorDesc const* inpu
159159
mBNTensorDesc, //
160160
mBnScales->mPtr, // 1
161161
mBnBias->mPtr, // 0
162-
0.0F, // exponential average factor
162+
static_cast<double>(0.0F), // exponential average factor
163163
nullptr, // resultRunningMean
164164
nullptr, // resultRunningVar
165165
static_cast<double>(mEpsilon), // eps

plugin/voxelGeneratorPlugin/voxelGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ size_t constexpr kSERIALIZATION_SIZE{9 * sizeof(float) + 7 * sizeof(int32_t)};
3939
int32_t npRound(float x)
4040
{
4141
// half way round to nearest-even
42-
int32_t x2 = static_cast<int32_t>(lround(x * 2.0F));
42+
int32_t x2 = static_cast<int32_t>(lroundf(x * 2.0F));
4343
if (x != static_cast<float>(static_cast<int32_t>(x)) && static_cast<float>(x2) == x * 2.0F)
4444
{
45-
return static_cast<int32_t>(lround(x / 2.0F + 0.5F)) * 2;
45+
return static_cast<int32_t>(lroundf(x / 2.0F + 0.5F)) * 2;
4646
}
47-
return static_cast<int32_t>(lround(x));
47+
return static_cast<int32_t>(lroundf(x));
4848
}
4949

5050
VoxelGeneratorPlugin::VoxelGeneratorPlugin(int32_t maxVoxels, int32_t maxPoints, int32_t voxelFeatures, float xMin,

samples/common/ErrorRecorder.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ class SampleErrorRecorder : public IErrorRecorder
5252
}
5353
ErrorCode getErrorCode(int32_t errorIdx) const noexcept final
5454
{
55-
return invalidIndexCheck(errorIdx) ? ErrorCode::kINVALID_ARGUMENT : (*this)[errorIdx].first;
55+
return invalidIndexCheck(errorIdx) ? ErrorCode::kINVALID_ARGUMENT
56+
: (*this)[static_cast<size_t>(errorIdx)].first;
5657
};
5758
IErrorRecorder::ErrorDesc getErrorDesc(int32_t errorIdx) const noexcept final
5859
{
59-
return invalidIndexCheck(errorIdx) ? "errorIdx out of range." : (*this)[errorIdx].second.c_str();
60+
return invalidIndexCheck(errorIdx) ? "errorIdx out of range."
61+
: (*this)[static_cast<size_t>(errorIdx)].second.c_str();
6062
}
6163
// This class can never overflow since we have dynamic resize via std::vector usage.
6264
bool hasOverflowed() const noexcept final
@@ -122,7 +124,7 @@ class SampleErrorRecorder : public IErrorRecorder
122124
{
123125
// By converting signed to unsigned, we only need a single check since
124126
// negative numbers turn into large positive greater than the size.
125-
size_t sIndex = index;
127+
size_t sIndex = static_cast<size_t>(index);
126128
return sIndex >= mErrorStack.size();
127129
}
128130
// Mutex to hold when locking mErrorStack.

samples/common/common.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ using namespace nvinfer1;
105105
#undef CHECK
106106
#define CHECK(status) CHECK_WITH_STREAM(status, std::cerr)
107107

108-
constexpr long double operator"" _GiB(long double val)
108+
constexpr long double operator""_GiB(long double val)
109109
{
110110
return val * (1 << 30);
111111
}
112-
constexpr long double operator"" _MiB(long double val)
112+
constexpr long double operator""_MiB(long double val)
113113
{
114114
return val * (1 << 20);
115115
}
116-
constexpr long double operator"" _KiB(long double val)
116+
constexpr long double operator""_KiB(long double val)
117117
{
118118
return val * (1 << 10);
119119
}
@@ -536,28 +536,28 @@ inline size_t getNbBytes(nvinfer1::DataType t, int64_t vol) noexcept
536536
{
537537
switch (t)
538538
{
539-
case nvinfer1::DataType::kINT64: return 8 * vol;
539+
case nvinfer1::DataType::kINT64: return static_cast<size_t>(8 * vol);
540540
case nvinfer1::DataType::kINT32:
541-
case nvinfer1::DataType::kFLOAT: return 4 * vol;
541+
case nvinfer1::DataType::kFLOAT: return static_cast<size_t>(4 * vol);
542542
case nvinfer1::DataType::kBF16:
543-
case nvinfer1::DataType::kHALF: return 2 * vol;
543+
case nvinfer1::DataType::kHALF: return static_cast<size_t>(2 * vol);
544544
case nvinfer1::DataType::kBOOL:
545545
case nvinfer1::DataType::kUINT8:
546-
case nvinfer1::DataType::kINT8: return vol;
546+
case nvinfer1::DataType::kINT8: return static_cast<size_t>(vol);
547547
case nvinfer1::DataType::kFP8:
548548
#if CUDA_VERSION < 11060
549549
ASSERT(false && "FP8 is not supported");
550550
#else
551-
return vol;
551+
return static_cast<size_t>(vol);
552552
#endif
553553
case nvinfer1::DataType::kE8M0:
554554
#if CUDA_VERSION < 12080
555555
ASSERT(false && "E8M0 is not supported");
556556
#else
557-
return vol;
557+
return static_cast<size_t>(vol);
558558
#endif // CUDA_VERSION < 12080
559559
case nvinfer1::DataType::kINT4:
560-
case nvinfer1::DataType::kFP4: return (vol + 1) / 2;
560+
case nvinfer1::DataType::kFP4: return static_cast<size_t>((vol + 1) / 2);
561561
}
562562
ASSERT(false && "Unknown element type");
563563
}
@@ -759,25 +759,25 @@ inline void writePPMFileWithBBox(const std::string& filename, vPPM ppm, std::vec
759759
for (int x = int(bbox.x1); x < int(bbox.x2); ++x)
760760
{
761761
// bbox top border
762-
ppm.buffer[(round(bbox.y1) * ppm.w + x) * 3] = 255;
763-
ppm.buffer[(round(bbox.y1) * ppm.w + x) * 3 + 1] = 0;
764-
ppm.buffer[(round(bbox.y1) * ppm.w + x) * 3 + 2] = 0;
762+
ppm.buffer[static_cast<size_t>((round(bbox.y1) * ppm.w + x) * 3)] = 255;
763+
ppm.buffer[static_cast<size_t>((round(bbox.y1) * ppm.w + x) * 3 + 1)] = 0;
764+
ppm.buffer[static_cast<size_t>((round(bbox.y1) * ppm.w + x) * 3 + 2)] = 0;
765765
// bbox bottom border
766-
ppm.buffer[(round(bbox.y2) * ppm.w + x) * 3] = 255;
767-
ppm.buffer[(round(bbox.y2) * ppm.w + x) * 3 + 1] = 0;
768-
ppm.buffer[(round(bbox.y2) * ppm.w + x) * 3 + 2] = 0;
766+
ppm.buffer[static_cast<size_t>((round(bbox.y2) * ppm.w + x) * 3)] = 255;
767+
ppm.buffer[static_cast<size_t>((round(bbox.y2) * ppm.w + x) * 3 + 1)] = 0;
768+
ppm.buffer[static_cast<size_t>((round(bbox.y2) * ppm.w + x) * 3 + 2)] = 0;
769769
}
770770

771771
for (int y = int(bbox.y1); y < int(bbox.y2); ++y)
772772
{
773773
// bbox left border
774-
ppm.buffer[(y * ppm.w + round(bbox.x1)) * 3] = 255;
775-
ppm.buffer[(y * ppm.w + round(bbox.x1)) * 3 + 1] = 0;
776-
ppm.buffer[(y * ppm.w + round(bbox.x1)) * 3 + 2] = 0;
774+
ppm.buffer[static_cast<size_t>((y * ppm.w + round(bbox.x1)) * 3)] = 255;
775+
ppm.buffer[static_cast<size_t>((y * ppm.w + round(bbox.x1)) * 3 + 1)] = 0;
776+
ppm.buffer[static_cast<size_t>((y * ppm.w + round(bbox.x1)) * 3 + 2)] = 0;
777777
// bbox right border
778-
ppm.buffer[(y * ppm.w + round(bbox.x2)) * 3] = 255;
779-
ppm.buffer[(y * ppm.w + round(bbox.x2)) * 3 + 1] = 0;
780-
ppm.buffer[(y * ppm.w + round(bbox.x2)) * 3 + 2] = 0;
778+
ppm.buffer[static_cast<size_t>((y * ppm.w + round(bbox.x2)) * 3)] = 255;
779+
ppm.buffer[static_cast<size_t>((y * ppm.w + round(bbox.x2)) * 3 + 1)] = 0;
780+
ppm.buffer[static_cast<size_t>((y * ppm.w + round(bbox.x2)) * 3 + 2)] = 0;
781781
}
782782
}
783783

samples/common/getOptions.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ TRTParsedArgs parseArgs(int argc, const char* const* argv, const std::vector<TRT
201201
continue;
202202
}
203203

204-
if (options[idx].valueRequired)
204+
if (options[static_cast<size_t>(idx)].valueRequired)
205205
{
206206
if (!value.empty())
207207
{
208-
parsedArgs.values[idx].second.push_back(value);
209-
parsedArgs.values[idx].first = static_cast<int>(parsedArgs.values[idx].second.size());
208+
parsedArgs.values[static_cast<size_t>(idx)].second.push_back(value);
209+
parsedArgs.values[static_cast<size_t>(idx)].first
210+
= static_cast<int>(parsedArgs.values[static_cast<size_t>(idx)].second.size());
210211
continue;
211212
}
212213

@@ -222,14 +223,15 @@ TRTParsedArgs parseArgs(int argc, const char* const* argv, const std::vector<TRT
222223
<< "', Should this be its own flag?" << std::endl;
223224
}
224225

225-
parsedArgs.values[idx].second.push_back(nextArg);
226+
parsedArgs.values[static_cast<size_t>(idx)].second.push_back(nextArg);
226227
i += 1; // Next argument already consumed
227228

228-
parsedArgs.values[idx].first = static_cast<int>(parsedArgs.values[idx].second.size());
229+
parsedArgs.values[static_cast<size_t>(idx)].first
230+
= static_cast<int>(parsedArgs.values[static_cast<size_t>(idx)].second.size());
229231
}
230232
else
231233
{
232-
parsedArgs.values[idx].first += 1;
234+
parsedArgs.values[static_cast<size_t>(idx)].first += 1;
233235
}
234236
}
235237
return parsedArgs;

samples/common/sampleInference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ bool inferenceLoop(std::vector<std::unique_ptr<IterationBase>>& iStreams, TimePo
14261426
}
14271427
if (durationMs < warmupMs) // Warming up
14281428
{
1429-
if (durationMs) // Skip complete iterations
1429+
if (durationMs != 0.0F) // Skip complete iterations
14301430
{
14311431
++skip;
14321432
}

samples/common/sampleOptions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,27 +1189,27 @@ void BuildOptions::parse(Arguments& arguments)
11891189
if (memPoolName == "workspace")
11901190
{
11911191
// use unit in MB.
1192-
workspace = static_cast<double>(memPoolSize / 1.0_MiB);
1192+
workspace = static_cast<double>(static_cast<long double>(memPoolSize) / 1.0_MiB);
11931193
}
11941194
else if (memPoolName == "dlaSRAM")
11951195
{
11961196
// use unit in MB.
1197-
dlaSRAM = static_cast<double>(memPoolSize / 1.0_MiB);
1197+
dlaSRAM = static_cast<double>(static_cast<long double>(memPoolSize) / 1.0_MiB);
11981198
}
11991199
else if (memPoolName == "dlaLocalDRAM")
12001200
{
12011201
// use unit in MB.
1202-
dlaLocalDRAM = static_cast<double>(memPoolSize / 1.0_MiB);
1202+
dlaLocalDRAM = static_cast<double>(static_cast<long double>(memPoolSize) / 1.0_MiB);
12031203
}
12041204
else if (memPoolName == "dlaGlobalDRAM")
12051205
{
12061206
// use unit in MB.
1207-
dlaGlobalDRAM = static_cast<double>(memPoolSize / 1.0_MiB);
1207+
dlaGlobalDRAM = static_cast<double>(static_cast<long double>(memPoolSize) / 1.0_MiB);
12081208
}
12091209
else if (memPoolName == "tacticSharedMem")
12101210
{
12111211
// use unit in KB.
1212-
tacticSharedMem = static_cast<double>(memPoolSize / 1.0_KiB);
1212+
tacticSharedMem = static_cast<double>(static_cast<long double>(memPoolSize) / 1.0_KiB);
12131213
}
12141214
else if (!memPoolName.empty())
12151215
{

0 commit comments

Comments
 (0)