Skip to content

Commit ac7f7c1

Browse files
Merge branch 'bugfix/fneg'. Close #197.
2 parents 1d98c65 + 6f71990 commit ac7f7c1

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

frontend/llvm/src/import/function.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ void FunctionImporter::translate_instruction(
375375
} else if (llvm::isa< llvm::SwitchInst >(inst)) {
376376
// The preprocessor should use the -lowerswitch pass
377377
throw ImportError("llvm switch instructions are not supported");
378+
} else if (inst->getOpcode() == llvm::Instruction::FNeg) {
379+
auto* binary_inst =
380+
llvm::BinaryOperator::Create(llvm::BinaryOperator::FMul,
381+
llvm::ConstantFP::get(inst->getOperand(0)
382+
->getType(),
383+
-1.0),
384+
inst->getOperand(0));
385+
inst->replaceAllUsesWith(binary_inst);
386+
binary_inst->setDebugLoc(inst->getDebugLoc());
387+
this->translate_binary_operator(bb_translation, binary_inst);
378388
} else {
379389
std::ostringstream buf;
380390
buf << "unsupported llvm instruction: " << inst->getOpcodeName() << " [1]";
@@ -2023,6 +2033,10 @@ FunctionImporter::TypeHint FunctionImporter::infer_type_hint_use(
20232033
return {}; // no hint
20242034
} else if (llvm::isa< llvm::ResumeInst >(user)) {
20252035
return {}; // no hint
2036+
} else if (llvm::isa< llvm::Instruction >(user) &&
2037+
llvm::cast< llvm::Instruction >(user)->getOpcode() ==
2038+
llvm::Instruction::FNeg) {
2039+
return {}; // no hint
20262040
} else if (llvm::isa< llvm::SelectInst >(user)) {
20272041
// The preprocessor should use the -lower-select pass
20282042
throw ImportError("llvm select instructions are not supported");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
int main() {
3+
float y = 10.0F;
4+
return (int)(-y);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
int main() {
3+
double y = 10.0F;
4+
return (int)(-y);
5+
}

0 commit comments

Comments
 (0)