[PATCH] D154630: [LLVM-C] Use unwrapDI in LLVMDITypeGetName
Tamir Duberstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 6 11:16:12 PDT 2023
tamird updated this revision to Diff 537808.
tamird added a comment.
Add test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154630/new/
https://reviews.llvm.org/D154630
Files:
llvm/lib/IR/DebugInfo.cpp
llvm/tools/llvm-c-test/debuginfo.c
Index: llvm/tools/llvm-c-test/debuginfo.c
===================================================================
--- llvm/tools/llvm-c-test/debuginfo.c
+++ llvm/tools/llvm-c-test/debuginfo.c
@@ -13,9 +13,10 @@
#include "llvm-c-test.h"
#include "llvm-c/DebugInfo.h"
+
+#include <assert.h>
#include <stdio.h>
#include <string.h>
-#include <assert.h>
static LLVMMetadataRef
declare_objc_class(LLVMDIBuilderRef DIB, LLVMMetadataRef File) {
@@ -203,30 +204,32 @@
}
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);
+
+ 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);
- assert(tag1 == 0x13);
- (void)tag1;
+ size_t Len;
+ const char* TypeName = LLVMDITypeGetName(Struct, &Len);
+ assert(Len == strlen(Name));
+ assert(strncmp(TypeName, Name, Len) == 0);
- LLVMDisposeDIBuilder(builder);
- LLVMDisposeModule(m);
+ LLVMDisposeDIBuilder(Builder);
+ LLVMDisposeModule(M);
return 0;
}
Index: llvm/lib/IR/DebugInfo.cpp
===================================================================
--- llvm/lib/IR/DebugInfo.cpp
+++ llvm/lib/IR/DebugInfo.cpp
@@ -1487,7 +1487,7 @@
}
const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
- StringRef Str = unwrap<DIType>(DType)->getName();
+ StringRef Str = unwrapDI<DIType>(DType)->getName();
*Length = Str.size();
return Str.data();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154630.537808.patch
Type: text/x-patch
Size: 2798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230706/23377712/attachment.bin>
More information about the llvm-commits
mailing list