Skip to content

Commit 290fc1e

Browse files
authored
MC,AsmPrinter: Report redefinition error instead of crashing in more cases
* Fix the crash for `.equiv b, undef; b:` (.equiv equates a symbol to an expression and reports an error if the symbol was already defined). * Remove redundant isVariable check from emitFunctionEntryLabel Pull Request: #145460
1 parent d31ba52 commit 290fc1e

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,13 +1081,6 @@ void AsmPrinter::emitFunctionHeader() {
10811081
/// function. This can be overridden by targets as required to do custom stuff.
10821082
void AsmPrinter::emitFunctionEntryLabel() {
10831083
CurrentFnSym->redefineIfPossible();
1084-
1085-
// The function label could have already been emitted if two symbols end up
1086-
// conflicting due to asm renaming. Detect this and emit an error.
1087-
if (CurrentFnSym->isVariable())
1088-
report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
1089-
"' is a protected alias");
1090-
10911084
OutStreamer->emitLabel(CurrentFnSym);
10921085

10931086
if (TM.getTargetTriple().isOSBinFormatELF()) {

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ void MCAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
569569
// FIXME: Fix CodeGen/AArch64/arm64ec-varargs.ll. emitLabel is followed by
570570
// setVariableValue, leading to an assertion failure if setOffset(0) is
571571
// called.
572-
if (getContext().getObjectFileType() != MCContext::IsCOFF)
572+
if (!Symbol->isVariable() &&
573+
getContext().getObjectFileType() != MCContext::IsCOFF)
573574
Symbol->setOffset(0);
574575

575576
Symbol->print(OS, MAI);

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ void MCObjectStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
225225

226226
void MCObjectStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
227227
MCStreamer::emitLabel(Symbol, Loc);
228+
// If Symbol is a non-redefiniable variable, emitLabel has reported an error.
229+
// Bail out.
230+
if (Symbol->isVariable())
231+
return;
228232

229233
getAssembler().registerSymbol(*Symbol);
230234

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: not --crash llc < %s 2>&1 | FileCheck %s
1+
; RUN: not llc < %s 2>&1 | FileCheck %s
22
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
33
target triple = "x86_64-unknown-linux-gnu"
44

@@ -7,4 +7,4 @@ module asm ".equiv pselect, __pselect"
77
define void @pselect() {
88
ret void
99
}
10-
; CHECK: 'pselect' is a protected alias
10+
; CHECK: <unknown>:0: error: symbol 'pselect' is already defined

llvm/test/MC/AsmParser/redef-err.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ l:
1212

1313
.equiv a, undef
1414
# CHECK: [[#@LINE-1]]:11: error: redefinition of 'a'
15+
16+
.equiv b, undef
17+
b:
18+
# CHECK: [[#@LINE-1]]:1: error: symbol 'b' is already defined

0 commit comments

Comments
 (0)