Skip to content

Commit ea76214

Browse files
Improve ClangCL support by disabling, fixing warnings (#5876)
Co-authored-by: Mario Emmenlauer <[email protected]>
1 parent 85816e4 commit ea76214

21 files changed

+135
-89
lines changed

cmake/TargetExportScript.cmake

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,22 @@ function(target_export_script TARGET)
99
set(multiValueArgs)
1010
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
1111

12+
get_property(target_type TARGET ${TARGET} PROPERTY TYPE)
13+
if (NOT target_type STREQUAL "SHARED_LIBRARY")
14+
# Linker scripts do nothing on non-shared libraries.
15+
return()
16+
endif ()
17+
18+
if (MSVC)
19+
## TODO: implement something similar for Windows/link.exe
20+
# https://github.com/halide/Halide/issues/4651
21+
return()
22+
endif ()
23+
1224
set(dummy_source [[ int main() { return 0; } ]])
13-
set(is_shared "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>")
1425

15-
# CMake doesn't recognize MSVC/link.exe's unknown-option warning.
16-
set(extra_errors FAIL_REGEX "LNK4044: unrecognized option")
26+
# CMake doesn't recognize MSVC/ldd link.exe's unknown-option warnings
27+
set(extra_errors FAIL_REGEX "LNK4044: unrecognized option|warning : ignoring unknown argument")
1728

1829
## More linkers support the GNU syntax (ld, lld, gold), so try it first.
1930
set(version_script "LINKER:--version-script=${ARG_GNU_LD}")
@@ -22,8 +33,8 @@ function(target_export_script TARGET)
2233
check_cxx_source_compiles("${dummy_source}" LINKER_HAS_FLAG_VERSION_SCRIPT ${extra_errors})
2334

2435
if (LINKER_HAS_FLAG_VERSION_SCRIPT)
25-
target_link_options(${TARGET} PRIVATE "$<${is_shared}:${version_script}>")
26-
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "$<${is_shared}:${ARG_GNU_LD}>")
36+
target_link_options(${TARGET} PRIVATE "${version_script}")
37+
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${ARG_GNU_LD}")
2738
return()
2839
endif ()
2940

@@ -34,16 +45,10 @@ function(target_export_script TARGET)
3445
check_cxx_source_compiles("${dummy_source}" LINKER_HAS_FLAG_EXPORTED_SYMBOLS_LIST ${extra_errors})
3546

3647
if (LINKER_HAS_FLAG_EXPORTED_SYMBOLS_LIST)
37-
target_link_options(${TARGET} PRIVATE "$<${is_shared}:${exported_symbols_list}>")
38-
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "$<${is_shared}:${ARG_APPLE_LD}>")
48+
target_link_options(${TARGET} PRIVATE "${exported_symbols_list}")
49+
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${ARG_APPLE_LD}")
3950
return()
4051
endif ()
4152

42-
## TODO: implement something similar for Windows/link.exe
43-
# https://github.com/halide/Halide/issues/4651
44-
45-
## Warn the user if we were supposed to have been able to attach a linker script.
46-
if (BUILD_SHARED_LIBS AND NOT MSVC)
47-
message(WARNING "Unknown linker! Could not attach Halide linker script.")
48-
endif ()
53+
message(WARNING "Unknown linker! Could not attach Halide linker script.")
4954
endfunction()

src/AssociativeOpsTable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ map<TableKey, vector<AssociativePattern>> pattern_tables;
130130
Expr one_##index = make_const((t), 1); \
131131
Expr neg_one_##index = make_const((t), -1); \
132132
Expr tmax_##index = (t).max(); \
133-
Expr tmin_##index = (t).min();
133+
Expr tmin_##index = (t).min()
134134

135135
#define declare_vars_single(types) \
136136
internal_assert((types).size() == 1); \
137137
declare_vars((types)[0], 0)
138138

139139
#define declare_vars_double(types) \
140140
internal_assert((types).size() == 2); \
141-
declare_vars((types)[0], 0) \
142-
declare_vars((types)[1], 1)
141+
declare_vars((types)[0], 0); \
142+
declare_vars((types)[1], 1)
143143

