Skip to content

MC,AsmPrinter: Report redefinition error instead of crashing in more cases #145460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,13 +1081,6 @@ void AsmPrinter::emitFunctionHeader() {
/// 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->isVariable())
report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
"' is a protected alias");

OutStreamer->emitLabel(CurrentFnSym);

if (TM.getTargetTriple().isOSBinFormatELF()) {
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ void MCAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
// FIXME: Fix CodeGen/AArch64/arm64ec-varargs.ll. emitLabel is followed by
// setVariableValue, leading to an assertion failure if setOffset(0) is
// called.
if (getContext().getObjectFileType() != MCContext::IsCOFF)
if (!Symbol->isVariable() &&
getContext().getObjectFileType() != MCContext::IsCOFF)
Symbol->setOffset(0);

Symbol->print(OS, MAI);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/MC/MCObjectStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ void MCObjectStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {

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

getAssembler().registerSymbol(*Symbol);

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/X86/equiv_with_fndef.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: not --crash llc < %s 2>&1 | FileCheck %s
; RUN: not llc < %s 2>&1 | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

Expand All @@ -7,4 +7,4 @@ module asm ".equiv pselect, __pselect"
define void @pselect() {
ret void
}
; CHECK: 'pselect' is a protected alias
; CHECK: <unknown>:0: error: symbol 'pselect' is already defined
4 changes: 4 additions & 0 deletions llvm/test/MC/AsmParser/redef-err.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ l:

.equiv a, undef
# CHECK: [[#@LINE-1]]:11: error: redefinition of 'a'

.equiv b, undef
b:
# CHECK: [[#@LINE-1]]:1: error: symbol 'b' is already defined
Loading