Skip to content

Commit 2c16e24

Browse files
committed
Use C type when passing value to LLVM pass
Previously the C type LLVMRelocMode (available as RelocMode in Rust) was passed as is to the function. However createTargetMachine expects a Reloc::Model, which is an enum just one value short. Additionally, the function was marked as requiring Reloc::Model in the C code, but RelocMode on the Rust-side. We now use the correct C type LLVMRelocMode and convert it to an Optional<Reloc::Model> as expected by the createTargetMachine call the same the original LLVMCreateTargetMachine function does. See https://github.com/llvm-mirror/llvm/blob/c9b262bfbd5b9fb6f10749dba1465569f39bd625/lib/Target/TargetMachineC.cpp#L104-L121 This was found by @eddyb.
1 parent 079db4f commit 2c16e24

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/rustllvm/PassWrapper.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,35 @@ LLVMRustCreateTargetMachine(const char *triple,
167167
const char *cpu,
168168
const char *feature,
169169
CodeModel::Model CM,
170-
Reloc::Model RM,
170+
LLVMRelocMode Reloc,
171171
CodeGenOpt::Level OptLevel,
172172
bool UseSoftFloat,
173173
bool PositionIndependentExecutable,
174174
bool FunctionSections,
175175
bool DataSections) {
176+
177+
#if LLVM_VERSION_MINOR <= 8
178+
Reloc::Model RM;
179+
#else
180+
Optional<Reloc::Model> RM;
181+
#endif
182+
switch (Reloc){
183+
case LLVMRelocStatic:
184+
RM = Reloc::Static;
185+
break;
186+
case LLVMRelocPIC:
187+
RM = Reloc::PIC_;
188+
break;
189+
case LLVMRelocDynamicNoPic:
190+
RM = Reloc::DynamicNoPIC;
191+
break;
192+
default:
193+
#if LLVM_VERSION_MINOR <= 8
194+
RM = Reloc::Default;
195+
#endif
196+
break;
197+
}
198+
176199
std::string Error;
177200
Triple Trip(Triple::normalize(triple));
178201
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Trip.getTriple(),

0 commit comments

Comments
 (0)