Skip to content

Commit

Permalink
Allow aliases to be unnamed.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
espindola committed Jun 17, 2015
1 parent 3df5dd4 commit 54fc298
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Assembler/unnamed-alias.ll
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 54fc298

Please sign in to comment.