File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -1537,7 +1537,13 @@ const Init *BinOpInit::Fold(const Record *CurRec) const {
15371537 if (LHSi && RHSi) {
15381538 int64_t LHSv = LHSi->getValue (), RHSv = RHSi->getValue ();
15391539 int64_t Result;
1540- switch (getOpcode ()) {
1540+
1541+ unsigned Opc = getOpcode ();
1542+ if ((Opc == SHL || Opc == SRA || Opc == SRL) && (RHSv < 0 || RHSv >= 64 ))
1543+ PrintFatalError (CurRec->getLoc (),
1544+ " Illegal operation: out of bounds shift" );
1545+
1546+ switch (Opc) {
15411547 default : llvm_unreachable (" Bad opcode!" );
15421548 case ADD: Result = LHSv + RHSv; break ;
15431549 case SUB: Result = LHSv - RHSv; break ;
@@ -1556,7 +1562,7 @@ const Init *BinOpInit::Fold(const Record *CurRec) const {
15561562 case OR: Result = LHSv | RHSv; break ;
15571563 case XOR: Result = LHSv ^ RHSv; break ;
15581564 case SHL: Result = (uint64_t )LHSv << (uint64_t )RHSv; break ;
1559- case SRA: Result = LHSv >> RHSv; break ;
1565+ case SRA: Result = LHSv >> ( uint64_t ) RHSv; break ;
15601566 case SRL: Result = (uint64_t )LHSv >> (uint64_t )RHSv; break ;
15611567 }
15621568 return IntInit::get (getRecordKeeper (), Result);
You can’t perform that action at this time.
0 commit comments