Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

UBSan errors in MC/SystemZ (left shift of negative value) #20979

Closed Quuxplusone closed 8 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR20980
Status RESOLVED FIXED
Importance P normal
Reported by Alexey Samsonov (vonosmas@gmail.com)
Reported on 2014-09-17 15:09:27 -0700
Last modified on 2015-12-02 14:47:37 -0800
Version trunk
Hardware PC Linux
CC ahmed@bougacha.org, llvm-bugs@justinbogner.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks PR20815
Blocked by
See also PR23227
The following SystemZ tests fail under UBSan bootstrap of LLVM:

    LLVM :: MC/SystemZ/insn-bad-z196.s
    LLVM :: MC/SystemZ/insn-bad.s
    LLVM :: MC/SystemZ/insn-good-z196.s
    LLVM :: MC/SystemZ/insn-good.s

The problem seem to be left shifts of negative values in SystemZ, which are
evaluated directly by the MC layer (left shift of negative value is undefined
behavior in C).

Example error report:
llvm/lib/MC/MCExpr.cpp:802:43: runtime error: left shift of negative value -1
    #0 0x104bf21 in llvm::MCExpr::EvaluateAsRelocatableImpl(llvm::MCValue&, llvm::MCAssembler const*, llvm::MCAsmLayout const*, llvm::MCFixup const*, llvm::DenseMap<llvm::MCSectionData const*, unsigned long, llvm::DenseMapInfo<llvm::MCSectionData const*> > const*, bool, bool) const llvm/lib/MC/MCExpr.cpp:802:30
    #1 0x10499f1 in llvm::MCExpr::evaluateAsAbsolute(long&, llvm::MCAssembler const*, llvm::MCAsmLayout const*, llvm::DenseMap<llvm::MCSectionData const*, unsigned long, llvm::DenseMapInfo<llvm::MCSectionData const*> > const*, bool) const llvm/lib/MC/MCExpr.cpp:499:24
    #2 0x10492b1 in llvm::MCExpr::EvaluateAsAbsolute(long&, llvm::MCAssembler const*, llvm::MCAsmLayout const*, llvm::DenseMap<llvm::MCSectionData const*, unsigned long, llvm::DenseMapInfo<llvm::MCSectionData const*> > const*) const llvm/lib/MC/MCExpr.cpp:485:10
    #3 0x1049197 in llvm::MCExpr::EvaluateAsAbsolute(long&) const llvm/lib/MC/MCExpr.cpp:452:10
    #4 0x11ae495 in (anonymous namespace)::AsmParser::parseExpression(llvm::MCExpr const*&, llvm::SMLoc&) llvm/lib/MC/MCParser/AsmParser.cpp:1051:7
    #5 0x12a813b in llvm::MCAsmParser::parseExpression(llvm::MCExpr const*&) llvm/lib/MC/MCParser/MCAsmParser.cpp:43:10
    #6 0xd11359 in (anonymous namespace)::SystemZAsmParser::parseAddress(unsigned int&, llvm::MCExpr const*&, unsigned int&, llvm::MCExpr const*&, unsigned int const*, (anonymous namespace)::RegisterKind) llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp:500:7
    #7 0xd0e9a6 in (anonymous namespace)::SystemZAsmParser::parseOperand(llvm::SmallVectorImpl<std::unique_ptr<llvm::MCParsedAsmOperand, std::default_delete<llvm::MCParsedAsmOperand> > >&, llvm::StringRef) llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp:665:7
    #8 0xcfe697 in (anonymous namespace)::SystemZAsmParser::ParseInstruction(llvm::ParseInstructionInfo&, llvm::StringRef, llvm::SMLoc, llvm::SmallVectorImpl<std::unique_ptr<llvm::MCParsedAsmOperand, std::default_delete<llvm::MCParsedAsmOperand> > >&) llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp:616:11
    #9 0x11c2563 in (anonymous namespace)::AsmParser::parseStatement((anonymous namespace)::ParseStatementInfo&) llvm/lib/MC/MCParser/AsmParser.cpp:1576:19
    #10 0x11a222c in (anonymous namespace)::AsmParser::Run(bool, bool) llvm/lib/MC/MCParser/AsmParser.cpp:643:10
    #11 0x4494f0 in AssembleInput(char const*, llvm::Target const*, llvm::SourceMgr&, llvm::MCContext&, llvm::MCStreamer&, llvm::MCAsmInfo&, llvm::MCSubtargetInfo&, llvm::MCInstrInfo&, llvm::MCTargetOptions&) llvm/tools/llvm-mc/llvm-mc.cpp:338:13
    #12 0x43d4ee in main llvm/tools/llvm-mc/llvm-mc.cpp:486:11
    #13 0x7fc2d9c4676c in __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226
    #14 0x420504 in _start (llvm_ubsan/bin/llvm-mc+0x420504)

To reproduce: build LLVM with just-built Clang and -
DLLVM_USE_SANITIZER=Undefined CMake option. I'm going to disable all MC/SystemZ
tests under UBSan in test/MC/SystemZ/lit.local.cfg, so that suppression will
have to be removed as well.
Quuxplusone commented 9 years ago
I believe this is all fixed by r240420, r240520, and r240634. It works on
Darwin, at least. If nobody gets to it first, I'll commit the following in the
next couple of days when I have a couple of hours to wait for the sanitizer
bots:

diff --git a/test/MC/SystemZ/lit.local.cfg b/test/MC/SystemZ/lit.local.cfg
index 78c5738..2f3cf7d 100644
--- a/test/MC/SystemZ/lit.local.cfg
+++ b/test/MC/SystemZ/lit.local.cfg
@@ -1,6 +1,2 @@
 if not 'SystemZ' in config.root.targets:
     config.unsupported = True
-
-# http://llvm.org/bugs/show_bug.cgi?id=20980
-if 'ubsan' in config.available_features:
-  config.unsupported = True
Quuxplusone commented 8 years ago

Looks like they were fixed indeed! I've submitted your patch in r254542.