@@ -52,8 +52,8 @@ void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
5252 MCInst &Inst = *It;
5353 if (BC.MIB ->isCFI (Inst))
5454 continue ;
55- auto RAState = BC.MIB ->getRAState (Inst);
56- if (!RAState) {
55+ std::optional< bool > RAState = BC.MIB ->getRAState (Inst);
56+ if (!RAState. has_value () ) {
5757 BC.errs () << " BOLT-ERROR: unknown RAState after inferUnknownStates "
5858 << " in function " << BF.getPrintName () << " \n " ;
5959 PassFailed = true ;
@@ -106,8 +106,8 @@ void InsertNegateRAState::coverFunctionFragmentStart(BinaryFunction &BF,
106106 // If a function is already split in the input, the first FF can also start
107107 // with Signed state. This covers that scenario as well.
108108 auto II = (*FirstNonEmpty)->getFirstNonPseudo ();
109- auto RAState = BC.MIB ->getRAState (*II);
110- if (!RAState) {
109+ std::optional< bool > RAState = BC.MIB ->getRAState (*II);
110+ if (!RAState. has_value () ) {
111111 BC.errs () << " BOLT-ERROR: unknown RAState after inferUnknownStates "
112112 << " in function " << BF.getPrintName () << " \n " ;
113113 PassFailed = true ;
@@ -124,8 +124,8 @@ InsertNegateRAState::getFirstKnownRAState(BinaryContext &BC,
124124 for (const MCInst &Inst : BB) {
125125 if (BC.MIB ->isCFI (Inst))
126126 continue ;
127- auto RAStateOpt = BC.MIB ->getRAState (Inst);
128- if (RAStateOpt)
127+ std::optional< bool > RAStateOpt = BC.MIB ->getRAState (Inst);
128+ if (RAStateOpt. has_value () )
129129 return RAStateOpt;
130130 }
131131 return std::nullopt ;
@@ -139,8 +139,8 @@ void InsertNegateRAState::fillUnknownStateInBB(BinaryContext &BC,
139139 return ;
140140 // If the first instruction has unknown RAState, we should copy the first
141141 // known RAState.
142- auto RAStateOpt = BC.MIB ->getRAState (*First);
143- if (!RAStateOpt) {
142+ std::optional< bool > RAStateOpt = BC.MIB ->getRAState (*First);
143+ if (!RAStateOpt. has_value () ) {
144144 auto FirstRAState = getFirstKnownRAState (BC, BB);
145145 if (!FirstRAState)
146146 // We fill unknown BBs later.
@@ -160,7 +160,7 @@ void InsertNegateRAState::fillUnknownStateInBB(BinaryContext &BC,
160160 // No need to check for nullopt: we only entered this loop after the first
161161 // instruction had its RAState set, and RAState is always set for the
162162 // previous instruction in the previous iteration of the loop.
163- auto PrevRAState = BC.MIB ->getRAState (Prev);
163+ std::optional< bool > PrevRAState = BC.MIB ->getRAState (Prev);
164164
165165 auto RAState = BC.MIB ->getRAState (Inst);
166166 if (!RAState) {
@@ -179,8 +179,8 @@ bool InsertNegateRAState::isUnknownBlock(BinaryContext &BC,
179179 for (const MCInst &Inst : BB) {
180180 if (BC.MIB ->isCFI (Inst))
181181 continue ;
182- auto RAState = BC.MIB ->getRAState (Inst);
183- if (RAState)
182+ std::optional< bool > RAState = BC.MIB ->getRAState (Inst);
183+ if (RAState. has_value () )
184184 return false ;
185185 }
186186 return true ;
@@ -206,10 +206,12 @@ void InsertNegateRAState::fillUnknownStubs(BinaryFunction &BF) {
206206 for (FunctionFragment &FF : BF.getLayout ().fragments ()) {
207207 for (BinaryBasicBlock *BB : FF) {
208208 if (!FirstIter && isUnknownBlock (BC, *BB)) {
209- // As of #160989, we have to copy the
210- // PrevInst's RAState, because CFIs are already incorrect here.
211- auto PrevRAState = BC.MIB ->getRAState (PrevInst);
212- if (!PrevRAState) {
209+ // As exlained in issue #160989, the unwind info is incorrect for stubs.
210+ // Indicating the correct RAState without the rest of the unwind info
211+ // being correct is not useful. Instead, we copy the RAState from the
212+ // previous instruction.
213+ std::optional<bool > PrevRAState = BC.MIB ->getRAState (PrevInst);
214+ if (!PrevRAState.has_value ()) {
213215 llvm_unreachable (
214216 " Previous Instruction has no RAState in fillUnknownStubs." );
215217 continue ;
0 commit comments