llvm.org GIT mirror llvm / 7e2b51d
[MC] Don't crash when .word is given bogus values We didn't validate that the .word directive was given a sane value, leading to crashes when we attempt to write out the object file. Instead, perform some validation and issue a diagnostic pointing at the start of the diagnostic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251270 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
3 changed file(s) with 23 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
17291729 if (getLexer().isNot(AsmToken::EndOfStatement)) {
17301730 for (;;) {
17311731 const MCExpr *Value;
1732 SMLoc ExprLoc = getLexer().getLoc();
17321733 if (getParser().parseExpression(Value))
17331734 return false;
17341735
1735 getParser().getStreamer().EmitValue(Value, Size);
1736 if (const auto *MCE = dyn_cast(Value)) {
1737 assert(Size <= 8 && "Invalid size");
1738 uint64_t IntValue = MCE->getValue();
1739 if (!isUIntN(8 * Size, IntValue) && !isIntN(8 * Size, IntValue))
1740 return Error(ExprLoc, "literal value out of range for directive");
1741 getStreamer().EmitIntValue(IntValue, Size);
1742 } else {
1743 getStreamer().EmitValue(Value, Size, ExprLoc);
1744 }
17361745
17371746 if (getLexer().is(AsmToken::EndOfStatement))
17381747 break;
28302830 if (getLexer().isNot(AsmToken::EndOfStatement)) {
28312831 for (;;) {
28322832 const MCExpr *Value;
2833 SMLoc ExprLoc = getLexer().getLoc();
28332834 if (getParser().parseExpression(Value))
28342835 return false;
28352836
2836 getParser().getStreamer().EmitValue(Value, Size);
2837 if (const auto *MCE = dyn_cast(Value)) {
2838 assert(Size <= 8 && "Invalid size");
2839 uint64_t IntValue = MCE->getValue();
2840 if (!isUIntN(8 * Size, IntValue) && !isIntN(8 * Size, IntValue))
2841 return Error(ExprLoc, "literal value out of range for directive");
2842 getStreamer().EmitIntValue(IntValue, Size);
2843 } else {
2844 getStreamer().EmitValue(Value, Size, ExprLoc);
2845 }
28372846
28382847 if (getLexer().is(AsmToken::EndOfStatement))
28392848 break;
1111
1212 // CHECK-ERRORS: error: literal value out of range for directive
1313 .long 4e71cf69 // double floating point constant due to missing "0x"
14
15 // CHECK-ERRORS: error: literal value out of range for directive
16 .word 0xfffffffff