@@ -131,6 +131,12 @@ InsertNegateRAState::getFirstKnownRAState(BinaryContext &BC,
131131 return std::nullopt ;
132132}
133133
134+ bool InsertNegateRAState::isUnknownBlock (BinaryContext &BC,
135+ BinaryBasicBlock &BB) {
136+ std::optional<bool > FirstRAState = getFirstKnownRAState (BC, BB);
137+ return !FirstRAState.has_value ();
138+ }
139+
134140void InsertNegateRAState::fillUnknownStateInBB (BinaryContext &BC,
135141 BinaryBasicBlock &BB) {
136142
@@ -174,18 +180,6 @@ void InsertNegateRAState::fillUnknownStateInBB(BinaryContext &BC,
174180 }
175181}
176182
177- bool InsertNegateRAState::isUnknownBlock (BinaryContext &BC,
178- BinaryBasicBlock &BB) {
179- for (const MCInst &Inst : BB) {
180- if (BC.MIB ->isCFI (Inst))
181- continue ;
182- std::optional<bool > RAState = BC.MIB ->getRAState (Inst);
183- if (RAState.has_value ())
184- return false ;
185- }
186- return true ;
187- }
188-
189183void InsertNegateRAState::markUnknownBlock (BinaryContext &BC,
190184 BinaryBasicBlock &BB, bool State) {
191185 // If we call this when an Instruction has either kRASigned or kRAUnsigned
@@ -205,7 +199,13 @@ void InsertNegateRAState::fillUnknownStubs(BinaryFunction &BF) {
205199 MCInst PrevInst;
206200 for (FunctionFragment &FF : BF.getLayout ().fragments ()) {
207201 for (BinaryBasicBlock *BB : FF) {
208- if (!FirstIter && isUnknownBlock (BC, *BB)) {
202+ if (FirstIter) {
203+ FirstIter = false ;
204+ if (isUnknownBlock (BC, *BB))
205+ // If the first BasicBlock is unknown, the function's entry RAState
206+ // should be used.
207+ markUnknownBlock (BC, *BB, BF.getInitialRAState ());
208+ } else if (isUnknownBlock (BC, *BB)) {
209209 // As explained in issue #160989, the unwind info is incorrect for
210210 // stubs. Indicating the correct RAState without the rest of the unwind
211211 // info being correct is not useful. Instead, we copy the RAState from
@@ -224,13 +224,6 @@ void InsertNegateRAState::fillUnknownStubs(BinaryFunction &BF) {
224224 PrevRAState = false ;
225225 markUnknownBlock (BC, *BB, *PrevRAState);
226226 }
227- if (FirstIter) {
228- FirstIter = false ;
229- if (isUnknownBlock (BC, *BB))
230- // If the first BasicBlock is unknown, the function's entry RAState
231- // should be used.
232- markUnknownBlock (BC, *BB, BF.getInitialRAState ());
233- }
234227 // This function iterates on BasicBlocks, so the PrevInst has to be
235228 // updated to the last instruction of the current BasicBlock. If the
236229 // BasicBlock is empty, or only has PseudoInstructions, PrevInst will not
0 commit comments