forked from OSchip/llvm-project
[AsmPrinter] Move lowerConstant() error code out of switch (NFC)
Move this out of the switch, so that different branches can indicate an error by breaking out of the switch. This becomes important if there are more than the two current error cases.
This commit is contained in:
parent
d883a4ad02
commit
c2be703c6c
|
@ -2731,6 +2731,8 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) {
|
|||
// to represent relocations on supported targets. Expressions involving only
|
||||
// constant addresses are constant folded instead.
|
||||
switch (CE->getOpcode()) {
|
||||
default:
|
||||
break; // Error
|
||||
case Instruction::AddrSpaceCast: {
|
||||
const Constant *Op = CE->getOperand(0);
|
||||
unsigned DstAS = CE->getType()->getPointerAddressSpace();
|
||||
|
@ -2738,24 +2740,7 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) {
|
|||
if (TM.isNoopAddrSpaceCast(SrcAS, DstAS))
|
||||
return lowerConstant(Op);
|
||||
|
||||
// Fallthrough to error.
|
||||
LLVM_FALLTHROUGH;
|
||||
}
|
||||
default: {
|
||||
// If the code isn't optimized, there may be outstanding folding
|
||||
// opportunities. Attempt to fold the expression using DataLayout as a
|
||||
// last resort before giving up.
|
||||
Constant *C = ConstantFoldConstant(CE, getDataLayout());
|
||||
if (C != CE)
|
||||
return lowerConstant(C);
|
||||
|
||||
// Otherwise report the problem to the user.
|
||||
std::string S;
|
||||
raw_string_ostream OS(S);
|
||||
OS << "Unsupported expression in static initializer: ";
|
||||
CE->printAsOperand(OS, /*PrintType=*/false,
|
||||
!MF ? nullptr : MF->getFunction().getParent());
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
break; // Error
|
||||
}
|
||||
case Instruction::GetElementPtr: {
|
||||
// Generate a symbolic expression for the byte address
|
||||
|
@ -2860,6 +2845,21 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) {
|
|||
return MCBinaryExpr::createAdd(LHS, RHS, Ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// If the code isn't optimized, there may be outstanding folding
|
||||
// opportunities. Attempt to fold the expression using DataLayout as a
|
||||
// last resort before giving up.
|
||||
Constant *C = ConstantFoldConstant(CE, getDataLayout());
|
||||
if (C != CE)
|
||||
return lowerConstant(C);
|
||||
|
||||
// Otherwise report the problem to the user.
|
||||
std::string S;
|
||||
raw_string_ostream OS(S);
|
||||
OS << "Unsupported expression in static initializer: ";
|
||||
CE->printAsOperand(OS, /*PrintType=*/false,
|
||||
!MF ? nullptr : MF->getFunction().getParent());
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
|
||||
static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C,
|
||||
|
|
Loading…
Reference in New Issue