From 3c1d87e2f18b58d6433d656a4f0558b57eb26476 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Thu, 19 Jan 2023 12:17:18 -0800 Subject: [PATCH] Emit prototypes for destructor functions in C Backend 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. --- Makefile | 2 +- src/CodeGen_C.cpp | 2 +- test/generator/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ac2ed9121f08..c9b179a28da0 100644 --- a/Makefile +++ b/Makefile @@ -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. diff --git a/src/CodeGen_C.cpp b/src/CodeGen_C.cpp index bc1b1770f8eb..f91aa37d2a93 100644 --- a/src/CodeGen_C.cpp +++ b/src/CodeGen_C.cpp @@ -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 { diff --git a/test/generator/CMakeLists.txt b/test/generator/CMakeLists.txt index c1ba74cda760..cbf6ca5e3564 100644 --- a/test/generator/CMakeLists.txt +++ b/test/generator/CMakeLists.txt @@ -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})