Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -1496,14 +1496,14 @@ * * @see llvm::Value::getName() */ -const char *LLVMGetValueName(LLVMValueRef Val); +const char *LLVMValueGetName(LLVMValueRef Val, size_t *Length); /** * Set the string name of a value. * * @see llvm::Value::setName() */ -void LLVMSetValueName(LLVMValueRef Val, const char *Name); +void LLVMValueSetName(LLVMValueRef Val, const char *Name, size_t NameLen); /** * Dump a representation of a value to stderr. @@ -1555,6 +1555,11 @@ LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val); LLVMValueRef LLVMIsAMDString(LLVMValueRef Val); +/** Deprecated: Use LLVMValueGetName instead. */ +const char *LLVMGetValueName(LLVMValueRef Val); +/** Deprecated: Use LLVMValueSetName instead. */ +void LLVMSetValueName(LLVMValueRef Val, const char *Name); + /** * @} */ Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -795,6 +795,16 @@ } } +const char *LLVMValueGetName(LLVMValueRef Val, size_t *Length) { + auto *V = unwrap(Val); + *Length = V->getName().size(); + return V->getName().data(); +} + +void LLVMValueSetName(LLVMValueRef Val, const char *Name, size_t NameLen) { + unwrap(Val)->setName(StringRef(Name, NameLen)); +} + const char *LLVMGetValueName(LLVMValueRef Val) { return unwrap(Val)->getName().data(); } Index: tools/llvm-c-test/echo.cpp =================================================================== --- tools/llvm-c-test/echo.cpp +++ tools/llvm-c-test/echo.cpp @@ -174,8 +174,9 @@ LLVMValueRef SrcNext = nullptr; LLVMValueRef DstNext = nullptr; while (true) { - const char *Name = LLVMGetValueName(SrcCur); - LLVMSetValueName(DstCur, Name); + size_t NameLen; + const char *Name = LLVMValueGetName(SrcCur, &NameLen); + LLVMValueSetName(DstCur, Name, NameLen); VMap[SrcCur] = DstCur; @@ -232,7 +233,8 @@ // Maybe it is a symbol if (LLVMIsAGlobalValue(Cst)) { - const char *Name = LLVMGetValueName(Cst); + size_t NameLen; + const char *Name = LLVMValueGetName(Cst, &NameLen); // Try function if (LLVMIsAFunction(Cst)) { @@ -402,7 +404,8 @@ if (!LLVMIsAInstruction(Src)) report_fatal_error("Expected an instruction"); - const char *Name = LLVMGetValueName(Src); + size_t NameLen; + const char *Name = LLVMValueGetName(Src, &NameLen); // Check if this is something we already computed. { @@ -734,7 +737,8 @@ report_fatal_error("Basic block is not a basic block"); const char *Name = LLVMGetBasicBlockName(Src); - const char *VName = LLVMGetValueName(V); + size_t NameLen; + const char *VName = LLVMValueGetName(V, &NameLen); if (Name != VName) report_fatal_error("Basic block name mismatch"); @@ -830,7 +834,8 @@ } while (true) { - const char *Name = LLVMGetValueName(Cur); + size_t NameLen; + const char *Name = LLVMValueGetName(Cur, &NameLen); if (LLVMGetNamedGlobal(M, Name)) report_fatal_error("GlobalVariable already cloned"); LLVMAddGlobal(M, LLVMGetElementType(TypeCloner(M).Clone(Cur)), Name); @@ -863,7 +868,8 @@ Cur = Begin; Next = nullptr; while (true) { - const char *Name = LLVMGetValueName(Cur); + size_t NameLen; + const char *Name = LLVMValueGetName(Cur, &NameLen); if (LLVMGetNamedFunction(M, Name)) report_fatal_error("Function already cloned"); auto Ty = LLVMGetElementType(TypeCloner(M).Clone(Cur)); @@ -909,7 +915,8 @@ } while (true) { - const char *Name = LLVMGetValueName(Cur); + size_t NameLen; + const char *Name = LLVMValueGetName(Cur, &NameLen); LLVMValueRef G = LLVMGetNamedGlobal(M, Name); if (!G) report_fatal_error("GlobalVariable must have been declared already"); @@ -952,13 +959,16 @@ Cur = Begin; Next = nullptr; while (true) { - const char *Name = LLVMGetValueName(Cur); + size_t NameLen; + const char *Name = LLVMValueGetName(Cur, &NameLen); LLVMValueRef Fun = LLVMGetNamedFunction(M, Name); if (!Fun) report_fatal_error("Function must have been declared already"); if (LLVMHasPersonalityFn(Cur)) { - const char *FName = LLVMGetValueName(LLVMGetPersonalityFn(Cur)); + size_t FNameLen; + const char *FName = LLVMValueGetName(LLVMGetPersonalityFn(Cur), + &FNameLen); LLVMValueRef P = LLVMGetNamedFunction(M, FName); if (!P) report_fatal_error("Could not find personality function");