[llvm] r233155 - Produce an error instead of asserting on invalid .sleb128/.uleb128.
Rafael Espindola
rafael.espindola at gmail.com
Tue Mar 24 17:25:38 PDT 2015
Author: rafael
Date: Tue Mar 24 19:25:37 2015
New Revision: 233155
URL: http://llvm.org/viewvc/llvm-project?rev=233155&view=rev
Log:
Produce an error instead of asserting on invalid .sleb128/.uleb128.
Added:
llvm/trunk/test/MC/X86/invalid-sleb.s
Modified:
llvm/trunk/include/llvm/MC/MCExpr.h
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/MC/MCExpr.cpp
Modified: llvm/trunk/include/llvm/MC/MCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCExpr.h?rev=233155&r1=233154&r2=233155&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCExpr.h (original)
+++ llvm/trunk/include/llvm/MC/MCExpr.h Tue Mar 24 19:25:37 2015
@@ -94,7 +94,7 @@ public:
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
- int64_t evaluateKnownAbsolute(const MCAsmLayout &Layout) const;
+ bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
/// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
/// value, i.e. an expression of the fixed form (a - b + constant).
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=233155&r1=233154&r2=233155&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Tue Mar 24 19:25:37 2015
@@ -1034,7 +1034,10 @@ bool MCAssembler::relaxInstruction(MCAsm
bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
uint64_t OldSize = LF.getContents().size();
- int64_t Value = LF.getValue().evaluateKnownAbsolute(Layout);
+ int64_t Value;
+ bool Abs = LF.getValue().evaluateKnownAbsolute(Value, Layout);
+ if (!Abs)
+ report_fatal_error("sleb128 and uleb128 expressions must be absolute");
SmallString<8> &Data = LF.getContents();
Data.clear();
raw_svector_ostream OSE(Data);
@@ -1050,7 +1053,9 @@ bool MCAssembler::relaxDwarfLineAddr(MCA
MCDwarfLineAddrFragment &DF) {
MCContext &Context = Layout.getAssembler().getContext();
uint64_t OldSize = DF.getContents().size();
- int64_t AddrDelta = DF.getAddrDelta().evaluateKnownAbsolute(Layout);
+ int64_t AddrDelta;
+ bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
+ assert(Abs && "We created a line delta with an invalid expression");
int64_t LineDelta;
LineDelta = DF.getLineDelta();
SmallString<8> &Data = DF.getContents();
@@ -1065,7 +1070,9 @@ bool MCAssembler::relaxDwarfCallFrameFra
MCDwarfCallFrameFragment &DF) {
MCContext &Context = Layout.getAssembler().getContext();
uint64_t OldSize = DF.getContents().size();
- int64_t AddrDelta = DF.getAddrDelta().evaluateKnownAbsolute(Layout);
+ int64_t AddrDelta;
+ bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
+ assert(Abs && "We created call frame with an invalid expression");
SmallString<8> &Data = DF.getContents();
Data.clear();
raw_svector_ostream OSE(Data);
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=233155&r1=233154&r2=233155&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Tue Mar 24 19:25:37 2015
@@ -406,13 +406,10 @@ bool MCExpr::EvaluateAsAbsolute(int64_t
return EvaluateAsAbsolute(Res, &Asm, nullptr, nullptr);
}
-int64_t MCExpr::evaluateKnownAbsolute(const MCAsmLayout &Layout) const {
- int64_t Res;
- bool Abs =
- evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, true);
- (void)Abs;
- assert(Abs && "Not actually absolute");
- return Res;
+bool MCExpr::evaluateKnownAbsolute(int64_t &Res,
+ const MCAsmLayout &Layout) const {
+ return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr,
+ true);
}
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
Added: llvm/trunk/test/MC/X86/invalid-sleb.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/invalid-sleb.s?rev=233155&view=auto
==============================================================================
--- llvm/trunk/test/MC/X86/invalid-sleb.s (added)
+++ llvm/trunk/test/MC/X86/invalid-sleb.s Tue Mar 24 19:25:37 2015
@@ -0,0 +1,5 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux %s -o %t 2>&1 | FileCheck %s
+
+// CHECK: sleb128 and uleb128 expressions must be absolute
+
+ .sleb128 undefined
More information about the llvm-commits
mailing list