144144
void populate_ops_table_single_general_add(const vector<Type> &types, vector<AssociativePattern> &table) {
145145
declare_vars_single(types);

src/Buffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,12 @@ class Buffer {
568568
Expr operator()(const Expr &first, Args... rest) const {
569569
std::vector<Expr> args = {first, rest...};
570570
return (*this)(args);
571-
};
571+
}
572572

573573
template<typename... Args>
574574
Expr operator()(const std::vector<Expr> &args) const {
575575
return buffer_accessor(Buffer<>(*this), args);
576-
};
576+
}
577577
// @}
578578

579579
/** Copy to the GPU, using the device API that is the default for the given Target. */

src/CMakeLists.txt

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ add_custom_command(OUTPUT "${Halide_BINARY_DIR}/include/Halide.h"
353353
DEPENDS build_halide_h "${LICENSE_PATH}" ${HEADER_FILES}
354354
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
355355
VERBATIM)
356-
add_custom_target(HalideIncludes ALL
357-
DEPENDS "${Halide_BINARY_DIR}/include/Halide.h")
356+
add_custom_target(HalideIncludes ALL DEPENDS "${Halide_BINARY_DIR}/include/Halide.h")
358357

359358
##
360359
# Define the Halide library target.
@@ -369,10 +368,8 @@ add_library(Halide::Halide ALIAS Halide)
369368

370369
target_link_libraries(Halide PRIVATE Halide::LLVM)
371370
target_link_libraries(Halide PUBLIC Halide::LanguageOptions)
372-
target_compile_definitions(Halide
373-
PRIVATE
374-
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:Halide_STATIC_DEFINE>
375-
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:WITH_INTROSPECTION>)
371+
target_compile_definitions(Halide PRIVATE $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:Halide_STATIC_DEFINE>)
372+
target_compile_features(Halide PUBLIC cxx_std_11)
376373

377374
include(TargetExportScript)
378375
## TODO: implement something similar for Windows/link.exe
@@ -386,57 +383,94 @@ set_target_properties(Halide PROPERTIES
386383
VERSION ${Halide_VERSION}
387384
SOVERSION ${Halide_VERSION_MAJOR})
388385

386+
target_include_directories(Halide INTERFACE "$<BUILD_INTERFACE:${Halide_BINARY_DIR}/include>")
389387
add_dependencies(Halide HalideIncludes)
390388

389+
option(Halide_WITH_INTROSPECTION "Enable use of debugging symbols for default Func, Var, etc. names" ON)
390+
if (Halide_WITH_INTROSPECTION)
391+
target_compile_definitions(Halide PRIVATE WITH_INTROSPECTION)
392+
endif ()
393+
391394
if (TARGET wabt-obj)
392395
target_link_libraries(Halide PRIVATE wabt-obj)
393396
target_compile_definitions(Halide PRIVATE WITH_WABT)
394397
endif ()
395398

396-
##
397-
# Include paths for libHalide
398-
##
399-
400-
set(Halide_INCLUDE_PATH "$<BUILD_INTERFACE:${Halide_BINARY_DIR}/include>")
401-
target_include_directories(Halide INTERFACE ${Halide_INCLUDE_PATH})
402-
403399
##
404400
# Set compiler options for libHalide
405401
##
406402

