xref: /llvm-project/llvm/test/Transforms/SCCP/arg-count-mismatch.ll (revision 16bb8c16aab32e2ee623a2b64d976548be247180)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
2; RUN: opt < %s -passes=ipsccp -S -o - | FileCheck %s
3
4; The original C source looked like this:
5;
6;   long long a101, b101, e101;
7;   volatile long c101;
8;   int d101;
9;
10;   static inline int bar(p1, p2)
11;   {
12;       return 0;
13;   }
14;
15;   void foo(unsigned p1)
16;   {
17;       long long *f = &b101, *g = &e101;
18;       c101 = 0;
19;       (void)((*f |= a101) - (*g = bar(d101)));
20;       c101 = (*f |= a101 &= p1) == d101;
21;   }
22;
23; When compiled with Clang it gives a warning
24;   warning: too few arguments in call to 'bar'
25;
26; This ll reproducer has been reduced to only include tha call.
27;
28; Note that -lint will report this as UB, but it passes -verify.
29
30; This test is just to verify that we do not crash/assert due to mismatch in
31; argument count between the caller and callee.
32
33define dso_local void @foo(i16 %a) {
34; CHECK-LABEL: define {{[^@]+}}@foo
35; CHECK-SAME: (i16 [[A:%.*]]) {
36; CHECK-NEXT:    [[CALL:%.*]] = call i16 @bar(i16 [[A]])
37; CHECK-NEXT:    ret void
38;
39  %call = call i16 @bar(i16 %a)
40  ret void
41}
42
43define internal i16 @bar(i16 %p1, i16 %p2) {
44; CHECK-LABEL: define {{[^@]+}}@bar
45; CHECK-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) {
46; CHECK-NEXT:    ret i16 0
47;
48  ret i16 0
49}
50
51;-------------------------------------------------------------------------------
52; Additional tests to verify that we still optimize when having a mismatch
53; in argument count due to varargs (as long as all non-variadic arguments have
54; been provided),
55
56define internal i16 @vararg_prop(i16 %p1, ...) {
57; CHECK-LABEL: define {{[^@]+}}@vararg_prop
58; CHECK-SAME: (i16 [[P1:%.*]], ...) {
59; CHECK-NEXT:    ret i16 poison
60;
61  ret i16 %p1
62}
63
64define dso_local i16 @vararg_tests(i16 %a) {
65; CHECK-LABEL: define {{[^@]+}}@vararg_tests
66; CHECK-SAME: (i16 [[A:%.*]]) {
67; CHECK-NEXT:    [[CALL1:%.*]] = call i16 (i16, ...) @vararg_prop(i16 7, i16 8, i16 [[A]])
68; CHECK-NEXT:    [[CALL2:%.*]] = call i16 @vararg_no_prop(i16 7)
69; CHECK-NEXT:    [[ADD:%.*]] = add i16 7, [[CALL2]]
70; CHECK-NEXT:    ret i16 [[ADD]]
71;
72  %call1 = call i16 (i16, ...) @vararg_prop(i16 7, i16 8, i16 %a)
73  %call2 = call i16 @vararg_no_prop (i16 7)
74  %add = add i16 %call1, %call2
75  ret i16 %add
76}
77
78define internal i16 @vararg_no_prop(i16 %p1, i16 %p2, ...) {
79; CHECK-LABEL: define {{[^@]+}}@vararg_no_prop
80; CHECK-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]], ...) {
81; CHECK-NEXT:    ret i16 [[P1]]
82;
83  ret i16 %p1
84}
85
86