Skip to content

Commit 528f6f7

Browse files
lernoarsenm
authored andcommitted
Add type attributes to LLVM C API
The LLVM C API is missing type attributes as is needed by attributes such as sret and byval. This patch adds three missing wrapper functions. Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=48249 https://reviews.llvm.org/D97763
1 parent 4bd2bfb commit 528f6f7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

llvm/include/llvm-c/Core.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,17 @@ unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
604604
*/
605605
uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
606606

607+
/**
608+
* Create a type attribute
609+
*/
610+
LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
611+
LLVMTypeRef type_ref);
612+
613+
/**
614+
* Get the type attribute's value.
615+
*/
616+
LLVMTypeRef LLVMGetTypeAttributeValue(LLVMAttributeRef A);
617+
607618
/**
608619
* Create a string attribute.
609620
*/
@@ -626,6 +637,7 @@ const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
626637
*/
627638
LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
628639
LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
640+
LLVMBool LLVMIsTypeAttribute(LLVMAttributeRef A);
629641

630642
/**
631643
* Obtain a Type from a context by its registered name.

llvm/lib/IR/Core.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A) {
164164
return Attr.getValueAsInt();
165165
}
166166

167+
LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
168+
LLVMTypeRef type_ref) {
169+
auto &Ctx = *unwrap(C);
170+
auto AttrKind = (Attribute::AttrKind)KindID;
171+
return wrap(Attribute::get(Ctx, AttrKind, unwrap(type_ref)));
172+
}
173+
174+
LLVMTypeRef LLVMGetTypeAttributeValue(LLVMAttributeRef A) {
175+
auto Attr = unwrap(A);
176+
return wrap(Attr.getValueAsType());
177+
}
178+
167179
LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
168180
const char *K, unsigned KLength,
169181
const char *V, unsigned VLength) {
@@ -194,6 +206,10 @@ LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A) {
194206
return unwrap(A).isStringAttribute();
195207
}
196208

209+
LLVMBool LLVMIsTypeAttribute(LLVMAttributeRef A) {
210+
return unwrap(A).isTypeAttribute();
211+
}
212+
197213
char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
198214
std::string MsgStorage;
199215
raw_string_ostream Stream(MsgStorage);

0 commit comments

Comments
 (0)