[SimplifyLibCalls] Mark known arguments with nonnull
Reviewers: efriedma, jdoerfert
Reviewed By: jdoerfert
Subscribers: ychen, rsmith, joerg, aaron.ballman, lebedev.ri, uenoku, jdoerfert, hfinkel, javed.absar, spatel, dmgreen, llvm-commits
Differential Revision: https://reviews.llvm.org/D53342
llvm-svn: 372091
2019-09-17 17:32:52 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2018-04-11 07:32:36 +08:00
|
|
|
; Check if "RtLibUseGOT" works correctly when lib calls are simplified.
|
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
|
|
|
|
@percent_s = constant [4 x i8] c"%s\0A\00"
|
|
|
|
@hello_world = constant [13 x i8] c"hello world\0A\00"
|
|
|
|
declare i32 @printf(i8*, ...)
|
|
|
|
define void @printf_call() {
|
[SimplifyLibCalls] Mark known arguments with nonnull
Reviewers: efriedma, jdoerfert
Reviewed By: jdoerfert
Subscribers: ychen, rsmith, joerg, aaron.ballman, lebedev.ri, uenoku, jdoerfert, hfinkel, javed.absar, spatel, dmgreen, llvm-commits
Differential Revision: https://reviews.llvm.org/D53342
llvm-svn: 372091
2019-09-17 17:32:52 +08:00
|
|
|
; CHECK-LABEL: @printf_call(
|
|
|
|
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i64 0, i64 0))
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
;
|
2018-04-11 07:32:36 +08:00
|
|
|
%fmt = getelementptr [4 x i8], [4 x i8]* @percent_s, i32 0, i32 0
|
|
|
|
%str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
|
|
|
|
call i32 (i8*, ...) @printf(i8* %fmt, i8* %str)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2019-07-08 23:57:56 +08:00
|
|
|
; CHECK: Function Attrs: nofree nounwind nonlazybind
|
[BuildLibCalls] Add noundef to standard I/O functions
This patch adds noundef to return value and arguments of standard I/O functions.
With this patch, passing undef or poison to the functions becomes undefined
behavior in LLVM IR. Since undef/poison is lowered from operations having UB in C/C++,
passing undef to them was already UB in source.
With this patch, the functions cannot return undef or poison anymore as well.
According to C17 standard, ungetc/ungetwc/fgetpos/ftell can generate unspecified
value; 3.19.3 says unspecified value is a valid value of the relevant type,
and using unspecified value is unspecified behavior, which is not UB, so it
cannot be undef (using undef is UB when e.g. it is used at branch condition).
— The value of the file position indicator after a successful call to the ungetc function for a text stream, or the ungetwc function for any stream, until all pushed-back characters are read or discarded (7.21.7.10, 7.29.3.10).
— The details of the value stored by the fgetpos function (7.21.9.1).
— The details of the value returned by the ftell function for a text stream (7.21.9.4).
In the long run, most of the functions listed in BuildLibCalls should have noundefs; to remove redundant diffs which will anyway disappear in the future, I added noundef to a few more non-I/O functions as well.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85345
2020-08-10 09:57:18 +08:00
|
|
|
; CHECK-NEXT: declare noundef i32 @puts(i8* nocapture noundef readonly)
|
2018-04-11 07:32:36 +08:00
|
|
|
|
|
|
|
!llvm.module.flags = !{!0}
|
|
|
|
!0 = !{i32 7, !"RtLibUseGOT", i32 1}
|