[llvm] r224811 - MC: Label definitions are permitted after .set directives
David Majnemer
david.majnemer at gmail.com
Wed Dec 24 02:27:50 PST 2014
Author: majnemer
Date: Wed Dec 24 04:27:50 2014
New Revision: 224811
URL: http://llvm.org/viewvc/llvm-project?rev=224811&view=rev
Log:
MC: Label definitions are permitted after .set directives
.set directives may be overridden by other .set directives as well as
label definitions.
This fixes PR22019.
Added:
llvm/trunk/test/CodeGen/X86/pr22019.ll
Modified:
llvm/trunk/include/llvm/MC/MCSymbol.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/test/MC/ELF/alias.s
Modified: llvm/trunk/include/llvm/MC/MCSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbol.h?rev=224811&r1=224810&r2=224811&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbol.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbol.h Wed Dec 24 04:27:50 2014
@@ -53,6 +53,9 @@ namespace llvm {
/// "Lfoo" or ".foo".
unsigned IsTemporary : 1;
+ /// \brief True if this symbol can be redefined.
+ unsigned IsRedefinable : 1;
+
/// IsUsed - True if this symbol has been used.
mutable unsigned IsUsed : 1;
@@ -61,7 +64,7 @@ namespace llvm {
friend class MCContext;
MCSymbol(StringRef name, bool isTemporary)
: Name(name), Section(nullptr), Value(nullptr),
- IsTemporary(isTemporary), IsUsed(false) {}
+ IsTemporary(isTemporary), IsRedefinable(false), IsUsed(false) {}
MCSymbol(const MCSymbol&) LLVM_DELETED_FUNCTION;
void operator=(const MCSymbol&) LLVM_DELETED_FUNCTION;
@@ -79,6 +82,19 @@ namespace llvm {
bool isUsed() const { return IsUsed; }
void setUsed(bool Value) const { IsUsed = Value; }
+ /// \brief Check if this symbol is redefinable.
+ bool isRedefinable() const { return IsRedefinable; }
+ /// \brief Mark this symbol as redefinable.
+ void setRedefinable(bool Value) { IsRedefinable = Value; }
+ /// \brief Prepare this symbol to be redefined.
+ void redefineIfPossible() {
+ if (IsRedefinable) {
+ Value = nullptr;
+ Section = nullptr;
+ IsRedefinable = false;
+ }
+ }
+
/// @}
/// @name Associated Sections
/// @{
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=224811&r1=224810&r2=224811&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Dec 24 04:27:50 2014
@@ -541,6 +541,8 @@ void AsmPrinter::EmitFunctionHeader() {
/// EmitFunctionEntryLabel - Emit the label that is the entrypoint for the
/// function. This can be overridden by targets as required to do custom stuff.
void AsmPrinter::EmitFunctionEntryLabel() {
+ CurrentFnSym->redefineIfPossible();
+
// The function label could have already been emitted if two symbols end up
// conflicting due to asm renaming. Detect this and emit an error.
if (CurrentFnSym->isUndefined())
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=224811&r1=224810&r2=224811&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Dec 24 04:27:50 2014
@@ -1298,6 +1298,9 @@ bool AsmParser::parseStatement(ParseStat
Sym = getContext().GetOrCreateSymbol(IDVal);
} else
Sym = Ctx.CreateDirectionalLocalSymbol(LocalLabelVal);
+
+ Sym->redefineIfPossible();
+
if (!Sym->isUndefined() || Sym->isVariable())
return Error(IDLoc, "invalid symbol redefinition");
@@ -2217,6 +2220,8 @@ bool AsmParser::parseAssignment(StringRe
} else
Sym = getContext().GetOrCreateSymbol(Name);
+ Sym->setRedefinable(allow_redef);
+
// Do the assignment.
Out.EmitAssignment(Sym, Value);
if (NoDeadStrip)
Added: llvm/trunk/test/CodeGen/X86/pr22019.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr22019.ll?rev=224811&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr22019.ll (added)
+++ llvm/trunk/test/CodeGen/X86/pr22019.ll Wed Dec 24 04:27:50 2014
@@ -0,0 +1,12 @@
+; RUN: llc < %s | FileCheck %s
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+module asm "pselect = __pselect"
+; CHECK: pselect = __pselect
+
+; CHECK: pselect:
+; CHECK: retq
+define void @pselect() {
+ ret void
+}
Modified: llvm/trunk/test/MC/ELF/alias.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/alias.s?rev=224811&r1=224810&r2=224811&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/alias.s (original)
+++ llvm/trunk/test/MC/ELF/alias.s Wed Dec 24 04:27:50 2014
@@ -20,6 +20,10 @@ bar5 = bar4
.long foo2
+// Test that bar6 is a function that doesn't have the same value as foo4.
+bar6 = bar5
+bar6:
+
// CHECK: Symbols [
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: (0)
@@ -57,6 +61,15 @@ bar5 = bar4
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: bar6
+// CHECK-NEXT: Value: 0x5
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local
+// CHECK-NEXT: Type: None
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: .text
+// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: foo
// CHECK-NEXT: Value: 0x0
More information about the llvm-commits
mailing list