mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	opt_dff: don't remove cells until all have been visited to prevent UAF
This commit is contained in:
		
							parent
							
								
									378add3723
								
							
						
					
					
						commit
						19cdbc5a0c
					
				
					 1 changed files with 4 additions and 1 deletions
				
			
		| 
						 | 
					@ -737,6 +737,7 @@ struct OptDffWorker
 | 
				
			||||||
	bool run_constbits() {
 | 
						bool run_constbits() {
 | 
				
			||||||
		ModWalker modwalker(module->design, module);
 | 
							ModWalker modwalker(module->design, module);
 | 
				
			||||||
		QuickConeSat qcsat(modwalker);
 | 
							QuickConeSat qcsat(modwalker);
 | 
				
			||||||
 | 
							std::vector<RTLIL::Cell*> cells_to_remove;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Run as a separate sub-pass, so that we don't mutate (non-FF) cells under ModWalker.
 | 
							// Run as a separate sub-pass, so that we don't mutate (non-FF) cells under ModWalker.
 | 
				
			||||||
		bool did_something = false;
 | 
							bool did_something = false;
 | 
				
			||||||
| 
						 | 
					@ -830,7 +831,7 @@ struct OptDffWorker
 | 
				
			||||||
					if (!removed_sigbits.count(i))
 | 
										if (!removed_sigbits.count(i))
 | 
				
			||||||
						keep_bits.push_back(i);
 | 
											keep_bits.push_back(i);
 | 
				
			||||||
				if (keep_bits.empty()) {
 | 
									if (keep_bits.empty()) {
 | 
				
			||||||
					module->remove(cell);
 | 
										cells_to_remove.emplace_back(cell);
 | 
				
			||||||
					did_something = true;
 | 
										did_something = true;
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -840,6 +841,8 @@ struct OptDffWorker
 | 
				
			||||||
				did_something = true;
 | 
									did_something = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							for (auto* cell : cells_to_remove)
 | 
				
			||||||
 | 
								module->remove(cell);
 | 
				
			||||||
		return did_something;
 | 
							return did_something;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue