mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-03 21:09:12 +00:00 
			
		
		
		
	Merge pull request #2632 from zachjs/width-limit
verilog: impose limit on maximum expression width
This commit is contained in:
		
						commit
						72ae15c77c
					
				
					 3 changed files with 39 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -1000,6 +1000,12 @@ void AstNode::detectSignWidth(int &width_hint, bool &sign_hint, bool *found_real
 | 
			
		|||
	if (found_real)
 | 
			
		||||
		*found_real = false;
 | 
			
		||||
	detectSignWidthWorker(width_hint, sign_hint, found_real);
 | 
			
		||||
 | 
			
		||||
	constexpr int kWidthLimit = 1 << 24;
 | 
			
		||||
	if (width_hint >= kWidthLimit)
 | 
			
		||||
		log_file_error(filename, location.first_line,
 | 
			
		||||
			"Expression width %d exceeds implementation limit of %d!\n",
 | 
			
		||||
			width_hint, kWidthLimit);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void check_unique_id(RTLIL::Module *module, RTLIL::IdString id,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								tests/verilog/absurd_width.ys
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								tests/verilog/absurd_width.ys
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
logger -expect error "Expression width 1073741824 exceeds implementation limit of 16777216!" 1
 | 
			
		||||
read_verilog <<EOF
 | 
			
		||||
module top(
 | 
			
		||||
    input inp,
 | 
			
		||||
    output out
 | 
			
		||||
);
 | 
			
		||||
    assign out =
 | 
			
		||||
        {1024 {
 | 
			
		||||
        {1024 {
 | 
			
		||||
        {1024 {
 | 
			
		||||
        inp
 | 
			
		||||
        }}
 | 
			
		||||
        }}
 | 
			
		||||
        }}
 | 
			
		||||
        ;
 | 
			
		||||
endmodule
 | 
			
		||||
EOF
 | 
			
		||||
							
								
								
									
										16
									
								
								tests/verilog/absurd_width_const.ys
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								tests/verilog/absurd_width_const.ys
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
logger -expect error "Expression width 1073741824 exceeds implementation limit of 16777216!" 1
 | 
			
		||||
read_verilog <<EOF
 | 
			
		||||
module top(
 | 
			
		||||
    output out
 | 
			
		||||
);
 | 
			
		||||
    assign out =
 | 
			
		||||
        {1024 {
 | 
			
		||||
        {1024 {
 | 
			
		||||
        {1024 {
 | 
			
		||||
        1'b1
 | 
			
		||||
        }}
 | 
			
		||||
        }}
 | 
			
		||||
        }}
 | 
			
		||||
        ;
 | 
			
		||||
endmodule
 | 
			
		||||
EOF
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue