Skip to content

Commit 44a056a

Browse files
committed
Move LLVMRustAttribute[Kind] out of LLVMWrapper.h
1 parent 42188c3 commit 44a056a

File tree

3 files changed

+92
-91
lines changed

3 files changed

+92
-91
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub enum DLLStorageClass {
204204
DllExport = 2, // Function to be accessible from DLL.
205205
}
206206

207-
/// Matches LLVMRustAttribute in LLVMWrapper.h
207+
/// Must match the layout of `LLVMRustAttributeKind`.
208208
/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
209209
/// though it is not ABI compatible (since it's a C++ enum)
210210
#[repr(C)]

compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h

-45
Original file line numberDiff line numberDiff line change
@@ -55,51 +55,6 @@ extern "C" void LLVMRustSetLastError(const char *);
5555

5656
enum class LLVMRustResult { Success, Failure };
5757

58-
enum LLVMRustAttribute {
59-
AlwaysInline = 0,
60-
ByVal = 1,
61-
Cold = 2,
62-
InlineHint = 3,
63-
MinSize = 4,
64-
Naked = 5,
65-
NoAlias = 6,
66-
NoCapture = 7,
67-
NoInline = 8,
68-
NonNull = 9,
69-
NoRedZone = 10,
70-
NoReturn = 11,
71-
NoUnwind = 12,
72-
OptimizeForSize = 13,
73-
ReadOnly = 14,
74-
SExt = 15,
75-
StructRet = 16,
76-
UWTable = 17,
77-
ZExt = 18,
78-
InReg = 19,
79-
SanitizeThread = 20,
80-
SanitizeAddress = 21,
81-
SanitizeMemory = 22,
82-
NonLazyBind = 23,
83-
OptimizeNone = 24,
84-
ReadNone = 26,
85-
SanitizeHWAddress = 28,
86-
WillReturn = 29,
87-
StackProtectReq = 30,
88-
StackProtectStrong = 31,
89-
StackProtect = 32,
90-
NoUndef = 33,
91-
SanitizeMemTag = 34,
92-
NoCfCheck = 35,
93-
ShadowCallStack = 36,
94-
AllocSize = 37,
95-
AllocatedPointer = 38,
96-
AllocAlign = 39,
97-
SanitizeSafeStack = 40,
98-
FnRetThunkExtern = 41,
99-
Writable = 42,
100-
DeadOnUnwind = 43,
101-
};
102-
10358
typedef struct OpaqueRustString *RustStringRef;
10459
typedef struct LLVMOpaqueTwine *LLVMTwineRef;
10560
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+91-45
Original file line numberDiff line numberDiff line change
@@ -228,94 +228,140 @@ extern "C" LLVMValueRef LLVMRustInsertPrivateGlobal(LLVMModuleRef M,
228228
GlobalValue::PrivateLinkage, nullptr));
229229
}
230230

231-
static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
231+
// Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`.
232+
enum class LLVMRustAttributeKind {
233+
AlwaysInline = 0,
234+
ByVal = 1,
235+
Cold = 2,
236+
InlineHint = 3,
237+
MinSize = 4,
238+
Naked = 5,
239+
NoAlias = 6,
240+
NoCapture = 7,
241+
NoInline = 8,
242+
NonNull = 9,
243+
NoRedZone = 10,
244+
NoReturn = 11,
245+
NoUnwind = 12,
246+
OptimizeForSize = 13,
247+
ReadOnly = 14,
248+
SExt = 15,
249+
StructRet = 16,
250+
UWTable = 17,
251+
ZExt = 18,
252+
InReg = 19,
253+
SanitizeThread = 20,
254+
SanitizeAddress = 21,
255+
SanitizeMemory = 22,
256+
NonLazyBind = 23,
257+
OptimizeNone = 24,
258+
ReadNone = 26,
259+
SanitizeHWAddress = 28,
260+
WillReturn = 29,
261+
StackProtectReq = 30,
262+
StackProtectStrong = 31,
263+
StackProtect = 32,
264+
NoUndef = 33,
265+
SanitizeMemTag = 34,
266+
NoCfCheck = 35,
267+
ShadowCallStack = 36,
268+
AllocSize = 37,
269+
AllocatedPointer = 38,
270+
AllocAlign = 39,
271+
SanitizeSafeStack = 40,
272+
FnRetThunkExtern = 41,
273+
Writable = 42,
274+
DeadOnUnwind = 43,
275+
};
276+
277+
static Attribute::AttrKind fromRust(LLVMRustAttributeKind Kind) {
232278
switch (Kind) {
233-
case AlwaysInline:
279+
case LLVMRustAttributeKind::AlwaysInline:
234280
return Attribute::AlwaysInline;
235-
case ByVal:
281+
case LLVMRustAttributeKind::ByVal:
236282
return Attribute::ByVal;
237-
case Cold:
283+
case LLVMRustAttributeKind::Cold:
238284
return Attribute::Cold;
239-
case InlineHint:
285+
case LLVMRustAttributeKind::InlineHint:
240286
return Attribute::InlineHint;
241-
case MinSize:
287+
case LLVMRustAttributeKind::MinSize:
242288
return Attribute::MinSize;
243-
case Naked:
289+
case LLVMRustAttributeKind::Naked:
244290
return Attribute::Naked;
245-
case NoAlias:
291+
case LLVMRustAttributeKind::NoAlias:
246292
return Attribute::NoAlias;
247-
case NoCapture:
293+
case LLVMRustAttributeKind::NoCapture:
248294
return Attribute::NoCapture;
249-
case NoCfCheck:
295+
case LLVMRustAttributeKind::NoCfCheck:
250296
return Attribute::NoCfCheck;
251-
case NoInline:
297+
case LLVMRustAttributeKind::NoInline:
252298
return Attribute::NoInline;
253-
case NonNull:
299+
case LLVMRustAttributeKind::NonNull:
254300
return Attribute::NonNull;
255-
case NoRedZone:
301+
case LLVMRustAttributeKind::NoRedZone:
256302
return Attribute::NoRedZone;
257-
case NoReturn:
303+
case LLVMRustAttributeKind::NoReturn:
258304
return Attribute::NoReturn;
259-
case NoUnwind:
305+
case LLVMRustAttributeKind::NoUnwind:
260306
return Attribute::NoUnwind;
261-
case OptimizeForSize:
307+
case LLVMRustAttributeKind::OptimizeForSize:
262308
return Attribute::OptimizeForSize;
263-
case ReadOnly:
309+
case LLVMRustAttributeKind::ReadOnly:
264310
return Attribute::ReadOnly;
265-
case SExt:
311+
case LLVMRustAttributeKind::SExt:
266312
return Attribute::SExt;
267-
case StructRet:
313+
case LLVMRustAttributeKind::StructRet:
268314
return Attribute::StructRet;
269-
case UWTable:
315+
case LLVMRustAttributeKind::UWTable:
270316
return Attribute::UWTable;
271-
case ZExt:
317+
case LLVMRustAttributeKind::ZExt:
272318
return Attribute::ZExt;
273-
case InReg:
319+
case LLVMRustAttributeKind::InReg:
274320
return Attribute::InReg;
275-
case SanitizeThread:
321+
case LLVMRustAttributeKind::SanitizeThread:
276322
return Attribute::SanitizeThread;
277-
case SanitizeAddress:
323+
case LLVMRustAttributeKind::SanitizeAddress:
278324
return Attribute::SanitizeAddress;
279-
case SanitizeMemory:
325+
case LLVMRustAttributeKind::SanitizeMemory:
280326
return Attribute::SanitizeMemory;
281-
case NonLazyBind:
327+
case LLVMRustAttributeKind::NonLazyBind:
282328
return Attribute::NonLazyBind;
283-
case OptimizeNone:
329+
case LLVMRustAttributeKind::OptimizeNone:
284330
return Attribute::OptimizeNone;
285-
case ReadNone:
331+
case LLVMRustAttributeKind::ReadNone:
286332
return Attribute::ReadNone;
287-
case SanitizeHWAddress:
333+
case LLVMRustAttributeKind::SanitizeHWAddress:
288334
return Attribute::SanitizeHWAddress;
289-
case WillReturn:
335+
case LLVMRustAttributeKind::WillReturn:
290336
return Attribute::WillReturn;
291-
case StackProtectReq:
337+
case LLVMRustAttributeKind::StackProtectReq:
292338
return Attribute::StackProtectReq;
293-
case StackProtectStrong:
339+
case LLVMRustAttributeKind::StackProtectStrong:
294340
return Attribute::StackProtectStrong;
295-
case StackProtect:
341+
case LLVMRustAttributeKind::StackProtect:
296342
return Attribute::StackProtect;
297-
case NoUndef:
343+
case LLVMRustAttributeKind::NoUndef:
298344
return Attribute::NoUndef;
299-
case SanitizeMemTag:
345+
case LLVMRustAttributeKind::SanitizeMemTag:
300346
return Attribute::SanitizeMemTag;
301-
case ShadowCallStack:
347+
case LLVMRustAttributeKind::ShadowCallStack:
302348
return Attribute::ShadowCallStack;
303-
case AllocSize:
349+
case LLVMRustAttributeKind::AllocSize:
304350
return Attribute::AllocSize;
305-
case AllocatedPointer:
351+
case LLVMRustAttributeKind::AllocatedPointer:
306352
return Attribute::AllocatedPointer;
307-
case AllocAlign:
353+
case LLVMRustAttributeKind::AllocAlign:
308354
return Attribute::AllocAlign;
309-
case SanitizeSafeStack:
355+
case LLVMRustAttributeKind::SanitizeSafeStack:
310356
return Attribute::SafeStack;
311-
case FnRetThunkExtern:
357+
case LLVMRustAttributeKind::FnRetThunkExtern:
312358
return Attribute::FnRetThunkExtern;
313-
case Writable:
359+
case LLVMRustAttributeKind::Writable:
314360
return Attribute::Writable;
315-
case DeadOnUnwind:
361+
case LLVMRustAttributeKind::DeadOnUnwind:
316362
return Attribute::DeadOnUnwind;
317363
}
318-
report_fatal_error("bad AttributeKind");
364+
report_fatal_error("bad LLVMRustAttributeKind");
319365
}
320366

321367
template <typename T>
@@ -345,7 +391,7 @@ extern "C" void LLVMRustAddCallSiteAttributes(LLVMValueRef Instr,
345391
}
346392

347393
extern "C" LLVMAttributeRef
348-
LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttribute RustAttr) {
394+
LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) {
349395
return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr)));
350396
}
351397

0 commit comments

Comments
 (0)