llvm.org GIT mirror llvm / 3fed2f1
Recommitted fix for PR18931, with extended tests set. Issue subject: Crash using integrated assembler with immediate arithmetic Fix description: Expressions like 'cmp r0, #(l1 - l2) >> 3' could not be evaluated on asm parsing stage, since it is impossible to resolve labels on this stage. In the end of stage we still have expression (MCExpr). Then, when we want to encode it, we expect it to be an immediate, but it still an expression. Patch introduces a Fixup (MCFixup instance), that is processed after main encoding stage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205094 91177308-0d34-0410-b5e6-96231b3b80d8 Stepan Dyatkovskiy 6 years ago
7 changed file(s) with 52 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
93589358 const MCExpr *SOExpr = Op->getImm();
93599359 int64_t Value;
93609360 if (!SOExpr->EvaluateAsAbsolute(Value))
9361 return Match_InvalidOperand;
9361 return Match_Success;
93629362 assert((Value >= INT32_MIN && Value <= INT32_MAX) &&
93639363 "expression value must be representiable in 32 bits");
93649364 }
271271 unsigned getSOImmOpValue(const MCInst &MI, unsigned Op,
272272 SmallVectorImpl &Fixups,
273273 const MCSubtargetInfo &STI) const {
274 unsigned SoImm = MI.getOperand(Op).getImm();
274
275 const MCOperand &MO = MI.getOperand(Op);
276
277 // We expect MO to be an immediate or an expression,
278 // if it is an immediate - that's fine, just encode the value.
279 // Otherwise - create a Fixup.
280 if (MO.isExpr()) {
281 const MCExpr *Expr = MO.getExpr();
282 // In instruction code this value always encoded as lowest 12 bits,
283 // so we don't have to perform any specific adjustments.
284 // Due to requirements of relocatable records we have to use FK_Data_4.
285 // See ARMELFObjectWriter::ExplicitRelSym and
286 // ARMELFObjectWriter::GetRelocTypeInner for more details.
287 MCFixupKind Kind = MCFixupKind(FK_Data_4);
288 Fixups.push_back(MCFixup::Create(0, Expr, Kind, MI.getLoc()));
289 return 0;
290 }
291
292 unsigned SoImm = MO.getImm();
275293 int SoImmVal = ARM_AM::getSOImmVal(SoImm);
276294 assert(SoImmVal != -1 && "Not a valid so_imm value!");
277295
0 @ RUN: not llvm-mc -triple=arm-linux-gnueabi -filetype=obj < %s 2>&1 | FileCheck %s
1
2 .text
3 cmp r0, #(l1 - unknownLabel + 4) >> 2
4 @ CHECK: error: expected relocatable expression
5
6 l1:
0 @ RUN: not llvm-mc -triple=arm-linux-gnueabi -filetype=obj < %s 2>&1 | FileCheck %s
1
2 .text
3 cmp r0, #(l1 - unknownLabel)
4 @ CHECK: error: symbol 'unknownLabel' can not be undefined in a subtraction expression
5
6 l1:
0 @ PR18931
1 @ RUN: llvm-mc < %s -triple=arm-linux-gnueabi -filetype=obj -o - \
2 @ RUN: | llvm-objdump --disassemble -arch=arm - | FileCheck %s
3
4 .text
5 @ CHECK: cmp r2, #1
6 cmp r2, #(l2 - l1 + 4) >> 2
7 l1:
8 l2:
0 @ PR18931
1 @ RUN: llvm-mc < %s -triple=arm-linux-gnueabi -filetype=obj -o - \
2 @ RUN: | llvm-objdump --disassemble -arch=arm - | FileCheck %s
3
4 .text
5 @ CHECK: cmp r2, #0
6 cmp r2, #(l2 - l1)
7 l1:
8 l2:
+0
-8
test/MC/ARM/label_offset.s less more
None @ RUN: not llvm-mc -triple=armv7-linux-gnuabi -filetype=obj < %s 2>&1 | FileCheck %s
1
2 .text
3 cmp r2, #(l2 - l1) >> 6
4 @ CHECK: error: invalid operand for instruction
5
6 l1:
7 l2: