2010-03-06 06:25:30 +08:00
|
|
|
//===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-03-06 06:25:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements some functions that will create standard C libcalls.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Transforms/Utils/BuildLibCalls.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2016-04-28 03:04:40 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2015-11-25 02:57:06 +08:00
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/IRBuilder.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2019-07-08 23:57:56 +08:00
|
|
|
#include "llvm/Analysis/MemoryBuiltins.h"
|
2010-03-06 06:25:30 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2016-04-28 03:04:40 +08:00
|
|
|
#define DEBUG_TYPE "build-libcalls"
|
|
|
|
|
|
|
|
//- Infer Attributes ---------------------------------------------------------//
|
|
|
|
|
|
|
|
STATISTIC(NumReadNone, "Number of functions inferred as readnone");
|
2021-01-21 02:45:13 +08:00
|
|
|
STATISTIC(NumInaccessibleMemOnly,
|
|
|
|
"Number of functions inferred as inaccessiblememonly");
|
2016-04-28 03:04:40 +08:00
|
|
|
STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
|
|
|
|
STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
|
2021-01-21 02:45:13 +08:00
|
|
|
STATISTIC(NumInaccessibleMemOrArgMemOnly,
|
|
|
|
"Number of functions inferred as inaccessiblemem_or_argmemonly");
|
2016-04-28 03:04:40 +08:00
|
|
|
STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
|
|
|
|
STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
|
2020-10-30 02:14:55 +08:00
|
|
|
STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
|
2020-11-04 20:49:24 +08:00
|
|
|
STATISTIC(NumSExtArg, "Number of arguments inferred as signext");
|
2016-04-28 03:04:40 +08:00
|
|
|
STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
|
|
|
|
STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
|
[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
|
|
|
STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
|
2016-04-28 03:04:40 +08:00
|
|
|
STATISTIC(NumNonNull, "Number of function returns inferred as nonnull returns");
|
2018-08-23 13:18:23 +08:00
|
|
|
STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
|
2021-01-18 21:40:21 +08:00
|
|
|
STATISTIC(NumWillReturn, "Number of functions inferred as willreturn");
|
2016-04-28 03:04:40 +08:00
|
|
|
|
|
|
|
static bool setDoesNotAccessMemory(Function &F) {
|
|
|
|
if (F.doesNotAccessMemory())
|
|
|
|
return false;
|
|
|
|
F.setDoesNotAccessMemory();
|
|
|
|
++NumReadNone;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-21 02:45:13 +08:00
|
|
|
static bool setOnlyAccessesInaccessibleMemory(Function &F) {
|
|
|
|
if (F.onlyAccessesInaccessibleMemory())
|
|
|
|
return false;
|
|
|
|
F.setOnlyAccessesInaccessibleMemory();
|
|
|
|
++NumInaccessibleMemOnly;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-28 03:04:40 +08:00
|
|
|
static bool setOnlyReadsMemory(Function &F) {
|
|
|
|
if (F.onlyReadsMemory())
|
|
|
|
return false;
|
|
|
|
F.setOnlyReadsMemory();
|
|
|
|
++NumReadOnly;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool setOnlyAccessesArgMemory(Function &F) {
|
|
|
|
if (F.onlyAccessesArgMemory())
|
|
|
|
return false;
|
2017-05-04 02:17:31 +08:00
|
|
|
F.setOnlyAccessesArgMemory();
|
2016-04-28 03:04:40 +08:00
|
|
|
++NumArgMemOnly;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-21 02:45:13 +08:00
|
|
|
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F) {
|
|
|
|
if (F.onlyAccessesInaccessibleMemOrArgMem())
|
|
|
|
return false;
|
|
|
|
F.setOnlyAccessesInaccessibleMemOrArgMem();
|
|
|
|
++NumInaccessibleMemOrArgMemOnly;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-28 03:04:40 +08:00
|
|
|
static bool setDoesNotThrow(Function &F) {
|
|
|
|
if (F.doesNotThrow())
|
|
|
|
return false;
|
|
|
|
F.setDoesNotThrow();
|
|
|
|
++NumNoUnwind;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:17:31 +08:00
|
|
|
static bool setRetDoesNotAlias(Function &F) {
|
|
|
|
if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias))
|
2016-04-28 03:04:40 +08:00
|
|
|
return false;
|
2017-05-04 02:17:31 +08:00
|
|
|
F.addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
|
|
|
|
++NumNoAlias;
|
2016-04-28 03:04:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:17:31 +08:00
|
|
|
static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
|
|
|
|
if (F.hasParamAttribute(ArgNo, Attribute::NoCapture))
|
2016-04-28 03:04:40 +08:00
|
|
|
return false;
|
2017-05-04 02:17:31 +08:00
|
|
|
F.addParamAttr(ArgNo, Attribute::NoCapture);
|
|
|
|
++NumNoCapture;
|
2016-04-28 03:04:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-15 00:50:06 +08:00
|
|
|
static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
|
|
|
|
if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
|
|
|
|
return false;
|
|
|
|
F.addParamAttr(ArgNo, Attribute::NoAlias);
|
|
|
|
++NumNoAlias;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:17:31 +08:00
|
|
|
static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
|
|
|
|
if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
|
2016-04-28 03:04:40 +08:00
|
|
|
return false;
|
2017-05-04 02:17:31 +08:00
|
|
|
F.addParamAttr(ArgNo, Attribute::ReadOnly);
|
|
|
|
++NumReadOnlyArg;
|
2016-04-28 03:04:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-30 02:14:55 +08:00
|
|
|
static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
|
|
|
|
if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
|
|
|
|
return false;
|
|
|
|
F.addParamAttr(ArgNo, Attribute::WriteOnly);
|
|
|
|
++NumWriteOnlyArg;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:49:24 +08:00
|
|
|
static bool setSignExtendedArg(Function &F, unsigned ArgNo) {
|
|
|
|
if (F.hasParamAttribute(ArgNo, Attribute::SExt))
|
|
|
|
return false;
|
|
|
|
F.addParamAttr(ArgNo, Attribute::SExt);
|
|
|
|
++NumSExtArg;
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-30 02:14:55 +08:00
|
|
|
|
2020-09-20 17:08:27 +08:00
|
|
|
static bool setRetNoUndef(Function &F) {
|
[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
|
|
|
if (!F.getReturnType()->isVoidTy() &&
|
|
|
|
!F.hasAttribute(AttributeList::ReturnIndex, Attribute::NoUndef)) {
|
|
|
|
F.addAttribute(AttributeList::ReturnIndex, Attribute::NoUndef);
|
|
|
|
++NumNoUndef;
|
2020-09-20 17:08:27 +08:00
|
|
|
return true;
|
[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
|
|
|
}
|
2020-09-20 17:08:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool setArgsNoUndef(Function &F) {
|
|
|
|
bool Changed = false;
|
[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
|
|
|
for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
|
|
|
|
if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
|
|
|
|
F.addParamAttr(ArgNo, Attribute::NoUndef);
|
|
|
|
++NumNoUndef;
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2020-09-20 17:08:27 +08:00
|
|
|
static bool setRetAndArgsNoUndef(Function &F) {
|
|
|
|
return setRetNoUndef(F) | setArgsNoUndef(F);
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:17:31 +08:00
|
|
|
static bool setRetNonNull(Function &F) {
|
|
|
|
assert(F.getReturnType()->isPointerTy() &&
|
|
|
|
"nonnull applies only to pointers");
|
|
|
|
if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NonNull))
|
2016-04-28 03:04:40 +08:00
|
|
|
return false;
|
2017-05-04 02:17:31 +08:00
|
|
|
F.addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
|
2016-04-28 03:04:40 +08:00
|
|
|
++NumNonNull;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:18:23 +08:00
|
|
|
static bool setReturnedArg(Function &F, unsigned ArgNo) {
|
|
|
|
if (F.hasParamAttribute(ArgNo, Attribute::Returned))
|
|
|
|
return false;
|
|
|
|
F.addParamAttr(ArgNo, Attribute::Returned);
|
|
|
|
++NumReturnedArg;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-11 07:32:36 +08:00
|
|
|
static bool setNonLazyBind(Function &F) {
|
|
|
|
if (F.hasFnAttribute(Attribute::NonLazyBind))
|
|
|
|
return false;
|
|
|
|
F.addFnAttr(Attribute::NonLazyBind);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-08 23:57:56 +08:00
|
|
|
static bool setDoesNotFreeMemory(Function &F) {
|
|
|
|
if (F.hasFnAttribute(Attribute::NoFree))
|
|
|
|
return false;
|
|
|
|
F.addFnAttr(Attribute::NoFree);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-18 21:40:21 +08:00
|
|
|
static bool setWillReturn(Function &F) {
|
|
|
|
if (F.hasFnAttribute(Attribute::WillReturn))
|
|
|
|
return false;
|
|
|
|
F.addFnAttr(Attribute::WillReturn);
|
|
|
|
++NumWillReturn;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-17 05:18:31 +08:00
|
|
|
bool llvm::inferLibFuncAttributes(Module *M, StringRef Name,
|
2018-10-13 23:21:55 +08:00
|
|
|
const TargetLibraryInfo &TLI) {
|
2018-10-17 05:18:31 +08:00
|
|
|
Function *F = M->getFunction(Name);
|
|
|
|
if (!F)
|
2018-10-13 23:21:55 +08:00
|
|
|
return false;
|
2018-10-17 05:18:31 +08:00
|
|
|
return inferLibFuncAttributes(*F, TLI);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
LibFunc TheLibFunc;
|
2016-04-28 03:04:40 +08:00
|
|
|
if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool Changed = false;
|
2018-04-11 07:32:36 +08:00
|
|
|
|
2019-07-08 23:57:56 +08:00
|
|
|
if(!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F, &TLI))
|
|
|
|
Changed |= setDoesNotFreeMemory(F);
|
|
|
|
|
2018-04-11 07:32:36 +08:00
|
|
|
if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
|
|
|
|
Changed |= setNonLazyBind(F);
|
|
|
|
|
2016-04-28 03:04:40 +08:00
|
|
|
switch (TheLibFunc) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strlen:
|
2017-05-06 04:25:50 +08:00
|
|
|
case LibFunc_wcslen:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-06-18 11:10:26 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strchr:
|
|
|
|
case LibFunc_strrchr:
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strtol:
|
|
|
|
case LibFunc_strtod:
|
|
|
|
case LibFunc_strtof:
|
|
|
|
case LibFunc_strtoul:
|
|
|
|
case LibFunc_strtoll:
|
|
|
|
case LibFunc_strtold:
|
|
|
|
case LibFunc_strtoull:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strcpy:
|
2018-08-23 13:18:23 +08:00
|
|
|
case LibFunc_strncpy:
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strcat:
|
|
|
|
case LibFunc_strncat:
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2018-08-23 13:18:23 +08:00
|
|
|
Changed |= setReturnedArg(F, 0);
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case LibFunc_stpcpy:
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_stpncpy:
|
2020-10-18 04:23:39 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2020-09-28 03:32:32 +08:00
|
|
|
Changed |= setDoesNotAlias(F, 0);
|
|
|
|
Changed |= setDoesNotAlias(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strxfrm:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strcmp: // 0,1
|
|
|
|
case LibFunc_strspn: // 0,1
|
|
|
|
case LibFunc_strncmp: // 0,1
|
|
|
|
case LibFunc_strcspn: // 0,1
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
|
|
|
case LibFunc_strcoll:
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strcasecmp: // 0,1
|
|
|
|
case LibFunc_strncasecmp: //
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
// Those functions may depend on the locale, which may be accessed through
|
|
|
|
// global memory.
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strstr:
|
|
|
|
case LibFunc_strpbrk:
|
2020-10-18 04:23:39 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strtok:
|
|
|
|
case LibFunc_strtok_r:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_scanf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_setbuf:
|
|
|
|
case LibFunc_setvbuf:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_strdup:
|
|
|
|
case LibFunc_strndup:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_stat:
|
|
|
|
case LibFunc_statvfs:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_sscanf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_sprintf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2019-08-15 00:50:06 +08:00
|
|
|
Changed |= setDoesNotAlias(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_snprintf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2019-08-15 00:50:06 +08:00
|
|
|
Changed |= setDoesNotAlias(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 2);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 2);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_setitimer:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 2);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_system:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; "system" is a valid pthread cancellation point.
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_malloc:
|
2021-01-23 04:59:29 +08:00
|
|
|
case LibFunc_vec_malloc:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
2020-09-20 17:08:27 +08:00
|
|
|
Changed |= setRetNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_memcmp:
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_memchr:
|
|
|
|
case LibFunc_memrchr:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
|
|
|
Changed |= setOnlyReadsMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_modf:
|
|
|
|
case LibFunc_modff:
|
|
|
|
case LibFunc_modfl:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_memcpy:
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2019-08-15 00:50:06 +08:00
|
|
|
Changed |= setDoesNotAlias(F, 0);
|
2019-10-01 03:43:48 +08:00
|
|
|
Changed |= setReturnedArg(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setDoesNotAlias(F, 1);
|
2019-10-01 03:43:48 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
2018-08-23 13:18:23 +08:00
|
|
|
case LibFunc_memmove:
|
2019-10-01 03:43:48 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setReturnedArg(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
2019-10-01 03:43:48 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_mempcpy:
|
|
|
|
case LibFunc_memccpy:
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2019-10-01 03:43:48 +08:00
|
|
|
Changed |= setDoesNotAlias(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
2019-10-01 03:43:48 +08:00
|
|
|
Changed |= setDoesNotAlias(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_memcpy_chk:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_memalign:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
|
|
|
Changed |= setRetNoUndef(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_mkdir:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_mktime:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_realloc:
|
2021-01-23 04:59:29 +08:00
|
|
|
case LibFunc_vec_realloc:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
|
2020-09-20 17:08:27 +08:00
|
|
|
Changed |= setRetNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
2020-09-20 17:08:27 +08:00
|
|
|
case LibFunc_reallocf:
|
|
|
|
Changed |= setRetNoUndef(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2020-09-20 17:08:27 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_read:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; "read" is a valid pthread cancellation point.
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_rewind:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_rmdir:
|
|
|
|
case LibFunc_remove:
|
|
|
|
case LibFunc_realpath:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_rename:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_readlink:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_write:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; "write" is a valid pthread cancellation point.
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
2020-03-28 13:59:52 +08:00
|
|
|
case LibFunc_aligned_alloc:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
2020-09-20 17:08:27 +08:00
|
|
|
Changed |= setRetNoUndef(F);
|
2020-03-28 13:59:52 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2020-03-28 13:59:52 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_bcopy:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2020-10-18 04:23:39 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 1);
|
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_bcmp:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
[BuildLibCalls] Add argmemonly to more lib calls.
strspn, strncmp, strcspn, strcasecmp, strncasecmp, memcmp, memchr,
memrchr, memcpy, memmove, memcpy, mempcpy, strchr, strrchr, bcmp
should all only access memory through their arguments.
I broke out strcoll, strcasecmp, strncasecmp because the result
depends on the locale, which might get accessed through memory.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D86724
2020-08-28 16:37:01 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_bzero:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2020-10-18 04:23:39 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_calloc:
|
2021-01-23 04:59:29 +08:00
|
|
|
case LibFunc_vec_calloc:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
2020-09-20 17:08:27 +08:00
|
|
|
Changed |= setRetNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_chmod:
|
|
|
|
case LibFunc_chown:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_ctermid:
|
|
|
|
case LibFunc_clearerr:
|
|
|
|
case LibFunc_closedir:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_atoi:
|
|
|
|
case LibFunc_atol:
|
|
|
|
case LibFunc_atof:
|
|
|
|
case LibFunc_atoll:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setOnlyReadsMemory(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_access:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fopen:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fdopen:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_feof:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_free:
|
2021-01-23 04:59:29 +08:00
|
|
|
case LibFunc_vec_free:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
|
2020-09-20 17:08:27 +08:00
|
|
|
Changed |= setArgsNoUndef(F);
|
[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
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
[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
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fseek:
|
|
|
|
case LibFunc_ftell:
|
|
|
|
case LibFunc_fgetc:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_fgetc_unlocked:
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fseeko:
|
|
|
|
case LibFunc_ftello:
|
|
|
|
case LibFunc_fileno:
|
|
|
|
case LibFunc_fflush:
|
|
|
|
case LibFunc_fclose:
|
|
|
|
case LibFunc_fsetpos:
|
|
|
|
case LibFunc_flockfile:
|
|
|
|
case LibFunc_funlockfile:
|
|
|
|
case LibFunc_ftrylockfile:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_ferror:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fputc:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_fputc_unlocked:
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fstat:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_frexp:
|
|
|
|
case LibFunc_frexpf:
|
|
|
|
case LibFunc_frexpl:
|
[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
|
|
|
Changed |= setDoesNotThrow(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
[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
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fstatvfs:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fgets:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_fgets_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 2);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fread:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_fread_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setDoesNotCapture(F, 3);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fwrite:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_fwrite_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setDoesNotCapture(F, 3);
|
2016-04-28 03:04:40 +08:00
|
|
|
// FIXME: readonly #1?
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fputs:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_fputs_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fscanf:
|
|
|
|
case LibFunc_fprintf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fgetpos:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_getc:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_getlogin_r:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
[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
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_getc_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_getenv:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setOnlyReadsMemory(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_gets:
|
|
|
|
case LibFunc_getchar:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_getchar_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_getitimer:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_getpwnam:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_ungetc:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_uname:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_unlink:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_unsetenv:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_utime:
|
|
|
|
case LibFunc_utimes:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_putc:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_putc_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_puts:
|
|
|
|
case LibFunc_printf:
|
|
|
|
case LibFunc_perror:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_pread:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; "pread" is a valid pthread cancellation point.
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_pwrite:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; "pwrite" is a valid pthread cancellation point.
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_putchar:
|
[SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,
Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja
Reviewed By: rja
Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D45736
llvm-svn: 332452
2018-05-16 19:39:52 +08:00
|
|
|
case LibFunc_putchar_unlocked:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_popen:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_pclose:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_vscanf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_vsscanf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_vfscanf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_valloc:
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
2020-09-20 17:08:27 +08:00
|
|
|
Changed |= setRetNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_vprintf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_vfprintf:
|
|
|
|
case LibFunc_vsprintf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_vsnprintf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setDoesNotCapture(F, 2);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 2);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_open:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; "open" is a valid pthread cancellation point.
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_opendir:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_tmpfile:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_times:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_htonl:
|
|
|
|
case LibFunc_htons:
|
|
|
|
case LibFunc_ntohl:
|
|
|
|
case LibFunc_ntohs:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setDoesNotAccessMemory(F);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_lstat:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_lchown:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_qsort:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; places call through function pointer.
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
// Cannot give undef pointer/size
|
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 3);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_dunder_strdup:
|
|
|
|
case LibFunc_dunder_strndup:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_dunder_strtok_r:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_under_IO_getc:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_under_IO_putc:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_dunder_isoc99_scanf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_stat64:
|
|
|
|
case LibFunc_lstat64:
|
|
|
|
case LibFunc_statvfs64:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_dunder_isoc99_sscanf:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fopen64:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fseeko64:
|
|
|
|
case LibFunc_ftello64:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_tmpfile64:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_fstat64:
|
|
|
|
case LibFunc_fstatvfs64:
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_open64:
|
2016-04-28 03:04:40 +08:00
|
|
|
// May throw; "open" is a valid pthread cancellation point.
|
[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
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
Changed |= setOnlyReadsMemory(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_gettimeofday:
|
2016-04-28 03:04:40 +08:00
|
|
|
// Currently some platforms have the restrict keyword on the arguments to
|
|
|
|
// gettimeofday. To be conservative, do not add noalias to gettimeofday's
|
|
|
|
// arguments.
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotThrow(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
|
|
|
return Changed;
|
2021-01-21 07:12:28 +08:00
|
|
|
case LibFunc_ZdlPvRKSt9nothrow_t: // delete(void*, nothrow)
|
|
|
|
case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t: // delete(void*, align_val_t, nothrow)
|
|
|
|
case LibFunc_ZdaPvRKSt9nothrow_t: // delete[](void*, nothrow)
|
|
|
|
case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t: // delete[](void*, align_val_t, nothrow)
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case LibFunc_ZdlPv: // delete(void*)
|
|
|
|
case LibFunc_ZdlPvj: // delete(void*, unsigned int)
|
|
|
|
case LibFunc_ZdlPvm: // delete(void*, unsigned long)
|
|
|
|
case LibFunc_ZdaPv: // delete[](void*)
|
|
|
|
case LibFunc_ZdaPvj: // delete[](void*, unsigned int)
|
|
|
|
case LibFunc_ZdaPvm: // delete[](void*, unsigned long)
|
|
|
|
case LibFunc_ZdlPvSt11align_val_t: // delete(void*, align_val_t)
|
|
|
|
case LibFunc_ZdlPvjSt11align_val_t: // delete(void*, unsigned int, align_val_t)
|
|
|
|
case LibFunc_ZdlPvmSt11align_val_t: // delete(void*, unsigned long, align_val_t)
|
|
|
|
case LibFunc_ZdaPvSt11align_val_t: // delete[](void*, align_val_t)
|
|
|
|
case LibFunc_ZdaPvjSt11align_val_t: // delete[](void*, unsigned int, align_val_t)
|
|
|
|
case LibFunc_ZdaPvmSt11align_val_t: // delete[](void*, unsigned long, align_val_t);
|
|
|
|
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
|
|
|
|
Changed |= setArgsNoUndef(F);
|
|
|
|
Changed |= setWillReturn(F);
|
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
|
|
|
return Changed;
|
|
|
|
case LibFunc_ZnwjRKSt9nothrow_t: // new(unsigned int, nothrow)
|
|
|
|
case LibFunc_ZnwmRKSt9nothrow_t: // new(unsigned long, nothrow)
|
|
|
|
case LibFunc_ZnajRKSt9nothrow_t: // new[](unsigned int, nothrow)
|
|
|
|
case LibFunc_ZnamRKSt9nothrow_t: // new[](unsigned long, nothrow)
|
|
|
|
case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: // new(unsigned int, align_val_t, nothrow)
|
|
|
|
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: // new(unsigned long, align_val_t, nothrow)
|
|
|
|
case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: // new[](unsigned int, align_val_t, nothrow)
|
|
|
|
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: // new[](unsigned long, align_val_t, nothrow)
|
|
|
|
// Nothrow operator new may return null pointer
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
|
|
|
Changed |= setRetNoUndef(F);
|
|
|
|
Changed |= setRetDoesNotAlias(F);
|
|
|
|
Changed |= setWillReturn(F);
|
|
|
|
return Changed;
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_Znwj: // new(unsigned int)
|
|
|
|
case LibFunc_Znwm: // new(unsigned long)
|
|
|
|
case LibFunc_Znaj: // new[](unsigned int)
|
|
|
|
case LibFunc_Znam: // new[](unsigned long)
|
2021-01-21 07:12:28 +08:00
|
|
|
case LibFunc_ZnwjSt11align_val_t: // new(unsigned int, align_val_t)
|
|
|
|
case LibFunc_ZnwmSt11align_val_t: // new(unsigned long, align_val_t)
|
|
|
|
case LibFunc_ZnajSt11align_val_t: // new[](unsigned int, align_val_t)
|
|
|
|
case LibFunc_ZnamSt11align_val_t: // new[](unsigned long, align_val_t)
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_msvc_new_int: // new(unsigned int)
|
|
|
|
case LibFunc_msvc_new_longlong: // new(unsigned long long)
|
|
|
|
case LibFunc_msvc_new_array_int: // new[](unsigned int)
|
|
|
|
case LibFunc_msvc_new_array_longlong: // new[](unsigned long long)
|
2021-01-21 02:45:13 +08:00
|
|
|
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
// Operator new always returns a nonnull noalias pointer
|
2020-09-20 17:08:27 +08:00
|
|
|
Changed |= setRetNoUndef(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setRetNonNull(F);
|
|
|
|
Changed |= setRetDoesNotAlias(F);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
2018-04-25 12:33:36 +08:00
|
|
|
// TODO: add LibFunc entries for:
|
|
|
|
// case LibFunc_memset_pattern4:
|
|
|
|
// case LibFunc_memset_pattern8:
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_memset_pattern16:
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 0);
|
2020-10-30 02:14:55 +08:00
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
2016-04-28 03:04:43 +08:00
|
|
|
Changed |= setDoesNotCapture(F, 1);
|
2017-05-04 02:17:31 +08:00
|
|
|
Changed |= setOnlyReadsMemory(F, 1);
|
2016-04-28 03:04:40 +08:00
|
|
|
return Changed;
|
2021-01-18 21:40:21 +08:00
|
|
|
case LibFunc_memset:
|
|
|
|
Changed |= setOnlyAccessesArgMemory(F);
|
|
|
|
Changed |= setWillReturn(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setOnlyWritesMemory(F, 0);
|
|
|
|
return Changed;
|
2016-04-28 03:04:40 +08:00
|
|
|
// int __nvvm_reflect(const char *)
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
case LibFunc_nvvm_reflect:
|
[BuildLibCalls] Add more noundef to library functions
This patch follows D85345 and adds more noundef attributes to return values/arguments of library functions
that are mostly about accessing the file system or processes.
A few functions like `chmod` or `times` use typedef `mode_t` and `clock_t`.
They are neither struct nor union, so they cannot contain undef even if they're lowered to iN in IR. So, it is fine to add noundef to them.
- clock_t's actual type is size_t (C17, 7.27.1.3), so it isn't struct or union.
- For mode_t, either int or long is used in practice because programmers use bit manipulation. So, I think it is okay that it's never aggregate in practice.
After this patch, the remaining library functions are those that eagerly participate in optimizations: they can be removed, reordered, or
introduced by a transformation from primitive IR operations.
For them, a few testings is needed, since it may not be valid to add noundef anymore even if C standard says it's okay.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D85894
2020-09-09 19:31:51 +08:00
|
|
|
Changed |= setRetAndArgsNoUndef(F);
|
2016-04-28 03:04:40 +08:00
|
|
|
Changed |= setDoesNotAccessMemory(F);
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
return Changed;
|
2020-11-04 20:49:24 +08:00
|
|
|
case LibFunc_ldexp:
|
|
|
|
case LibFunc_ldexpf:
|
|
|
|
case LibFunc_ldexpl:
|
|
|
|
Changed |= setSignExtendedArg(F, 1);
|
2021-01-18 21:40:21 +08:00
|
|
|
Changed |= setWillReturn(F);
|
|
|
|
return Changed;
|
|
|
|
case LibFunc_abs:
|
|
|
|
case LibFunc_acos:
|
|
|
|
case LibFunc_acosf:
|
|
|
|
case LibFunc_acosh:
|
|
|
|
case LibFunc_acoshf:
|
|
|
|
case LibFunc_acoshl:
|
|
|
|
case LibFunc_acosl:
|
|
|
|
case LibFunc_asin:
|
|
|
|
case LibFunc_asinf:
|
|
|
|
case LibFunc_asinh:
|
|
|
|
case LibFunc_asinhf:
|
|
|
|
case LibFunc_asinhl:
|
|
|
|
case LibFunc_asinl:
|
|
|
|
case LibFunc_atan:
|
|
|
|
case LibFunc_atan2:
|
|
|
|
case LibFunc_atan2f:
|
|
|
|
case LibFunc_atan2l:
|
|
|
|
case LibFunc_atanf:
|
|
|
|
case LibFunc_atanh:
|
|
|
|
case LibFunc_atanhf:
|
|
|
|
case LibFunc_atanhl:
|
|
|
|
case LibFunc_atanl:
|
|
|
|
case LibFunc_cbrt:
|
|
|
|
case LibFunc_cbrtf:
|
|
|
|
case LibFunc_cbrtl:
|
|
|
|
case LibFunc_ceil:
|
|
|
|
case LibFunc_ceilf:
|
|
|
|
case LibFunc_ceill:
|
|
|
|
case LibFunc_copysign:
|
|
|
|
case LibFunc_copysignf:
|
|
|
|
case LibFunc_copysignl:
|
|
|
|
case LibFunc_cos:
|
|
|
|
case LibFunc_cosh:
|
|
|
|
case LibFunc_coshf:
|
|
|
|
case LibFunc_coshl:
|
|
|
|
case LibFunc_cosf:
|
|
|
|
case LibFunc_cosl:
|
|
|
|
case LibFunc_cospi:
|
|
|
|
case LibFunc_cospif:
|
|
|
|
case LibFunc_exp:
|
|
|
|
case LibFunc_expf:
|
|
|
|
case LibFunc_expl:
|
|
|
|
case LibFunc_exp2:
|
|
|
|
case LibFunc_exp2f:
|
|
|
|
case LibFunc_exp2l:
|
|
|
|
case LibFunc_expm1:
|
|
|
|
case LibFunc_expm1f:
|
|
|
|
case LibFunc_expm1l:
|
|
|
|
case LibFunc_fabs:
|
|
|
|
case LibFunc_fabsf:
|
|
|
|
case LibFunc_fabsl:
|
|
|
|
case LibFunc_ffs:
|
|
|
|
case LibFunc_ffsl:
|
|
|
|
case LibFunc_ffsll:
|
|
|
|
case LibFunc_floor:
|
|
|
|
case LibFunc_floorf:
|
|
|
|
case LibFunc_floorl:
|
|
|
|
case LibFunc_fls:
|
|
|
|
case LibFunc_flsl:
|
|
|
|
case LibFunc_flsll:
|
|
|
|
case LibFunc_fmax:
|
|
|
|
case LibFunc_fmaxf:
|
|
|
|
case LibFunc_fmaxl:
|
|
|
|
case LibFunc_fmin:
|
|
|
|
case LibFunc_fminf:
|
|
|
|
case LibFunc_fminl:
|
|
|
|
case LibFunc_fmod:
|
|
|
|
case LibFunc_fmodf:
|
|
|
|
case LibFunc_fmodl:
|
|
|
|
case LibFunc_isascii:
|
|
|
|
case LibFunc_isdigit:
|
|
|
|
case LibFunc_labs:
|
|
|
|
case LibFunc_llabs:
|
|
|
|
case LibFunc_log:
|
|
|
|
case LibFunc_log10:
|
|
|
|
case LibFunc_log10f:
|
|
|
|
case LibFunc_log10l:
|
|
|
|
case LibFunc_log1p:
|
|
|
|
case LibFunc_log1pf:
|
|
|
|
case LibFunc_log1pl:
|
|
|
|
case LibFunc_log2:
|
|
|
|
case LibFunc_log2f:
|
|
|
|
case LibFunc_log2l:
|
|
|
|
case LibFunc_logb:
|
|
|
|
case LibFunc_logbf:
|
|
|
|
case LibFunc_logbl:
|
|
|
|
case LibFunc_logf:
|
|
|
|
case LibFunc_logl:
|
|
|
|
case LibFunc_nearbyint:
|
|
|
|
case LibFunc_nearbyintf:
|
|
|
|
case LibFunc_nearbyintl:
|
|
|
|
case LibFunc_pow:
|
|
|
|
case LibFunc_powf:
|
|
|
|
case LibFunc_powl:
|
|
|
|
case LibFunc_rint:
|
|
|
|
case LibFunc_rintf:
|
|
|
|
case LibFunc_rintl:
|
|
|
|
case LibFunc_round:
|
|
|
|
case LibFunc_roundf:
|
|
|
|
case LibFunc_roundl:
|
|
|
|
case LibFunc_sin:
|
|
|
|
case LibFunc_sincospif_stret:
|
|
|
|
case LibFunc_sinf:
|
|
|
|
case LibFunc_sinh:
|
|
|
|
case LibFunc_sinhf:
|
|
|
|
case LibFunc_sinhl:
|
|
|
|
case LibFunc_sinl:
|
|
|
|
case LibFunc_sinpi:
|
|
|
|
case LibFunc_sinpif:
|
|
|
|
case LibFunc_sqrt:
|
|
|
|
case LibFunc_sqrtf:
|
|
|
|
case LibFunc_sqrtl:
|
|
|
|
case LibFunc_strnlen:
|
|
|
|
case LibFunc_tan:
|
|
|
|
case LibFunc_tanf:
|
|
|
|
case LibFunc_tanh:
|
|
|
|
case LibFunc_tanhf:
|
|
|
|
case LibFunc_tanhl:
|
|
|
|
case LibFunc_tanl:
|
|
|
|
case LibFunc_toascii:
|
|
|
|
case LibFunc_trunc:
|
|
|
|
case LibFunc_truncf:
|
|
|
|
case LibFunc_truncl:
|
|
|
|
Changed |= setDoesNotThrow(F);
|
|
|
|
Changed |= setDoesNotFreeMemory(F);
|
|
|
|
Changed |= setWillReturn(F);
|
2020-11-04 20:49:24 +08:00
|
|
|
return Changed;
|
2016-04-28 03:04:40 +08:00
|
|
|
default:
|
|
|
|
// FIXME: It'd be really nice to cover all the library functions we're
|
|
|
|
// aware of here.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-10 00:04:18 +08:00
|
|
|
bool llvm::hasFloatFn(const TargetLibraryInfo *TLI, Type *Ty,
|
|
|
|
LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
|
2018-01-11 14:33:00 +08:00
|
|
|
switch (Ty->getTypeID()) {
|
2018-09-19 20:01:38 +08:00
|
|
|
case Type::HalfTyID:
|
|
|
|
return false;
|
2018-01-11 14:33:00 +08:00
|
|
|
case Type::FloatTyID:
|
|
|
|
return TLI->has(FloatFn);
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
return TLI->has(DoubleFn);
|
|
|
|
default:
|
|
|
|
return TLI->has(LongDoubleFn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-10 00:04:18 +08:00
|
|
|
StringRef llvm::getFloatFnName(const TargetLibraryInfo *TLI, Type *Ty,
|
|
|
|
LibFunc DoubleFn, LibFunc FloatFn,
|
|
|
|
LibFunc LongDoubleFn) {
|
|
|
|
assert(hasFloatFn(TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
|
Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
In several places in the code we use the following pattern:
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
[...]
}
In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.
This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.
In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".
To solve this, the above pattern is changed to
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
LibFunc_tanl, B, Attrs);
[...]
}
I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.
Reviewers: eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, bjope, llvm-commits
Differential Revision: https://reviews.llvm.org/D53370
llvm-svn: 344725
2018-10-18 14:27:53 +08:00
|
|
|
"Cannot get name for unavailable function!");
|
|
|
|
|
|
|
|
switch (Ty->getTypeID()) {
|
|
|
|
case Type::HalfTyID:
|
|
|
|
llvm_unreachable("No name for HalfTy!");
|
|
|
|
case Type::FloatTyID:
|
|
|
|
return TLI->getName(FloatFn);
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
return TLI->getName(DoubleFn);
|
|
|
|
default:
|
|
|
|
return TLI->getName(LongDoubleFn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 03:04:40 +08:00
|
|
|
//- Emit LibCalls ------------------------------------------------------------//
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::castToCStr(Value *V, IRBuilderBase &B) {
|
2014-04-24 04:58:57 +08:00
|
|
|
unsigned AS = V->getType()->getPointerAddressSpace();
|
|
|
|
return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
|
|
|
|
2019-06-01 06:41:31 +08:00
|
|
|
static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
|
|
|
|
ArrayRef<Type *> ParamTypes,
|
2020-02-18 04:52:11 +08:00
|
|
|
ArrayRef<Value *> Operands, IRBuilderBase &B,
|
2019-06-01 06:41:31 +08:00
|
|
|
const TargetLibraryInfo *TLI,
|
|
|
|
bool IsVaArgs = false) {
|
|
|
|
if (!TLI->has(TheLibFunc))
|
2014-04-25 13:29:35 +08:00
|
|
|
return nullptr;
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2019-06-01 06:41:31 +08:00
|
|
|
StringRef FuncName = TLI->getName(TheLibFunc);
|
|
|
|
FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
|
|
|
|
FunctionCallee Callee = M->getOrInsertFunction(FuncName, FuncType);
|
|
|
|
inferLibFuncAttributes(M, FuncName, *TLI);
|
|
|
|
CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *F =
|
2019-06-01 06:41:31 +08:00
|
|
|
dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
2010-03-06 06:25:30 +08:00
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
|
2015-03-10 10:37:25 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
2019-06-01 06:41:31 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
|
|
|
return emitLibCall(LibFunc_strlen, DL.getIntPtrType(Context),
|
|
|
|
B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI);
|
2019-09-24 02:20:01 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B,
|
2019-09-24 02:20:01 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
return emitLibCall(LibFunc_strdup, B.getInt8PtrTy(), B.getInt8PtrTy(),
|
|
|
|
castToCStr(Ptr, B), B, TLI);
|
2019-06-01 06:41:31 +08:00
|
|
|
}
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
|
2019-06-01 06:41:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *I8Ptr = B.getInt8PtrTy();
|
|
|
|
Type *I32Ty = B.getInt32Ty();
|
2019-06-01 06:41:31 +08:00
|
|
|
return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, I32Ty},
|
|
|
|
{castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, B, TLI);
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
|
2015-03-10 10:37:25 +08:00
|
|
|
const DataLayout &DL, const TargetLibraryInfo *TLI) {
|
2012-11-01 16:07:29 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
2019-06-01 06:41:31 +08:00
|
|
|
return emitLibCall(
|
|
|
|
LibFunc_strncmp, B.getInt32Ty(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
|
|
|
|
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
|
2010-06-16 05:34:25 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B,
|
2019-06-01 06:41:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
Type *I8Ptr = B.getInt8PtrTy();
|
|
|
|
return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
|
|
|
|
{castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
|
|
|
|
}
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
|
2019-06-01 06:41:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *I8Ptr = B.getInt8PtrTy();
|
2019-06-01 06:41:31 +08:00
|
|
|
return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
|
|
|
|
{castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
|
2019-06-01 06:41:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
Type *I8Ptr = B.getInt8PtrTy();
|
|
|
|
return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
|
|
|
|
{castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
|
|
|
|
}
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
|
2019-06-01 06:41:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *I8Ptr = B.getInt8PtrTy();
|
2019-06-01 06:41:31 +08:00
|
|
|
return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
|
|
|
|
{castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
|
2010-03-11 09:25:07 +08:00
|
|
|
}
|
|
|
|
|
2016-01-20 03:46:10 +08:00
|
|
|
Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
|
2020-02-18 04:52:11 +08:00
|
|
|
IRBuilderBase &B, const DataLayout &DL,
|
2012-07-26 00:46:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
if (!TLI->has(LibFunc_memcpy_chk))
|
2014-04-25 13:29:35 +08:00
|
|
|
return nullptr;
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
AttributeList AS;
|
|
|
|
AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
|
|
|
|
Attribute::NoUnwind);
|
2012-11-01 16:07:29 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee MemCpy = M->getOrInsertFunction(
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
"__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
|
2015-03-10 10:37:25 +08:00
|
|
|
B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
|
2017-04-11 23:01:18 +08:00
|
|
|
DL.getIntPtrType(Context));
|
2016-01-20 03:46:10 +08:00
|
|
|
Dst = castToCStr(Dst, B);
|
|
|
|
Src = castToCStr(Src, B);
|
2015-05-19 06:13:54 +08:00
|
|
|
CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *F =
|
|
|
|
dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
2010-03-23 23:48:04 +08:00
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
2020-10-06 04:16:59 +08:00
|
|
|
Value *llvm::emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
|
|
|
|
const DataLayout &DL, const TargetLibraryInfo *TLI) {
|
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
|
|
|
return emitLibCall(
|
|
|
|
LibFunc_mempcpy, B.getInt8PtrTy(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
|
|
|
|
{Dst, Src, Len}, B, TLI);
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
|
2015-03-10 10:37:25 +08:00
|
|
|
const DataLayout &DL, const TargetLibraryInfo *TLI) {
|
2012-11-01 16:07:29 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
2019-06-01 06:41:31 +08:00
|
|
|
return emitLibCall(
|
|
|
|
LibFunc_memchr, B.getInt8PtrTy(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)},
|
|
|
|
{castToCStr(Ptr, B), Val, Len}, B, TLI);
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
|
[SelectionDAG] Allow the user to specify a memeq function.
Summary:
Right now, when we encounter a string equality check,
e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a
small compile-time constant, and fall back on calling `memcmp()` else.
This is sub-optimal because memcmp has to compute much more than
equality.
This patch replaces `memcmp(a, b, s) == 0` by `bcmp(a, b, s) == 0` on platforms
that support `bcmp`.
`bcmp` can be made much more efficient than `memcmp` because equality
compare is trivially parallel while lexicographic ordering has a chain
dependency.
Subscribers: fedor.sergeev, jyknight, ckennelly, gchatelet, llvm-commits
Differential Revision: https://reviews.llvm.org/D56593
llvm-svn: 355672
2019-03-08 17:07:45 +08:00
|
|
|
const DataLayout &DL, const TargetLibraryInfo *TLI) {
|
2019-06-01 06:41:31 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
|
|
|
return emitLibCall(
|
|
|
|
LibFunc_memcmp, B.getInt32Ty(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
|
|
|
|
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
|
[SelectionDAG] Allow the user to specify a memeq function.
Summary:
Right now, when we encounter a string equality check,
e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a
small compile-time constant, and fall back on calling `memcmp()` else.
This is sub-optimal because memcmp has to compute much more than
equality.
This patch replaces `memcmp(a, b, s) == 0` by `bcmp(a, b, s) == 0` on platforms
that support `bcmp`.
`bcmp` can be made much more efficient than `memcmp` because equality
compare is trivially parallel while lexicographic ordering has a chain
dependency.
Subscribers: fedor.sergeev, jyknight, ckennelly, gchatelet, llvm-commits
Differential Revision: https://reviews.llvm.org/D56593
llvm-svn: 355672
2019-03-08 17:07:45 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
|
[SelectionDAG] Allow the user to specify a memeq function.
Summary:
Right now, when we encounter a string equality check,
e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a
small compile-time constant, and fall back on calling `memcmp()` else.
This is sub-optimal because memcmp has to compute much more than
equality.
This patch replaces `memcmp(a, b, s) == 0` by `bcmp(a, b, s) == 0` on platforms
that support `bcmp`.
`bcmp` can be made much more efficient than `memcmp` because equality
compare is trivially parallel while lexicographic ordering has a chain
dependency.
Subscribers: fedor.sergeev, jyknight, ckennelly, gchatelet, llvm-commits
Differential Revision: https://reviews.llvm.org/D56593
llvm-svn: 355672
2019-03-08 17:07:45 +08:00
|
|
|
const DataLayout &DL, const TargetLibraryInfo *TLI) {
|
2019-06-01 06:41:31 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
|
|
|
return emitLibCall(
|
|
|
|
LibFunc_bcmp, B.getInt32Ty(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
|
|
|
|
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
|
[SelectionDAG] Allow the user to specify a memeq function.
Summary:
Right now, when we encounter a string equality check,
e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a
small compile-time constant, and fall back on calling `memcmp()` else.
This is sub-optimal because memcmp has to compute much more than
equality.
This patch replaces `memcmp(a, b, s) == 0` by `bcmp(a, b, s) == 0` on platforms
that support `bcmp`.
`bcmp` can be made much more efficient than `memcmp` because equality
compare is trivially parallel while lexicographic ordering has a chain
dependency.
Subscribers: fedor.sergeev, jyknight, ckennelly, gchatelet, llvm-commits
Differential Revision: https://reviews.llvm.org/D56593
llvm-svn: 355672
2019-03-08 17:07:45 +08:00
|
|
|
}
|
|
|
|
|
2019-06-01 06:41:36 +08:00
|
|
|
Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
|
2020-02-18 04:52:11 +08:00
|
|
|
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
|
2019-06-01 06:41:36 +08:00
|
|
|
return emitLibCall(
|
|
|
|
LibFunc_memccpy, B.getInt8PtrTy(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt32Ty(), Len->getType()},
|
|
|
|
{Ptr1, Ptr2, Val, Len}, B, TLI);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *llvm::emitSNPrintf(Value *Dest, Value *Size, Value *Fmt,
|
2020-02-18 04:52:11 +08:00
|
|
|
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
|
2019-06-01 06:41:36 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
SmallVector<Value *, 8> Args{castToCStr(Dest, B), Size, castToCStr(Fmt, B)};
|
2020-12-28 01:57:28 +08:00
|
|
|
llvm::append_range(Args, VariadicArgs);
|
2019-06-01 06:41:36 +08:00
|
|
|
return emitLibCall(LibFunc_snprintf, B.getInt32Ty(),
|
|
|
|
{B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy()},
|
|
|
|
Args, B, TLI, /*IsVaArgs=*/true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *llvm::emitSPrintf(Value *Dest, Value *Fmt,
|
2020-02-18 04:52:11 +08:00
|
|
|
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
|
2019-06-01 06:41:36 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
SmallVector<Value *, 8> Args{castToCStr(Dest, B), castToCStr(Fmt, B)};
|
2020-12-28 01:57:28 +08:00
|
|
|
llvm::append_range(Args, VariadicArgs);
|
2019-06-01 06:41:36 +08:00
|
|
|
return emitLibCall(LibFunc_sprintf, B.getInt32Ty(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy()}, Args, B, TLI,
|
|
|
|
/*IsVaArgs=*/true);
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
|
2019-06-01 06:41:36 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy()},
|
|
|
|
{castToCStr(Dest, B), castToCStr(Src, B)}, B, TLI);
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
|
2019-06-01 06:41:36 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
return emitLibCall(LibFunc_strlcpy, Size->getType(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
|
|
|
|
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
|
2019-06-01 06:41:36 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
return emitLibCall(LibFunc_strlcat, Size->getType(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
|
|
|
|
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
|
2019-06-01 06:41:36 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
return emitLibCall(LibFunc_strncat, B.getInt8PtrTy(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
|
|
|
|
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
|
2020-02-18 04:52:11 +08:00
|
|
|
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
|
2019-06-01 06:41:36 +08:00
|
|
|
return emitLibCall(
|
|
|
|
LibFunc_vsnprintf, B.getInt32Ty(),
|
|
|
|
{B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy(), VAList->getType()},
|
|
|
|
{castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
|
2020-02-18 04:52:11 +08:00
|
|
|
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
|
2019-06-01 06:41:36 +08:00
|
|
|
return emitLibCall(LibFunc_vsprintf, B.getInt32Ty(),
|
|
|
|
{B.getInt8PtrTy(), B.getInt8PtrTy(), VAList->getType()},
|
|
|
|
{castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI);
|
|
|
|
}
|
|
|
|
|
2013-12-17 06:42:40 +08:00
|
|
|
/// Append a suffix to the function name according to the type of 'Op'.
|
2016-01-20 03:46:10 +08:00
|
|
|
static void appendTypeSuffix(Value *Op, StringRef &Name,
|
2016-01-20 03:17:47 +08:00
|
|
|
SmallString<20> &NameBuffer) {
|
2013-12-17 06:42:40 +08:00
|
|
|
if (!Op->getType()->isDoubleTy()) {
|
|
|
|
NameBuffer += Name;
|
|
|
|
|
|
|
|
if (Op->getType()->isFloatTy())
|
|
|
|
NameBuffer += 'f';
|
|
|
|
else
|
|
|
|
NameBuffer += 'l';
|
|
|
|
|
|
|
|
Name = NameBuffer;
|
2018-07-31 03:41:25 +08:00
|
|
|
}
|
2013-12-17 06:42:40 +08:00
|
|
|
}
|
|
|
|
|
Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
In several places in the code we use the following pattern:
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
[...]
}
In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.
This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.
In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".
To solve this, the above pattern is changed to
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
LibFunc_tanl, B, Attrs);
[...]
}
I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.
Reviewers: eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, bjope, llvm-commits
Differential Revision: https://reviews.llvm.org/D53370
llvm-svn: 344725
2018-10-18 14:27:53 +08:00
|
|
|
static Value *emitUnaryFloatFnCallHelper(Value *Op, StringRef Name,
|
2020-02-18 04:52:11 +08:00
|
|
|
IRBuilderBase &B,
|
Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
In several places in the code we use the following pattern:
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
[...]
}
In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.
This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.
In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".
To solve this, the above pattern is changed to
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
LibFunc_tanl, B, Attrs);
[...]
}
I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.
Reviewers: eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, bjope, llvm-commits
Differential Revision: https://reviews.llvm.org/D53370
llvm-svn: 344725
2018-10-18 14:27:53 +08:00
|
|
|
const AttributeList &Attrs) {
|
|
|
|
assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
|
2010-03-06 06:25:30 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee Callee =
|
|
|
|
M->getOrInsertFunction(Name, Op->getType(), Op->getType());
|
2010-03-06 06:25:30 +08:00
|
|
|
CallInst *CI = B.CreateCall(Callee, Op, Name);
|
2017-05-03 10:26:10 +08:00
|
|
|
|
|
|
|
// The incoming attribute set may have come from a speculatable intrinsic, but
|
|
|
|
// is being replaced with a library call which is not allowed to be
|
|
|
|
// speculatable.
|
|
|
|
CI->setAttributes(Attrs.removeAttribute(B.getContext(),
|
|
|
|
AttributeList::FunctionIndex,
|
|
|
|
Attribute::Speculatable));
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *F =
|
|
|
|
dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
|
|
|
|
2010-03-06 06:25:30 +08:00
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilderBase &B,
|
Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
In several places in the code we use the following pattern:
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
[...]
}
In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.
This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.
In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".
To solve this, the above pattern is changed to
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
LibFunc_tanl, B, Attrs);
[...]
}
I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.
Reviewers: eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, bjope, llvm-commits
Differential Revision: https://reviews.llvm.org/D53370
llvm-svn: 344725
2018-10-18 14:27:53 +08:00
|
|
|
const AttributeList &Attrs) {
|
|
|
|
SmallString<20> NameBuffer;
|
|
|
|
appendTypeSuffix(Op, Name, NameBuffer);
|
|
|
|
|
|
|
|
return emitUnaryFloatFnCallHelper(Op, Name, B, Attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *llvm::emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI,
|
|
|
|
LibFunc DoubleFn, LibFunc FloatFn,
|
2020-02-18 04:52:11 +08:00
|
|
|
LibFunc LongDoubleFn, IRBuilderBase &B,
|
Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
In several places in the code we use the following pattern:
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
[...]
}
In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.
This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.
In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".
To solve this, the above pattern is changed to
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
LibFunc_tanl, B, Attrs);
[...]
}
I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.
Reviewers: eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, bjope, llvm-commits
Differential Revision: https://reviews.llvm.org/D53370
llvm-svn: 344725
2018-10-18 14:27:53 +08:00
|
|
|
const AttributeList &Attrs) {
|
|
|
|
// Get the name of the function according to TLI.
|
2019-08-10 00:04:18 +08:00
|
|
|
StringRef Name = getFloatFnName(TLI, Op->getType(),
|
|
|
|
DoubleFn, FloatFn, LongDoubleFn);
|
Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
In several places in the code we use the following pattern:
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
[...]
}
In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.
This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.
In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".
To solve this, the above pattern is changed to
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
LibFunc_tanl, B, Attrs);
[...]
}
I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.
Reviewers: eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, bjope, llvm-commits
Differential Revision: https://reviews.llvm.org/D53370
llvm-svn: 344725
2018-10-18 14:27:53 +08:00
|
|
|
|
|
|
|
return emitUnaryFloatFnCallHelper(Op, Name, B, Attrs);
|
|
|
|
}
|
|
|
|
|
2019-08-10 01:06:46 +08:00
|
|
|
static Value *emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2,
|
2020-02-18 04:52:11 +08:00
|
|
|
StringRef Name, IRBuilderBase &B,
|
2020-11-04 20:49:24 +08:00
|
|
|
const AttributeList &Attrs,
|
|
|
|
const TargetLibraryInfo *TLI = nullptr) {
|
Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
In several places in the code we use the following pattern:
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
[...]
}
In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.
This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.
In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".
To solve this, the above pattern is changed to
if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
[...]
Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
LibFunc_tanl, B, Attrs);
[...]
}
I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.
Reviewers: eli.friedman, efriedma
Reviewed By: efriedma
Subscribers: efriedma, bjope, llvm-commits
Differential Revision: https://reviews.llvm.org/D53370
llvm-svn: 344725
2018-10-18 14:27:53 +08:00
|
|
|
assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
|
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2019-08-10 01:06:46 +08:00
|
|
|
FunctionCallee Callee = M->getOrInsertFunction(Name, Op1->getType(),
|
|
|
|
Op1->getType(), Op2->getType());
|
2020-11-04 20:49:24 +08:00
|
|
|
if (TLI != nullptr)
|
|
|
|
inferLibFuncAttributes(M, Name, *TLI);
|
2019-08-10 01:06:46 +08:00
|
|
|
CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
|
|
|
|
|
|
|
|
// The incoming attribute set may have come from a speculatable intrinsic, but
|
|
|
|
// is being replaced with a library call which is not allowed to be
|
|
|
|
// speculatable.
|
|
|
|
CI->setAttributes(Attrs.removeAttribute(B.getContext(),
|
|
|
|
AttributeList::FunctionIndex,
|
|
|
|
Attribute::Speculatable));
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *F =
|
|
|
|
dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
|
|
|
|
2013-12-17 06:42:40 +08:00
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
2019-08-10 01:06:46 +08:00
|
|
|
Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
|
2020-02-18 04:52:11 +08:00
|
|
|
IRBuilderBase &B,
|
|
|
|
const AttributeList &Attrs) {
|
2019-08-10 01:06:46 +08:00
|
|
|
assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
|
|
|
|
|
|
|
|
SmallString<20> NameBuffer;
|
|
|
|
appendTypeSuffix(Op1, Name, NameBuffer);
|
|
|
|
|
|
|
|
return emitBinaryFloatFnCallHelper(Op1, Op2, Name, B, Attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2,
|
|
|
|
const TargetLibraryInfo *TLI,
|
|
|
|
LibFunc DoubleFn, LibFunc FloatFn,
|
2020-02-18 04:52:11 +08:00
|
|
|
LibFunc LongDoubleFn, IRBuilderBase &B,
|
2019-08-10 01:06:46 +08:00
|
|
|
const AttributeList &Attrs) {
|
|
|
|
// Get the name of the function according to TLI.
|
|
|
|
StringRef Name = getFloatFnName(TLI, Op1->getType(),
|
|
|
|
DoubleFn, FloatFn, LongDoubleFn);
|
|
|
|
|
2020-11-04 20:49:24 +08:00
|
|
|
return emitBinaryFloatFnCallHelper(Op1, Op2, Name, B, Attrs, TLI);
|
2019-08-10 01:06:46 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitPutChar(Value *Char, IRBuilderBase &B,
|
2012-07-26 00:46:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
if (!TLI->has(LibFunc_putchar))
|
2014-04-25 13:29:35 +08:00
|
|
|
return nullptr;
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2018-10-17 05:18:31 +08:00
|
|
|
StringRef PutCharName = TLI->getName(LibFunc_putchar);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee PutChar =
|
|
|
|
M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty());
|
2018-10-17 05:18:31 +08:00
|
|
|
inferLibFuncAttributes(M, PutCharName, *TLI);
|
2010-03-06 06:25:30 +08:00
|
|
|
CallInst *CI = B.CreateCall(PutChar,
|
|
|
|
B.CreateIntCast(Char,
|
|
|
|
B.getInt32Ty(),
|
|
|
|
/*isSigned*/true,
|
|
|
|
"chari"),
|
2018-10-17 05:18:31 +08:00
|
|
|
PutCharName);
|
2014-03-13 02:09:37 +08:00
|
|
|
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *F =
|
|
|
|
dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
2010-03-06 06:25:30 +08:00
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitPutS(Value *Str, IRBuilderBase &B,
|
2012-07-26 00:46:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
if (!TLI->has(LibFunc_puts))
|
2014-04-25 13:29:35 +08:00
|
|
|
return nullptr;
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2018-10-17 05:18:31 +08:00
|
|
|
StringRef PutsName = TLI->getName(LibFunc_puts);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee PutS =
|
2018-10-17 05:18:31 +08:00
|
|
|
M->getOrInsertFunction(PutsName, B.getInt32Ty(), B.getInt8PtrTy());
|
|
|
|
inferLibFuncAttributes(M, PutsName, *TLI);
|
|
|
|
CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *F =
|
|
|
|
dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
2012-07-26 00:46:31 +08:00
|
|
|
return CI;
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilderBase &B,
|
2015-03-10 10:37:25 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
if (!TLI->has(LibFunc_fputc))
|
2014-04-25 13:29:35 +08:00
|
|
|
return nullptr;
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2018-10-17 05:18:31 +08:00
|
|
|
StringRef FPutcName = TLI->getName(LibFunc_fputc);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(),
|
|
|
|
B.getInt32Ty(), File->getType());
|
2010-03-06 06:25:30 +08:00
|
|
|
if (File->getType()->isPointerTy())
|
2018-10-17 05:18:31 +08:00
|
|
|
inferLibFuncAttributes(M, FPutcName, *TLI);
|
2010-03-06 06:25:30 +08:00
|
|
|
Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
|
|
|
|
"chari");
|
2018-10-17 05:18:31 +08:00
|
|
|
CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
|
2014-03-13 02:09:37 +08:00
|
|
|
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *Fn =
|
|
|
|
dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(Fn->getCallingConv());
|
2012-07-26 00:46:31 +08:00
|
|
|
return CI;
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
|
2015-03-10 10:37:25 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
if (!TLI->has(LibFunc_fputs))
|
2014-04-25 13:29:35 +08:00
|
|
|
return nullptr;
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
StringRef FPutsName = TLI->getName(LibFunc_fputs);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
|
|
|
|
B.getInt8PtrTy(), File->getType());
|
2010-03-06 06:25:30 +08:00
|
|
|
if (File->getType()->isPointerTy())
|
2018-10-17 05:18:31 +08:00
|
|
|
inferLibFuncAttributes(M, FPutsName, *TLI);
|
|
|
|
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName);
|
2014-03-13 02:09:37 +08:00
|
|
|
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *Fn =
|
|
|
|
dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(Fn->getCallingConv());
|
2012-07-26 00:46:31 +08:00
|
|
|
return CI;
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
|
2015-03-10 10:37:25 +08:00
|
|
|
const DataLayout &DL, const TargetLibraryInfo *TLI) {
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
if (!TLI->has(LibFunc_fwrite))
|
2014-04-25 13:29:35 +08:00
|
|
|
return nullptr;
|
2012-07-26 00:46:31 +08:00
|
|
|
|
2016-01-20 03:58:49 +08:00
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2012-11-01 16:07:29 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
[Analysis] Add LibFunc_ prefix to enums in TargetLibraryInfo. (NFC)
Summary:
The LibFunc::Func enum holds enumerators named for libc functions.
Unfortunately, there are real situations, including libc implementations, where
function names are actually macros (musl uses "#define fopen64 fopen", for
example; any other transitively visible macro would have similar effects).
Strictly speaking, a conforming C++ Standard Library should provide any such
macros as functions instead (via <cstdio>). However, there are some "library"
functions which are not part of the standard, and thus not subject to this
rule (fopen64, for example). So, in order to be both portable and consistent,
the enum should not use the bare function names.
The old enum naming used a namespace LibFunc and an enum Func, with bare
enumerators. This patch changes LibFunc to be an enum with enumerators prefixed
with "LibFFunc_". (Unfortunately, a scoped enum is not sufficient to override
macros.)
There are additional changes required in clang.
Reviewers: rsmith
Subscribers: mehdi_amini, mzolotukhin, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28476
llvm-svn: 292848
2017-01-24 07:16:46 +08:00
|
|
|
StringRef FWriteName = TLI->getName(LibFunc_fwrite);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee F = M->getOrInsertFunction(
|
2016-04-28 03:04:40 +08:00
|
|
|
FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
|
2017-04-11 23:01:18 +08:00
|
|
|
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
|
|
|
|
|
2010-03-06 06:25:30 +08:00
|
|
|
if (File->getType()->isPointerTy())
|
2018-10-17 05:18:31 +08:00
|
|
|
inferLibFuncAttributes(M, FWriteName, *TLI);
|
2015-03-10 10:37:25 +08:00
|
|
|
CallInst *CI =
|
2016-01-20 03:46:10 +08:00
|
|
|
B.CreateCall(F, {castToCStr(Ptr, B), Size,
|
2015-05-19 06:13:54 +08:00
|
|
|
ConstantInt::get(DL.getIntPtrType(Context), 1), File});
|
2014-03-13 02:09:37 +08:00
|
|
|
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *Fn =
|
|
|
|
dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
|
2014-03-13 02:09:37 +08:00
|
|
|
CI->setCallingConv(Fn->getCallingConv());
|
2012-07-26 00:46:31 +08:00
|
|
|
return CI;
|
2010-03-06 06:25:30 +08:00
|
|
|
}
|
2018-04-18 22:21:31 +08:00
|
|
|
|
2020-02-18 04:52:11 +08:00
|
|
|
Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
|
2018-04-18 22:21:31 +08:00
|
|
|
const TargetLibraryInfo *TLI) {
|
|
|
|
if (!TLI->has(LibFunc_malloc))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2018-10-17 05:18:31 +08:00
|
|
|
StringRef MallocName = TLI->getName(LibFunc_malloc);
|
2018-04-18 22:21:31 +08:00
|
|
|
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(),
|
|
|
|
DL.getIntPtrType(Context));
|
2018-10-17 05:18:31 +08:00
|
|
|
inferLibFuncAttributes(M, MallocName, *TLI);
|
|
|
|
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
|
2018-04-18 22:21:31 +08:00
|
|
|
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const Function *F =
|
|
|
|
dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
|
2018-04-18 22:21:31 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
|
|
|
|
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *llvm::emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,
|
2020-02-18 04:52:11 +08:00
|
|
|
IRBuilderBase &B, const TargetLibraryInfo &TLI) {
|
2018-04-18 22:21:31 +08:00
|
|
|
if (!TLI.has(LibFunc_calloc))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Module *M = B.GetInsertBlock()->getModule();
|
2018-10-17 05:18:31 +08:00
|
|
|
StringRef CallocName = TLI.getName(LibFunc_calloc);
|
2018-04-18 22:21:31 +08:00
|
|
|
const DataLayout &DL = M->getDataLayout();
|
|
|
|
IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
FunctionCallee Calloc = M->getOrInsertFunction(
|
|
|
|
CallocName, Attrs, B.getInt8PtrTy(), PtrType, PtrType);
|
2018-10-17 05:18:31 +08:00
|
|
|
inferLibFuncAttributes(M, CallocName, TLI);
|
|
|
|
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
|
2018-04-18 22:21:31 +08:00
|
|
|
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 10:28:03 +08:00
|
|
|
if (const auto *F =
|
|
|
|
dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
|
2018-04-18 22:21:31 +08:00
|
|
|
CI->setCallingConv(F->getCallingConv());
|
|
|
|
|
|
|
|
return CI;
|
|
|
|
}
|