diff options
author | Ben Dunbobbin <Ben.Dunbobbin@sony.com> | 2022-09-30 00:21:31 +0100 |
---|---|---|
committer | Ben Dunbobbin <Ben.Dunbobbin@sony.com> | 2022-09-30 00:26:01 +0100 |
commit | 7eee2a2d4401813cd485ae708e8cb0f94469e037 (patch) | |
tree | e7f241a8ee6c5a7df2cf74cfd72cdff62ff7b70c /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 0bfaa301e28dacc9b79ecdff12254439e2e8458a (diff) | |
download | llvm-7eee2a2d4401813cd485ae708e8cb0f94469e037.zip llvm-7eee2a2d4401813cd485ae708e8cb0f94469e037.tar.gz llvm-7eee2a2d4401813cd485ae708e8cb0f94469e037.tar.bz2 |
[IR] Don't allow DLL storage-class and local linkage
Disallow this meaningless combination. Doing so simplifies analysis
of LLVM code w.r.t t DLL storage-class, and prevents mistakes with
DLL storage class.
- Change the assembler to reject DLL storage class on symbols with
local linkage.
- Change the bitcode reader to clear the DLL Storage class when the
linkage is local for auto-upgrading
- Update LangRef.
There is an existing restriction on non-default visibility and local
linkage which this is modelled on.
Differential Review: https://reviews.llvm.org/D134784
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 0ed0614..bfce79c 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1298,6 +1298,9 @@ static FastMathFlags getDecodedFastMathFlags(unsigned Val) { } static void upgradeDLLImportExportLinkage(GlobalValue *GV, unsigned Val) { + // A GlobalValue with local linkage cannot have a DLL storage class. + if (GV->hasLocalLinkage()) + return; switch (Val) { case 5: GV->setDLLStorageClass(GlobalValue::DLLImportStorageClass); break; case 6: GV->setDLLStorageClass(GlobalValue::DLLExportStorageClass); break; @@ -3764,10 +3767,14 @@ Error BitcodeReader::parseGlobalVarRecord(ArrayRef<uint64_t> Record) { NewGV->setVisibility(Visibility); NewGV->setUnnamedAddr(UnnamedAddr); - if (Record.size() > 10) - NewGV->setDLLStorageClass(getDecodedDLLStorageClass(Record[10])); - else + if (Record.size() > 10) { + // A GlobalValue with local linkage cannot have a DLL storage class. + if (!NewGV->hasLocalLinkage()) { + NewGV->setDLLStorageClass(getDecodedDLLStorageClass(Record[10])); + } + } else { upgradeDLLImportExportLinkage(NewGV, RawLinkage); + } ValueList.push_back(NewGV, getVirtualTypeID(NewGV->getType(), TyID)); @@ -3928,10 +3935,14 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) { if (Record.size() > 10) OperandInfo.Prologue = Record[10]; - if (Record.size() > 11) - Func->setDLLStorageClass(getDecodedDLLStorageClass(Record[11])); - else + if (Record.size() > 11) { + // A GlobalValue with local linkage cannot have a DLL storage class. + if (!Func->hasLocalLinkage()) { + Func->setDLLStorageClass(getDecodedDLLStorageClass(Record[11])); + } + } else { upgradeDLLImportExportLinkage(Func, RawLinkage); + } if (Record.size() > 12) { if (unsigned ComdatID = Record[12]) { @@ -4034,8 +4045,12 @@ Error BitcodeReader::parseGlobalIndirectSymbolRecord( } if (BitCode == bitc::MODULE_CODE_ALIAS || BitCode == bitc::MODULE_CODE_ALIAS_OLD) { - if (OpNum != Record.size()) - NewGA->setDLLStorageClass(getDecodedDLLStorageClass(Record[OpNum++])); + if (OpNum != Record.size()) { + auto S = Record[OpNum++]; + // A GlobalValue with local linkage cannot have a DLL storage class. + if (!NewGA->hasLocalLinkage()) + NewGA->setDLLStorageClass(getDecodedDLLStorageClass(S)); + } else upgradeDLLImportExportLinkage(NewGA, Linkage); if (OpNum != Record.size()) |