diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -1487,7 +1487,7 @@ } const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) { - StringRef Str = unwrap(DType)->getName(); + StringRef Str = unwrapDI(DType)->getName(); *Length = Str.size(); return Str.data(); } diff --git a/llvm/test/Bindings/llvm-c/di-type-get-name.ll b/llvm/test/Bindings/llvm-c/di-type-get-name.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Bindings/llvm-c/di-type-get-name.ll @@ -0,0 +1,2 @@ +; RUN: llvm-c-test --di-type-get-name < /dev/null +; This used to trigger an assertion diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c --- a/llvm/tools/llvm-c-test/debuginfo.c +++ b/llvm/tools/llvm-c-test/debuginfo.c @@ -229,6 +229,30 @@ LLVMDisposeDIBuilder(Builder); LLVMDisposeModule(M); + return 0; +} + +int llvm_di_type_get_name(void) { + LLVMModuleRef M = LLVMModuleCreateWithName("Mod"); + + LLVMDIBuilderRef Builder = LLVMCreateDIBuilder(M); + const char Filename[] = "metadata.c"; + const char Directory[] = "."; + LLVMMetadataRef File = LLVMDIBuilderCreateFile( + Builder, Filename, strlen(Filename), Directory, strlen(Directory)); + const char Name[] = "TestClass"; + LLVMMetadataRef Struct = LLVMDIBuilderCreateStructType( + Builder, File, Name, strlen(Name), File, 42, 64, 0, + LLVMDIFlagObjcClassComplete, NULL, NULL, 0, 0, NULL, NULL, 0); + + size_t Len; + const char *TypeName = LLVMDITypeGetName(Struct, &Len); + assert(Len == strlen(Name)); + assert(strncmp(TypeName, Name, Len) == 0); + (void)TypeName; + + LLVMDisposeDIBuilder(Builder); + LLVMDisposeModule(M); return 0; } diff --git a/llvm/tools/llvm-c-test/llvm-c-test.h b/llvm/tools/llvm-c-test/llvm-c-test.h --- a/llvm/tools/llvm-c-test/llvm-c-test.h +++ b/llvm/tools/llvm-c-test/llvm-c-test.h @@ -38,6 +38,7 @@ // debuginfo.c int llvm_test_dibuilder(void); int llvm_get_di_tag(void); +int llvm_di_type_get_name(void); // metadata.c int llvm_add_named_metadata_operand(void); diff --git a/llvm/tools/llvm-c-test/main.c b/llvm/tools/llvm-c-test/main.c --- a/llvm/tools/llvm-c-test/main.c +++ b/llvm/tools/llvm-c-test/main.c @@ -49,6 +49,8 @@ " Read lines of name, rpn from stdin - print generated module\n\n"); fprintf(stderr, " * --get-di-tag\n"); fprintf(stderr, " Run test for getting MDNode dwarf tag\n"); + fprintf(stderr, " * --di-type-get-name\n"); + fprintf(stderr, " Run test for getting MDNode type name\n"); fprintf(stderr, " * --replace-md-operand\n"); fprintf(stderr, " Run test for replacing MDNode operands\n"); fprintf(stderr, " * --is-a-value-as-metadata\n"); @@ -96,6 +98,8 @@ return llvm_set_metadata(); } else if (argc == 2 && !strcmp(argv[1], "--get-di-tag")) { return llvm_get_di_tag(); + } else if (argc == 2 && !strcmp(argv[1], "--di-type-get-name")) { + return llvm_di_type_get_name(); } else if (argc == 2 && !strcmp(argv[1], "--replace-md-operand")) { return llvm_replace_md_operand(); } else if (argc == 2 && !strcmp(argv[1], "--is-a-value-as-metadata")) {