407-
target_compile_options(Halide
408-
PRIVATE
409-
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall>
410-
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-function>
411-
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wcast-qual>
412-
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wignored-qualifiers>
403+
target_compile_options(
404+
Halide
405+
PRIVATE
406+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall>
407+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wcast-qual>
408+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wignored-qualifiers>
413409

414-
$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-Woverloaded-virtual>
415-
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wsuggest-override>
416-
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-override>
417-
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-destructor-override>
410+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-c++98-compat-pedantic>
411+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-c++98-compat>
412+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-cast-align>
413+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-comma>
414+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-covered-switch-default>
415+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-deprecated-declarations>
416+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-documentation-unknown-command>
417+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-documentation>
418+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-double-promotion>
419+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-exit-time-destructors>
420+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-conversion>
421+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-equal>
422+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-global-constructors>
423+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-implicit-float-conversion>
424+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-implicit-int-conversion>
425+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-implicit-int-float-conversion>
426+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-missing-field-initializers>
427+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-missing-prototypes>
428+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-nonportable-system-include-path>
429+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-old-style-cast>
430+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-reserved-id-macro> # can't have an underscore followed by a capital letter
431+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-return-std-move-in-c++11>
432+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow-field-in-constructor>
433+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow-field>
434+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow>
435+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shorten-64-to-32>
436+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-sign-conversion>
437+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-switch-enum>
438+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-undef>
439+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-undefined-func-template>
440+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-function>
441+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-macros>
442+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-member-function>
443+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-parameter>
444+
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-template>
418445

419-
$<$<CXX_COMPILER_ID:MSVC>:/W3>
420-
$<$<CXX_COMPILER_ID:MSVC>:/wd4018> # disable "signed/unsigned mismatch"
421-
$<$<CXX_COMPILER_ID:MSVC>:/wd4503> # disable "decorated name length exceeded, name was truncated"
422-
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # disable "conversion from 'size_t' to 'int', possible loss of data"
423-
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # forcing value to bool 'true' or 'false' (performance warning)
424-
$<$<CXX_COMPILER_ID:MSVC>:/wd4244> # 4244: conversion, possible loss of data
425-
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # 4267: conversion, possible loss of data
426-
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # 4800: BOOL -> true or false
427-
$<$<CXX_COMPILER_ID:MSVC>:/wd4996> # 4996: compiler encountered deprecated declaration
446+
$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-Woverloaded-virtual>
447+
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wsuggest-override>
448+
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-override>
449+
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-destructor-override>
428450

429-
# Injected from recent LLVM:
430-
$<$<CXX_COMPILER_ID:MSVC>:/wd4141> # 'inline' used more than once
431-
$<$<CXX_COMPILER_ID:MSVC>:/wd4146> # unary minus applied to unsigned type
432-
$<$<CXX_COMPILER_ID:MSVC>:/wd4291> # No matching operator delete found
451+
$<$<CXX_COMPILER_ID:MSVC>:/W3>
452+
$<$<CXX_COMPILER_ID:MSVC>:/wd4018> # disable "signed/unsigned mismatch"
453+
$<$<CXX_COMPILER_ID:MSVC>:/wd4503> # disable "decorated name length exceeded, name was truncated"
454+
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # disable "conversion from 'size_t' to 'int', possible loss of data"
455+
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # forcing value to bool 'true' or 'false' (performance warning)
456+
$<$<CXX_COMPILER_ID:MSVC>:/wd4244> # 4244: conversion, possible loss of data
457+
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # 4267: conversion, possible loss of data
458+
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # 4800: BOOL -> true or false
459+
$<$<CXX_COMPILER_ID:MSVC>:/wd4996> # 4996: compiler encountered deprecated declaration
433460

434-
# We could expose the /MP flag to all targets, but that might end up saturating the build
435-
# since multiple MSBuild projects might get built in parallel, each of which compiling their
436-
# source files in parallel; the Halide library itself is a "knot" point of the build graph,
437-
# so compiling its files in parallel should not oversubscribe the system
438-
$<$<CXX_COMPILER_ID:MSVC>:/MP>
439-
)
461+
# Injected from recent LLVM:
462+
$<$<CXX_COMPILER_ID:MSVC>:/wd4141> # 'inline' used more than once
463+
$<$<CXX_COMPILER_ID:MSVC>:/wd4146> # unary minus applied to unsigned type
464+
$<$<CXX_COMPILER_ID:MSVC>:/wd4291> # No matching operator delete found
465+
)
466+
467+
if (CMAKE_GENERATOR MATCHES "Visual Studio")
468+
# We could expose the /MP flag to all targets, but that might end up saturating the build
469+
# since multiple MSBuild projects might get built in parallel, each of which compiling their
470+
# source files in parallel; the Halide library itself is a "knot" point of the build graph,
471+
# so compiling its files in parallel should not oversubscribe the system
472+
target_compile_options(Halide PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/MP>)
473+
endif ()
440474

