Skip to content

Commit e56b479

Browse files
[Hexagon] Bugfix in VarArg lowering: Special case for musl (#157564)
While debugging #145206 I found that a possible cause for the problem is the call to printf, which is variadic. In a musl environment VarArgs are treated like *non* VarArgs. The handling of this special case was bypassed by the commit a4f8551. The reason is that the arguement `TreatAsVarArg` is only set to `true` in an *non* musl env. `TreatAsVarArg` determines the result of `isVarArg()`. The `CCIfArgVarArg` class only checks each individual variable, but not whether `isVarArg()` is true. Without the special case, the unnamed arguments are always passed on the stack, as is standard calling convention. But with musl also unnamed arguments can be passed in registers. Possibly, this fixes #145206.
1 parent 4e3aa76 commit e56b479

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

llvm/lib/Target/Hexagon/HexagonCallingConv.td

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// We cannot use the standard CCIfArgVarArg class here since in Hexagon there
10+
// exists a special case for a musl environment. In a musl environment VarArgs
11+
// are treated like non VarArgs. I.e., in a musl enviroment unnamed arguments
12+
// can also be passed in registers. The CCIfArgVarArg class only checks each
13+
// individual argument, but not whether State.isVarArg() is true. We also have
14+
// to check State.isVarArg() which is determined by the TreatAsVarArg argument.
15+
class CCIfStateVarArgAndArgVarArg<CCAction A>
16+
: CCIf<"State.isVarArg() && ArgFlags.isVarArg()", A>;
17+
918
def CC_HexagonStack: CallingConv<[
1019
CCIfType<[i32,v2i16,v4i8],
1120
CCAssignToStack<4,4>>,
@@ -23,7 +32,7 @@ def CC_Hexagon_Legacy: CallingConv<[
2332

2433
CCIfByVal<
2534
CCPassByVal<8,8>>,
26-
CCIfArgVarArg<
35+
CCIfStateVarArgAndArgVarArg<
2736
CCDelegateTo<CC_HexagonStack>>,
2837

2938
// Pass split values in pairs, allocate odd register if necessary.
@@ -53,7 +62,7 @@ def CC_Hexagon: CallingConv<[
5362

5463
CCIfByVal<
5564
CCPassByVal<8,1>>,
56-
CCIfArgVarArg<
65+
CCIfStateVarArgAndArgVarArg<
5766
CCDelegateTo<CC_HexagonStack>>,
5867

5968
// Pass split values in pairs, allocate odd register if necessary.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: llc -mtriple=hexagon-unknown-linux-musl < %s | FileCheck %s -check-prefix=MUSL
2+
; RUN: llc -mtriple=hexagon-unknown-none-elf < %s | FileCheck %s -check-prefix=NONMUSL
3+
4+
; MUSL-NOT: memw
5+
; NONMUSL: memw
6+
7+
declare i32 @f0(i32 %a0, ...)
8+
9+
define i32 @f1(i32 %a0, i32 %a1) #0 {
10+
b1:
11+
%v7 = call i32 (i32, ...) @f0(i32 %a0, i32 %a1)
12+
ret i32 %v7
13+
}
14+
15+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)