xref: /llvm-project/llvm/test/Transforms/Attributor/IPConstantProp/arg-count-mismatch.ll (revision e31724f1a6e928951a86c9dbe725533a91f3c7da)
19c2074dcSJohannes Doerfert; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2e1dc0f55SNikita Popov; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-annotate-decl-cs  -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
3e1dc0f55SNikita Popov; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
43da7efedSJohannes Doerfert
53da7efedSJohannes Doerfert; The original C source looked like this:
63da7efedSJohannes Doerfert;
73da7efedSJohannes Doerfert;   long long a101, b101, e101;
83da7efedSJohannes Doerfert;   volatile long c101;
93da7efedSJohannes Doerfert;   int d101;
103da7efedSJohannes Doerfert;
113da7efedSJohannes Doerfert;   static inline int bar(p1, p2)
123da7efedSJohannes Doerfert;   {
133da7efedSJohannes Doerfert;       return 0;
143da7efedSJohannes Doerfert;   }
153da7efedSJohannes Doerfert;
163da7efedSJohannes Doerfert;   void foo(unsigned p1)
173da7efedSJohannes Doerfert;   {
183da7efedSJohannes Doerfert;       long long *f = &b101, *g = &e101;
193da7efedSJohannes Doerfert;       c101 = 0;
203da7efedSJohannes Doerfert;       (void)((*f |= a101) - (*g = bar(d101)));
213da7efedSJohannes Doerfert;       c101 = (*f |= a101 &= p1) == d101;
223da7efedSJohannes Doerfert;   }
233da7efedSJohannes Doerfert;
243da7efedSJohannes Doerfert; When compiled with Clang it gives a warning
253da7efedSJohannes Doerfert;   warning: too few arguments in call to 'bar'
263da7efedSJohannes Doerfert;
273da7efedSJohannes Doerfert; This ll reproducer has been reduced to only include tha call.
283da7efedSJohannes Doerfert;
293da7efedSJohannes Doerfert; Note that -lint will report this as UB, but it passes -verify.
303da7efedSJohannes Doerfert
313da7efedSJohannes Doerfert; This test is just to verify that we do not crash/assert due to mismatch in
323da7efedSJohannes Doerfert; argument count between the caller and callee.
333da7efedSJohannes Doerfert
34e1eed6c5SJohannes Doerfert; FIXME we should recognize this as UB and make it an unreachable.
35e1eed6c5SJohannes Doerfert
36c6ac717aSJohannes Doerfertdefine dso_local i16 @foo(i16 %a) {
37732bdb60SJohannes Doerfert; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
38846709b2SNikita Popov; TUNIT-LABEL: define {{[^@]+}}@foo
39846709b2SNikita Popov; TUNIT-SAME: (i16 [[A:%.*]]) #[[ATTR0:[0-9]+]] {
40732bdb60SJohannes Doerfert; TUNIT-NEXT:    ret i16 0
4143d6991cSAntonio Frighetto;
42e1dc0f55SNikita Popov; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
43846709b2SNikita Popov; CGSCC-LABEL: define {{[^@]+}}@foo
44846709b2SNikita Popov; CGSCC-SAME: (i16 [[A:%.*]]) #[[ATTR0:[0-9]+]] {
45369930bcSJohannes Doerfert; CGSCC-NEXT:    [[CALL:%.*]] = call noundef i16 @bar(i16 [[A]]) #[[ATTR2:[0-9]+]]
46846709b2SNikita Popov; CGSCC-NEXT:    ret i16 [[CALL]]
473da7efedSJohannes Doerfert;
48e1dc0f55SNikita Popov  %call = call i16 @bar(i16 %a)
49c6ac717aSJohannes Doerfert  ret i16 %call
503da7efedSJohannes Doerfert}
513da7efedSJohannes Doerfert
523da7efedSJohannes Doerfertdefine internal i16 @bar(i16 %p1, i16 %p2) {
53732bdb60SJohannes Doerfert; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
54732bdb60SJohannes Doerfert; CGSCC-LABEL: define {{[^@]+}}@bar
55732bdb60SJohannes Doerfert; CGSCC-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) #[[ATTR1:[0-9]+]] {
56732bdb60SJohannes Doerfert; CGSCC-NEXT:    ret i16 0
57f3ad8cf0SJohannes Doerfert;
583da7efedSJohannes Doerfert  ret i16 0
593da7efedSJohannes Doerfert}
603da7efedSJohannes Doerfert
611e99fc9dSJohannes Doerfertdefine dso_local i16 @foo2(i16 %a) {
62732bdb60SJohannes Doerfert; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
63846709b2SNikita Popov; TUNIT-LABEL: define {{[^@]+}}@foo2
64846709b2SNikita Popov; TUNIT-SAME: (i16 [[A:%.*]]) #[[ATTR0]] {
65e1dc0f55SNikita Popov; TUNIT-NEXT:    [[CALL:%.*]] = call i16 @bar2(i16 [[A]]) #[[ATTR1:[0-9]+]]
66846709b2SNikita Popov; TUNIT-NEXT:    ret i16 [[CALL]]
6743d6991cSAntonio Frighetto;
68e1dc0f55SNikita Popov; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
69846709b2SNikita Popov; CGSCC-LABEL: define {{[^@]+}}@foo2
70846709b2SNikita Popov; CGSCC-SAME: (i16 [[A:%.*]]) #[[ATTR0]] {
71369930bcSJohannes Doerfert; CGSCC-NEXT:    [[CALL:%.*]] = call i16 @bar2(i16 [[A]]) #[[ATTR2]]
72846709b2SNikita Popov; CGSCC-NEXT:    ret i16 [[CALL]]
731e99fc9dSJohannes Doerfert;
74e1dc0f55SNikita Popov  %call = call i16 @bar2(i16 %a)
751e99fc9dSJohannes Doerfert  ret i16 %call
761e99fc9dSJohannes Doerfert}
771e99fc9dSJohannes Doerfert
781e99fc9dSJohannes Doerfertdefine internal i16 @bar2(i16 %p1, i16 %p2) {
79732bdb60SJohannes Doerfert; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
80732bdb60SJohannes Doerfert; TUNIT-LABEL: define {{[^@]+}}@bar2
81732bdb60SJohannes Doerfert; TUNIT-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) #[[ATTR0]] {
82732bdb60SJohannes Doerfert; TUNIT-NEXT:    [[A:%.*]] = add i16 [[P1]], [[P2]]
83732bdb60SJohannes Doerfert; TUNIT-NEXT:    ret i16 [[A]]
84732bdb60SJohannes Doerfert;
85732bdb60SJohannes Doerfert; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
86732bdb60SJohannes Doerfert; CGSCC-LABEL: define {{[^@]+}}@bar2
87732bdb60SJohannes Doerfert; CGSCC-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) #[[ATTR1]] {
88732bdb60SJohannes Doerfert; CGSCC-NEXT:    [[A:%.*]] = add i16 [[P1]], [[P2]]
89732bdb60SJohannes Doerfert; CGSCC-NEXT:    ret i16 [[A]]
90f3ad8cf0SJohannes Doerfert;
911e99fc9dSJohannes Doerfert  %a = add i16 %p1, %p2
921e99fc9dSJohannes Doerfert  ret i16 %a
931e99fc9dSJohannes Doerfert}
941e99fc9dSJohannes Doerfert
951e99fc9dSJohannes Doerfert
963da7efedSJohannes Doerfert;-------------------------------------------------------------------------------
973da7efedSJohannes Doerfert; Additional tests to verify that we still optimize when having a mismatch
983da7efedSJohannes Doerfert; in argument count due to varargs (as long as all non-variadic arguments have
993da7efedSJohannes Doerfert; been provided),
1003da7efedSJohannes Doerfert
1013da7efedSJohannes Doerfertdefine dso_local i16 @vararg_tests(i16 %a) {
102732bdb60SJohannes Doerfert; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
103846709b2SNikita Popov; TUNIT-LABEL: define {{[^@]+}}@vararg_tests
104846709b2SNikita Popov; TUNIT-SAME: (i16 [[A:%.*]]) #[[ATTR0]] {
105732bdb60SJohannes Doerfert; TUNIT-NEXT:    ret i16 14
106f3ad8cf0SJohannes Doerfert;
107e1dc0f55SNikita Popov; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
108846709b2SNikita Popov; CGSCC-LABEL: define {{[^@]+}}@vararg_tests
109846709b2SNikita Popov; CGSCC-SAME: (i16 [[A:%.*]]) #[[ATTR0]] {
110369930bcSJohannes Doerfert; CGSCC-NEXT:    [[CALL1:%.*]] = call i16 (i16, ...) @vararg_prop(i16 noundef 7, i16 noundef 8, i16 [[A]]) #[[ATTR2]]
111369930bcSJohannes Doerfert; CGSCC-NEXT:    [[CALL2:%.*]] = call i16 @vararg_no_prop(i16 noundef 7) #[[ATTR2]]
112846709b2SNikita Popov; CGSCC-NEXT:    [[ADD:%.*]] = add i16 [[CALL1]], [[CALL2]]
113846709b2SNikita Popov; CGSCC-NEXT:    ret i16 [[ADD]]
1143da7efedSJohannes Doerfert;
1153da7efedSJohannes Doerfert  %call1 = call i16 (i16, ...) @vararg_prop(i16 7, i16 8, i16 %a)
116e1dc0f55SNikita Popov  %call2 = call i16 @vararg_no_prop (i16 7)
1173da7efedSJohannes Doerfert  %add = add i16 %call1, %call2
1183da7efedSJohannes Doerfert  ret i16 %add
1193da7efedSJohannes Doerfert}
1203da7efedSJohannes Doerfert
1213da7efedSJohannes Doerfertdefine internal i16 @vararg_prop(i16 %p1, ...) {
122dbbe9b37SJohannes Doerfert; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
123846709b2SNikita Popov; CGSCC-LABEL: define {{[^@]+}}@vararg_prop
124846709b2SNikita Popov; CGSCC-SAME: (i16 [[P1:%.*]], ...) #[[ATTR1]] {
125846709b2SNikita Popov; CGSCC-NEXT:    ret i16 7
1263ca54f45SJohannes Doerfert;
1273da7efedSJohannes Doerfert  ret i16 %p1
1283da7efedSJohannes Doerfert}
1293da7efedSJohannes Doerfert
1303da7efedSJohannes Doerfertdefine internal i16 @vararg_no_prop(i16 %p1, i16 %p2, ...) {
131732bdb60SJohannes Doerfert; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
132732bdb60SJohannes Doerfert; CGSCC-LABEL: define {{[^@]+}}@vararg_no_prop
133732bdb60SJohannes Doerfert; CGSCC-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]], ...) #[[ATTR1]] {
134732bdb60SJohannes Doerfert; CGSCC-NEXT:    ret i16 7
135f3ad8cf0SJohannes Doerfert;
1363da7efedSJohannes Doerfert  ret i16 %p1
1373da7efedSJohannes Doerfert}
1383da7efedSJohannes Doerfert
1399c2074dcSJohannes Doerfert;.
140732bdb60SJohannes Doerfert; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
141b672c602SJohannes Doerfert; TUNIT: attributes #[[ATTR1]] = { nofree nosync nounwind willreturn memory(none) }
14243d6991cSAntonio Frighetto;.
143e1dc0f55SNikita Popov; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree nosync nounwind willreturn memory(none) }
144dbbe9b37SJohannes Doerfert; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
145*e31724f1SJohannes Doerfert; CGSCC: attributes #[[ATTR2]] = { nofree nosync willreturn }
1469c2074dcSJohannes Doerfert;.
147732bdb60SJohannes Doerfert;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
148732bdb60SJohannes Doerfert; CHECK: {{.*}}
149