441475
target_compile_definitions(Halide
442476
PRIVATE

src/CodeGen_Hexagon.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ class SloppyUnpredicateLoadsAndStores : public IRMutator {
283283

284284
return Call::make(op->type, Call::if_then_else,
285285
{condition, load, make_zero(op->type)}, Call::Intrinsic);
286-
287-
return load;
288286
} else {
289287
// It's a predicated vector gather. Just scalarize. We'd
290288
// prefer to keep it in a loop, but that would require

src/CodeGen_LLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ using std::vector;
9191

9292
#ifdef WITH_NVPTX
9393
#define InitializeNVPTXTarget() InitializeTarget(NVPTX)
94-
#define InitializeNVPTXAsmParser() InitializeAsmParser(NVPTX)
94+
// #define InitializeNVPTXAsmParser() InitializeAsmParser(NVPTX) // there is no ASM parser for NVPTX
9595
#define InitializeNVPTXAsmPrinter() InitializeAsmPrinter(NVPTX)
9696
#endif
9797

src/IRMatch.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ struct CanProve {
22062206
ty.code = halide_type_uint;
22072207
ty.bits = 1;
22082208
ty.lanes = condition.type().lanes();
2209-
};
2209+
}
22102210
};
22112211

22122212
template<typename A, typename Prover>
@@ -2243,7 +2243,7 @@ struct IsFloat {
22432243
ty.code = halide_type_uint;
22442244
ty.bits = 1;
22452245
ty.lanes = t.lanes();
2246-
};
2246+
}
22472247
};
22482248

22492249
template<typename A>
@@ -2281,7 +2281,7 @@ struct IsInt {
22812281
ty.code = halide_type_uint;
22822282
ty.bits = 1;
22832283
ty.lanes = t.lanes();
2284-
};
2284+
}
22852285
};
22862286

22872287
template<typename A>
@@ -2323,7 +2323,7 @@ struct IsUInt {
23232323
ty.code = halide_type_uint;
23242324
ty.bits = 1;
23252325
ty.lanes = t.lanes();
2326-
};
2326+
}
23272327
};
23282328

23292329
template<typename A>
@@ -2364,7 +2364,7 @@ struct IsScalar {
23642364
ty.code = halide_type_uint;
23652365
ty.bits = 1;
23662366
ty.lanes = t.lanes();
2367-
};
2367+
}
23682368
};
23692369

23702370
template<typename A>
@@ -2399,7 +2399,7 @@ struct IsMaxValue {
23992399
}
24002400
ty.code = halide_type_uint;
24012401
ty.bits = 1;
2402-
};
2402+
}
24032403
};
24042404

24052405
template<typename A>
@@ -2436,7 +2436,7 @@ struct IsMinValue {
24362436
}
24372437
ty.code = halide_type_uint;
24382438
ty.bits = 1;
2439-
};
2439+
}
24402440
};
24412441

24422442
template<typename A>

src/IRVisitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class VariadicVisitor {
160160
ExprRet dispatch_expr(const BaseExprNode *node, Args &&...args) {
161161
if (node == nullptr) {
162162
return ExprRet{};
163-
};
163+
}
164164
switch (node->node_type) {
165165
case IRNodeType::IntImm:
166166
return ((T *)this)->visit((const IntImm *)node, std::forward<Args>(args)...);
@@ -250,7 +250,7 @@ class VariadicVisitor {
250250
StmtRet dispatch_stmt(const BaseStmtNode *node, Args &&...args) {
251251
if (node == nullptr) {
252252
return StmtRet{};
253-
};
253+
}
254254
switch (node->node_type) {
255255
case IRNodeType::IntImm:
256256
case IRNodeType::UIntImm:

src/Introspection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#include "Introspection.h"
22

3+
#if defined(_MSC_VER)
4+
#undef WITH_INTROSPECTION
5+
#elif defined(__has_include)
6+
#if !__has_include(<execinfo.h>)
7+
#undef WITH_INTROSPECTION
8+
#endif
9+
#endif
10+
311
#ifdef WITH_INTROSPECTION
412

513
#include "Debug.h"

src/IntrusivePtr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct IntrusivePtr {
7171
if (p) {
7272
ref_count(p).increment();
7373
}
74-
};
74+
}
7575

7676
void decref(T *p) {
7777
if (p) {

0 commit comments

Comments
 (0)