Skip to content

Commit cc4e5d7

Browse files
dylanmckaydylanmckay
authored andcommitted
[AVR] Fix indirect calls to function pointers
Patch by Carl Peto. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307888 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 78a80d5 commit cc4e5d7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/Target/AVR/AVRMCInstLower.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,22 @@ MCOperand AVRMCInstLower::lowerSymbolOperand(const MachineOperand &MO,
3737
Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
3838
}
3939

40+
bool IsFunction = MO.isGlobal() && isa<Function>(MO.getGlobal());
41+
4042
if (TF & AVRII::MO_LO) {
41-
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_LO8, Expr, IsNegated, Ctx);
43+
if (IsFunction) {
44+
// N.B. Should we use _GS fixups here to cope with >128k progmem?
45+
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_PM_LO8, Expr, IsNegated, Ctx);
46+
} else {
47+
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_LO8, Expr, IsNegated, Ctx);
48+
}
4249
} else if (TF & AVRII::MO_HI) {
43-
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_HI8, Expr, IsNegated, Ctx);
50+
if (IsFunction) {
51+
// N.B. Should we use _GS fixups here to cope with >128k progmem?
52+
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_PM_HI8, Expr, IsNegated, Ctx);
53+
} else {
54+
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_HI8, Expr, IsNegated, Ctx);
55+
}
4456
} else if (TF != 0) {
4557
llvm_unreachable("Unknown target flag on symbol operand");
4658
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: llc -mattr=lpm,lpmw < %s -march=avr | FileCheck %s
2+
3+
declare void @callback(i16 zeroext)
4+
5+
; CHECK-LABEL: foo
6+
define void @foo() {
7+
entry:
8+
; CHECK: ldi r{{[0-9]+}}, pm_lo8(callback)
9+
; CHECK-NEXT: ldi r{{[0-9]+}}, pm_hi8(callback)
10+
call void @bar(i8 zeroext undef, void (i16)* @callback)
11+
ret void
12+
}
13+
14+
declare void @bar(i8 zeroext, void (i16)*)
15+

0 commit comments

Comments
 (0)