MCPcopy Create free account
hub / github.com/GANGE666/xVMP / parseGlobalVarRecord

Method parseGlobalVarRecord

src/lib/Bitcode/Reader/BitcodeReader.cpp:2878–2973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2876}
2877
2878Error BitcodeReader::parseGlobalVarRecord(ArrayRef<uint64_t> Record) {
2879 // v1: [pointer type, isconst, initid, linkage, alignment, section,
2880 // visibility, threadlocal, unnamed_addr, externally_initialized,
2881 // dllstorageclass, comdat, attributes, preemption specifier] (name in VST)
2882 // v2: [strtab_offset, strtab_size, v1]
2883 StringRef Name;
2884 std::tie(Name, Record) = readNameFromStrtab(Record);
2885
2886 if (Record.size() < 6)
2887 return error("Invalid record");
2888 Type *Ty = getTypeByID(Record[0]);
2889 if (!Ty)
2890 return error("Invalid record");
2891 bool isConstant = Record[1] & 1;
2892 bool explicitType = Record[1] & 2;
2893 unsigned AddressSpace;
2894 if (explicitType) {
2895 AddressSpace = Record[1] >> 2;
2896 } else {
2897 if (!Ty->isPointerTy())
2898 return error("Invalid type for value");
2899 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
2900 Ty = cast<PointerType>(Ty)->getElementType();
2901 }
2902
2903 uint64_t RawLinkage = Record[3];
2904 GlobalValue::LinkageTypes Linkage = getDecodedLinkage(RawLinkage);
2905 unsigned Alignment;
2906 if (Error Err = parseAlignmentValue(Record[4], Alignment))
2907 return Err;
2908 std::string Section;
2909 if (Record[5]) {
2910 if (Record[5] - 1 >= SectionTable.size())
2911 return error("Invalid ID");
2912 Section = SectionTable[Record[5] - 1];
2913 }
2914 GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
2915 // Local linkage must have default visibility.
2916 if (Record.size() > 6 && !GlobalValue::isLocalLinkage(Linkage))
2917 // FIXME: Change to an error if non-default in 4.0.
2918 Visibility = getDecodedVisibility(Record[6]);
2919
2920 GlobalVariable::ThreadLocalMode TLM = GlobalVariable::NotThreadLocal;
2921 if (Record.size() > 7)
2922 TLM = getDecodedThreadLocalMode(Record[7]);
2923
2924 GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None;
2925 if (Record.size() > 8)
2926 UnnamedAddr = getDecodedUnnamedAddrType(Record[8]);
2927
2928 bool ExternallyInitialized = false;
2929 if (Record.size() > 9)
2930 ExternallyInitialized = Record[9];
2931
2932 GlobalVariable *NewGV =
2933 new GlobalVariable(*TheModule, Ty, isConstant, Linkage, nullptr, Name,
2934 nullptr, TLM, AddressSpace, ExternallyInitialized);
2935 NewGV->setAlignment(Alignment);

Callers

nothing calls this directly

Calls 15

getDecodedLinkageFunction · 0.85
getDecodedVisibilityFunction · 0.85
hasImplicitComdatFunction · 0.85
getDecodedDSOLocalFunction · 0.85
inferDSOLocalFunction · 0.85
successFunction · 0.85
isPointerTyMethod · 0.80
setUnnamedAddrMethod · 0.80

Tested by

no test coverage detected