33 ArrayType *ATy = cast<ArrayType>(GVCtor->getValueType());
36 if (Data && OldEltTy->getNumElements() < 3)
42 unsigned n =
Init->getNumOperands();
43 CurrentCtors.reserve(n + 1);
44 for (
unsigned i = 0;
i != n; ++
i) {
45 auto Ctor = cast<Constant>(
Init->getOperand(
i));
46 if (EltTy != OldEltTy)
48 EltTy, Ctor->getAggregateElement((
unsigned)0),
49 Ctor->getAggregateElement(1),
51 CurrentCtors.push_back(Ctor);
54 GVCtor->eraseFromParent();
63 CSVals[0] = IRB.getInt32(Priority);
72 CurrentCtors.push_back(RuntimeCtorInit);
100 if (InitAsSet.
insert(C).second)
107 for (
auto *V : Values) {
109 if (InitAsSet.
insert(C).second)
119 GV->setSection(
"llvm.metadata");
131 if (isa<Function>(FuncOrBitcast))
132 return cast<Function>(FuncOrBitcast);
133 FuncOrBitcast->
dump();
136 Stream <<
"Sanitizer interface function redefined: " << *FuncOrBitcast;
144 assert(!InitName.
empty() &&
"Expected init function name");
146 "Sanitizer's init function expects different number of arguments");
157 IRB.CreateCall(InitFunction, InitArgs);
158 if (!VersionCheckName.
empty()) {
163 IRB.CreateCall(VersionCheckFunction, {});
165 return std::make_pair(Ctor, InitFunction);
175 for (
Function *
F : DeadComdatFunctions) {
177 assert(C &&
"Expected all input GVs to be in a comdat!");
178 ComdatEntriesCovered[
C] += 1;
181 auto CheckComdat = [&](
Comdat &
C) {
182 auto CI = ComdatEntriesCovered.
find(&
C);
183 if (CI == ComdatEntriesCovered.
end())
188 if (CI->second > 0) {
195 ComdatEntriesCovered.
erase(CI);
198 auto CheckAllComdats = [&] {
202 if (ComdatEntriesCovered.
empty())
206 if (
Comdat *
C = GV.getComdat()) {
208 if (ComdatEntriesCovered.
empty())
212 if (
Comdat *
C = GA.getComdat()) {
214 if (ComdatEntriesCovered.
empty())
220 if (ComdatEntriesCovered.
empty()) {
221 DeadComdatFunctions.clear();
228 ComdatEntriesCovered.
end();
void push_back(const T &Elt)
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Special purpose, only applies to global arrays.
Function * checkSanitizerInterfaceFunction(Constant *FuncOrBitcast)
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
A Module instance is used to store all the information related to an LLVM module. ...
Externally visible function.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Class to represent struct types.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void filterDeadComdatFunctions(Module &M, SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive...
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
LLVM_NODISCARD bool empty() const
Class to represent function types.
Class to represent array types.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Type * getElementType() const
size_t size() const
size - Get the array size.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool erase(const KeyT &Val)
iterator_range< iterator > functions()
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important base class in LLVM.
static void appendToGlobalArray(const char *Array, Module &M, Function *F, int Priority, Constant *Data)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static Type * getVoidTy(LLVMContext &C)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
void dump() const
Support for debugging, callable in GDB: V->dump()
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
std::pair< Function *, Function * > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function, and calls sanitizer's init function from it.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
GlobalVariable * getNamedGlobal(StringRef Name)
Return the global variable in the module with the specified name, of arbitrary type.
void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
void setLinkage(LinkageTypes LT)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
ConstantArray - Constant Array Declarations.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static void appendToUsedList(Module &M, StringRef Name, ArrayRef< GlobalValue * > Values)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
iterator find(const KeyT &Val)
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Rename collisions when linking (static functions).
LLVM_NODISCARD bool empty() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
unsigned getNumElements() const
Random access to the elements.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
LLVMContext & getContext() const
Get the global data context.
iterator_range< alias_iterator > aliases()