[all-commits] [llvm/llvm-project] ef018c: [BuildLibCalls] Add noundef to standard I/O functions

Juneyoung Lee via All-commits all-commits at lists.llvm.org
Sun Aug 9 18:58:51 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: ef018cb65c98fdb517930b762b3b3a3c0dd4dbdd
      https://github.com/llvm/llvm-project/commit/ef018cb65c98fdb517930b762b3b3a3c0dd4dbdd
  Author: Juneyoung Lee <aqjune at gmail.com>
  Date:   2020-08-10 (Mon, 10 Aug 2020)

  Changed paths:
    M clang/test/CodeGen/PR3589-freestanding-libcalls.c
    M llvm/lib/Transforms/Utils/BuildLibCalls.cpp
    M llvm/test/CodeGen/X86/no-plt-libcalls.ll
    M llvm/test/Transforms/InferFunctionAttrs/annotate.ll

  Log Message:
  -----------
  [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




More information about the All-commits mailing list