diff --git a/llvm/test/Bindings/llvm-c/get-md-tag.ll b/llvm/test/Bindings/llvm-c/get-di-tag.ll rename from llvm/test/Bindings/llvm-c/get-md-tag.ll rename to llvm/test/Bindings/llvm-c/get-di-tag.ll 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 @@ -13,9 +13,10 @@ #include "llvm-c-test.h" #include "llvm-c/DebugInfo.h" + +#include #include #include -#include static LLVMMetadataRef declare_objc_class(LLVMDIBuilderRef DIB, LLVMMetadataRef File) { @@ -203,30 +204,30 @@ } int llvm_get_di_tag(void) { - LLVMModuleRef m = LLVMModuleCreateWithName("Mod"); - LLVMContextRef context = LLVMGetModuleContext(m); - - LLVMMetadataRef metas[] = {LLVMMDStringInContext2(context, "foo", 3)}; - LLVMMetadataRef md = LLVMMDNodeInContext2(context, metas, 1); - uint16_t tag0 = LLVMGetDINodeTag(md); - - assert(tag0 == 0); - (void)tag0; - - const char *filename = "metadata.c"; - LLVMDIBuilderRef builder = LLVMCreateDIBuilder(m); - LLVMMetadataRef file = - LLVMDIBuilderCreateFile(builder, filename, strlen(filename), ".", 1); - LLVMMetadataRef decl = LLVMDIBuilderCreateStructType( - builder, file, "TestClass", 9, file, 42, 64, 0, + LLVMModuleRef M = LLVMModuleCreateWithName("Mod"); + LLVMContextRef Context = LLVMGetModuleContext(M); + + const char String[] = "foo"; + LLVMMetadataRef StringMD = + LLVMMDStringInContext2(Context, String, strlen(String)); + LLVMMetadataRef NodeMD = LLVMMDNodeInContext2(Context, &StringMD, 1); + assert(LLVMGetDINodeTag(NodeMD) == 0); + (void)NodeMD; + + 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); - uint16_t tag1 = LLVMGetDINodeTag(decl); + assert(LLVMGetDINodeTag(Struct) == 0x13); + (void)Struct; - assert(tag1 == 0x13); - (void)tag1; - - LLVMDisposeDIBuilder(builder); - LLVMDisposeModule(m); + LLVMDisposeDIBuilder(Builder); + LLVMDisposeModule(M); return 0; } 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 @@ -44,6 +44,9 @@ fprintf(stderr, " Read lines of triple, hex ascii machine code from stdin " "- print disassembly\n\n"); fprintf(stderr, " * --calc\n"); + fprintf( + stderr, + " 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, " * --replace-md-operand\n"); @@ -51,9 +54,6 @@ fprintf(stderr, " * --is-a-value-as-metadata\n"); fprintf(stderr, " Run test for checking if LLVMValueRef is a ValueAsMetadata\n"); - fprintf( - stderr, - " Read lines of name, rpn from stdin - print generated module\n\n"); fprintf(stderr, " * --echo\n"); fprintf(stderr, " Read bitcode file from stdin - print it back out\n\n"); fprintf(stderr, " * --echo --opaque-pointers\n"); diff --git a/llvm/tools/llvm-c-test/metadata.c b/llvm/tools/llvm-c-test/metadata.c --- a/llvm/tools/llvm-c-test/metadata.c +++ b/llvm/tools/llvm-c-test/metadata.c @@ -13,70 +13,88 @@ \*===----------------------------------------------------------------------===*/ #include "llvm-c-test.h" +#include "llvm-c/Types.h" #include #include int llvm_add_named_metadata_operand(void) { - LLVMModuleRef m = LLVMModuleCreateWithName("Mod"); - LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) }; + LLVMModuleRef M = LLVMModuleCreateWithName("Mod"); + LLVMValueRef Int = LLVMConstInt(LLVMInt32Type(), 0, 0); // This used to trigger an assertion - LLVMAddNamedMetadataOperand(m, "name", LLVMMDNode(values, 1)); + LLVMAddNamedMetadataOperand(M, "name", LLVMMDNode(&Int, 1)); - LLVMDisposeModule(m); + LLVMDisposeModule(M); return 0; } int llvm_set_metadata(void) { - LLVMBuilderRef b = LLVMCreateBuilder(); - LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) }; + LLVMBuilderRef Builder = LLVMCreateBuilder(); // This used to trigger an assertion - LLVMValueRef ret = LLVMBuildRetVoid(b); - LLVMSetMetadata(ret, LLVMGetMDKindID("kind", 4), LLVMMDNode(values, 1)); + LLVMValueRef Return = LLVMBuildRetVoid(Builder); - LLVMDisposeBuilder(b); - LLVMDeleteInstruction(ret); + const char Name[] = "kind"; + LLVMValueRef Int = LLVMConstInt(LLVMInt32Type(), 0, 0); + LLVMSetMetadata(Return, LLVMGetMDKindID(Name, strlen(Name)), + LLVMMDNode(&Int, 1)); + + LLVMDisposeBuilder(Builder); + LLVMDeleteInstruction(Return); return 0; } int llvm_replace_md_operand(void) { - LLVMModuleRef m = LLVMModuleCreateWithName("Mod"); - LLVMContextRef context = LLVMGetModuleContext(m); - unsigned int tmp = 0; + LLVMModuleRef M = LLVMModuleCreateWithName("Mod"); + LLVMContextRef Context = LLVMGetModuleContext(M); + + const char String1[] = "foo"; + LLVMMetadataRef String1MD = + LLVMMDStringInContext2(Context, String1, strlen(String1)); + LLVMMetadataRef NodeMD = LLVMMDNodeInContext2(Context, &String1MD, 1); + LLVMValueRef Value = LLVMMetadataAsValue(Context, NodeMD); - LLVMMetadataRef metas[] = {LLVMMDStringInContext2(context, "foo", 3)}; - LLVMValueRef md = - LLVMMetadataAsValue(context, LLVMMDNodeInContext2(context, metas, 1)); + const char String2[] = "bar"; + LLVMMetadataRef String2MD = + LLVMMDStringInContext2(Context, String2, strlen(String2)); + LLVMReplaceMDNodeOperandWith(Value, 0, String2MD); - LLVMReplaceMDNodeOperandWith(md, 0, - LLVMMDStringInContext2(context, "bar", 3)); + LLVMValueRef Operand = LLVMGetOperand(Value, 0); - assert(!strncmp(LLVMGetMDString(LLVMGetOperand(md, 0), &tmp), "bar", 0)); - (void)tmp; + unsigned int Len; + const char *String = LLVMGetMDString(Operand, &Len); + assert(Len == strlen(String2)); + assert(strncmp(String, String2, Len) == 0); + (void)String; - LLVMDisposeModule(m); + LLVMDisposeModule(M); return 0; } int llvm_is_a_value_as_metadata(void) { - LLVMModuleRef m = LLVMModuleCreateWithName("Mod"); - LLVMContextRef context = LLVMGetModuleContext(m); - - LLVMValueRef values[] = {LLVMConstInt(LLVMInt32Type(), 0, 0)}; - LLVMValueRef md = LLVMMDNode(values, 1); - assert(LLVMIsAValueAsMetadata(md) == md); - (void)md; - - LLVMMetadataRef metas[] = {LLVMMDStringInContext2(context, "foo", 3)}; - LLVMValueRef md2 = - LLVMMetadataAsValue(context, LLVMMDNodeInContext2(context, metas, 1)); - assert(LLVMIsAValueAsMetadata(md2) == NULL); - (void)md2; + LLVMModuleRef M = LLVMModuleCreateWithName("Mod"); + LLVMContextRef Context = LLVMGetModuleContext(M); + + { + LLVMValueRef Int = LLVMConstInt(LLVMInt32Type(), 0, 0); + LLVMValueRef NodeMD = LLVMMDNode(&Int, 1); + assert(LLVMIsAValueAsMetadata(NodeMD) == NodeMD); + (void)NodeMD; + } + + { + const char String[] = "foo"; + LLVMMetadataRef StringMD = + LLVMMDStringInContext2(Context, String, strlen(String)); + LLVMMetadataRef NodeMD = LLVMMDNodeInContext2(Context, &StringMD, 1); + LLVMValueRef Value = LLVMMetadataAsValue(Context, NodeMD); + assert(LLVMIsAValueAsMetadata(Value) == NULL); + (void)Value; + } return 0; }