Skip to content

Commit

Permalink
Emit prototypes for destructor functions in C Backend (halide#7296)
Browse files Browse the repository at this point in the history
We gathered up the destructors, but only emitted the prototypes if there was at least one non-C++ function declaration needed -- so if you built with cpp_name_mangling enabled, you might omit the right prototype. Fixed and added the right flag to a Generator test to tickle this behavior.
  • Loading branch information
steven-johnson authored and ardier committed Mar 3, 2024
1 parent 20ffb9e commit fd0c6f2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ $(FILTERS_DIR)/autograd_grad.a: $(BIN_DIR)/autograd.generator $(BIN_MULLAPUDI201
# all have the form nested_externs_*).
$(FILTERS_DIR)/nested_externs_%.a: $(BIN_DIR)/nested_externs.generator
@mkdir -p $(@D)
$(CURDIR)/$< -g nested_externs_$* $(GEN_AOT_OUTPUTS) -o $(CURDIR)/$(FILTERS_DIR) target=$(TARGET)-no_runtime
$(CURDIR)/$< -g nested_externs_$* $(GEN_AOT_OUTPUTS) -o $(CURDIR)/$(FILTERS_DIR) target=$(TARGET)-no_runtime-c_plus_plus_name_mangling

# Similarly, gpu_multi needs two different kernels to test compilation caching.
# Also requies user-context.
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGen_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ class ExternCallPrototypes : public IRGraphVisitor {
}

bool has_c_declarations() const {
return !c_externs.empty();
return !c_externs.empty() || !destructors.empty();
}

bool has_c_plus_plus_declarations() const {
Expand Down
2 changes: 1 addition & 1 deletion test/generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ _add_halide_aot_tests(multitarget
add_halide_generator(nested_externs.generator SOURCES nested_externs_generator.cpp)
set(NESTED_EXTERNS_LIBS nested_externs_root nested_externs_inner nested_externs_combine nested_externs_leaf)
foreach (LIB IN LISTS NESTED_EXTERNS_LIBS)
_add_halide_libraries(${LIB} FROM nested_externs.generator GENERATOR_NAME ${LIB})
_add_halide_libraries(${LIB} FROM nested_externs.generator GENERATOR_NAME ${LIB} FEATURES c_plus_plus_name_mangling)
endforeach ()
_add_halide_aot_tests(nested_externs
HALIDE_LIBRARIES ${NESTED_EXTERNS_LIBS})
Expand Down

0 comments on commit fd0c6f2

Please sign in to comment.