[PATCH] D85345: [BuildLibCalls] Add noundef to standard I/O functions

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 12:31:04 PDT 2020


aqjune created this revision.
aqjune added reviewers: jdoerfert, MaskRay, efriedma, xbolva00, uenoku.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
aqjune requested review of this revision.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85345

Files:
  llvm/lib/Transforms/Utils/BuildLibCalls.cpp
  llvm/test/CodeGen/X86/no-plt-libcalls.ll
  llvm/test/Transforms/InferFunctionAttrs/annotate.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85345.283344.patch
Type: text/x-patch
Size: 27326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/d49cd8e4/attachment.bin>


More information about the llvm-commits mailing list