diff --git a/projects/hip/include/hip/hcc_detail/hiprtc.h b/projects/hip/include/hip/hcc_detail/hiprtc.h index d4174e4ce1..26d3129dbc 100644 --- a/projects/hip/include/hip/hcc_detail/hiprtc.h +++ b/projects/hip/include/hip/hcc_detail/hiprtc.h @@ -84,7 +84,7 @@ hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, std::size_t* codeSizeRet); namespace hip_impl { - std::string demangle(const char* mangled_expression); + char* demangle(const char* mangled_expression); } #if defined(HIPRTC_GET_TYPE_NAME) @@ -102,10 +102,11 @@ namespace hip_impl { if (!result) return HIPRTC_ERROR_INVALID_INPUT; - *result = hip_impl::demangle(typeid(T).name()); - + char * res= hip_impl::demangle(typeid(T).name()); + result->assign(res == nullptr ? "" : res); + std::free(res); return (result->empty()) ? HIPRTC_ERROR_INTERNAL_ERROR : HIPRTC_SUCCESS; } #endif -#endif \ No newline at end of file +#endif diff --git a/projects/hip/src/hiprtc.cpp b/projects/hip/src/hiprtc.cpp index aadf48c3ed..f3288a3bcb 100644 --- a/projects/hip/src/hiprtc.cpp +++ b/projects/hip/src/hiprtc.cpp @@ -143,7 +143,9 @@ struct _hiprtcProgram { { using namespace std; - name = hip_impl::demangle(name.c_str()); + char* demangled = hip_impl::demangle(name.c_str()); + name.assign(demangled == nullptr ? "" : demangled); + free(demangled); if (name.empty()) return name; @@ -392,18 +394,16 @@ namespace namespace hip_impl { - inline - std::string demangle(const char* x) + char* demangle(const char* x) { - if (!x) return {}; + if (!x) return nullptr; int s{}; - std::unique_ptr tmp{ - abi::__cxa_demangle(x, nullptr, nullptr, &s), std::free}; + char* tmp = abi::__cxa_demangle(x, nullptr, nullptr, &s); - if (s != 0) return {}; + if (s != 0) return nullptr; - return tmp.get(); + return tmp; } } // Namespace hip_impl. @@ -598,4 +598,4 @@ hiprtcResult hiprtcGetCodeSize(hiprtcProgram p, std::size_t* sz) *sz = p->elf.size(); return HIPRTC_SUCCESS; -} \ No newline at end of file +}