diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-17 17:53:31 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-06-17 17:53:31 +0000 |
| commit | 54fc298bbc2e0a99800e86ec9464d92a7b8f6337 (patch) | |
| tree | 91b8b95cbf2797151952c7026619e723e6f6b9c1 | |
| parent | 3df5dd4de79daab1da83119430f8396af783fd1f (diff) | |
| download | bcm5719-llvm-54fc298bbc2e0a99800e86ec9464d92a7b8f6337.tar.gz bcm5719-llvm-54fc298bbc2e0a99800e86ec9464d92a7b8f6337.zip | |
Allow aliases to be unnamed.
If globals can be unnamed, there is no reason for aliases to be different.
The restriction was there since the original implementation in r36435. I
can only guess it was there because of the old bison parser for the old
alias syntax.
llvm-svn: 239921
| -rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 15 | ||||
| -rw-r--r-- | llvm/lib/IR/Verifier.cpp | 1 | ||||
| -rw-r--r-- | llvm/test/Assembler/unnamed-alias.ll | 11 |
4 files changed, 22 insertions, 8 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 0b6740dba3b..064b74304a9 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -670,6 +670,9 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc, unsigned L, GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass); GA->setUnnamedAddr(UnnamedAddr); + if (Name.empty()) + NumberedVals.push_back(GA.get()); + // See if this value already exists in the symbol table. If so, it is either // a redefinition or a definition of a forward reference. if (GlobalValue *Val = M->getNamedValue(Name)) { diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 611acc68845..05f7e08555f 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -730,6 +730,11 @@ void SlotTracker::processModule() { CreateModuleSlot(&Var); } + for (const GlobalAlias &A : TheModule->aliases()) { + if (!A.hasName()) + CreateModuleSlot(&A); + } + // Add metadata used by named metadata. for (const NamedMDNode &NMD : TheModule->named_metadata()) { for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) @@ -2356,13 +2361,9 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) { if (GA->isMaterializable()) Out << "; Materializable\n"; - // Don't crash when dumping partially built GA - if (!GA->hasName()) - Out << "<<nameless>> = "; - else { - PrintLLVMName(Out, GA); - Out << " = "; - } + WriteAsOperandInternal(Out, GA, &TypePrinter, &Machine, GA->getParent()); + Out << " = "; + PrintLinkage(GA->getLinkage(), Out); PrintVisibility(GA->getVisibility(), Out); PrintDLLStorageClass(GA->getDLLStorageClass(), Out); diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 5fac05527bb..13b451a06b2 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -584,7 +584,6 @@ void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited, } void Verifier::visitGlobalAlias(const GlobalAlias &GA) { - Assert(!GA.getName().empty(), "Alias name cannot be empty!", &GA); Assert(GlobalAlias::isValidLinkage(GA.getLinkage()), "Alias should have private, internal, linkonce, weak, linkonce_odr, " "weak_odr, or external linkage!", diff --git a/llvm/test/Assembler/unnamed-alias.ll b/llvm/test/Assembler/unnamed-alias.ll new file mode 100644 index 00000000000..8ae1c45d312 --- /dev/null +++ b/llvm/test/Assembler/unnamed-alias.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s + +@0 = private constant i32 0 +; CHECK: @0 = private constant i32 0 +@1 = private constant i32 1 +; CHECK: @1 = private constant i32 1 + +@2 = private alias i32* @0 +; CHECK: @2 = private alias i32* @0 +@3 = private alias i32* @1 +; CHECK: @3 = private alias i32* @1 |

