diff --git a/llvm/lib/AsmParser/LLParser.h b/llvm/lib/AsmParser/LLParser.h --- a/llvm/lib/AsmParser/LLParser.h +++ b/llvm/lib/AsmParser/LLParser.h @@ -276,8 +276,8 @@ bool ParseOptionalReturnAttrs(AttrBuilder &B); bool ParseOptionalLinkage(unsigned &Res, bool &HasLinkage, unsigned &Visibility, unsigned &DLLStorageClass, - bool &DSOLocal); - void ParseOptionalDSOLocal(bool &DSOLocal); + bool &ExplicitDSOPreemption, bool &DSOLocal); + void ParseOptionalDSOLocal(bool &ExplicitDSOPreemption, bool &DSOLocal); void ParseOptionalVisibility(unsigned &Res); void ParseOptionalDLLStorageClass(unsigned &Res); bool ParseOptionalCallingConv(unsigned &CC); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -565,11 +565,11 @@ bool HasLinkage; unsigned Linkage, Visibility, DLLStorageClass; - bool DSOLocal; + bool ExplicitDSOPreemption, DSOLocal; GlobalVariable::ThreadLocalMode TLM; GlobalVariable::UnnamedAddr UnnamedAddr; if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass, - DSOLocal) || + ExplicitDSOPreemption, DSOLocal) || ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr)) return true; @@ -594,12 +594,12 @@ bool HasLinkage; unsigned Linkage, Visibility, DLLStorageClass; - bool DSOLocal; + bool ExplicitDSOPreemption, DSOLocal; GlobalVariable::ThreadLocalMode TLM; GlobalVariable::UnnamedAddr UnnamedAddr; if (ParseToken(lltok::equal, "expected '=' in global variable") || ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass, - DSOLocal) || + ExplicitDSOPreemption, DSOLocal) || ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr)) return true; @@ -1844,11 +1844,12 @@ bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage, unsigned &Visibility, unsigned &DLLStorageClass, + bool &ExplicitDSOPreemption, bool &DSOLocal) { Res = parseOptionalLinkageAux(Lex.getKind(), HasLinkage); if (HasLinkage) Lex.Lex(); - ParseOptionalDSOLocal(DSOLocal); + ParseOptionalDSOLocal(ExplicitDSOPreemption, DSOLocal); ParseOptionalVisibility(Visibility); ParseOptionalDLLStorageClass(DLLStorageClass); @@ -1859,16 +1860,19 @@ return false; } -void LLParser::ParseOptionalDSOLocal(bool &DSOLocal) { +void LLParser::ParseOptionalDSOLocal(bool &ExplicitDSOPreemption, bool &DSOLocal) { switch (Lex.getKind()) { default: + ExplicitDSOPreemption = false; DSOLocal = false; break; case lltok::kw_dso_local: + ExplicitDSOPreemption = true; DSOLocal = true; Lex.Lex(); break; case lltok::kw_dso_preemptable: + ExplicitDSOPreemption = true; DSOLocal = false; Lex.Lex(); break; @@ -5324,14 +5328,14 @@ unsigned Linkage; unsigned Visibility; unsigned DLLStorageClass; - bool DSOLocal; + bool ExplicitDSOPreemption, DSOLocal; AttrBuilder RetAttrs; unsigned CC; bool HasLinkage; Type *RetType = nullptr; LocTy RetTypeLoc = Lex.getLoc(); if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass, - DSOLocal) || + ExplicitDSOPreemption, DSOLocal) || ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) || ParseType(RetType, RetTypeLoc, true /*void allowed*/)) return true; @@ -5504,7 +5508,7 @@ NumberedVals.push_back(Fn); Fn->setLinkage((GlobalValue::LinkageTypes)Linkage); - maybeSetDSOLocal(DSOLocal, *Fn); + Fn->setDSOLocal(ExplicitDSOPreemption ? DSOLocal : isDefine); Fn->setVisibility((GlobalValue::VisibilityTypes)Visibility); Fn->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass); Fn->setCallingConv(CC); diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -3218,8 +3218,15 @@ static void PrintDSOLocation(const GlobalValue &GV, formatted_raw_ostream &Out) { - if (GV.isDSOLocal() && !GV.isImplicitDSOLocal()) - Out << "dso_local "; + bool Default = + GV.isImplicitDSOLocal() || (isa(GV) && !GV.isDeclaration()); + if (GV.isDSOLocal()) { + if (!Default) + Out << "dso_local "; + } else { + if (Default) + Out << "dso_preemptable "; + } } static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT,