tccgen.c: Recognise constant expressions with conditional operator.
tests/tests2/78_vla_label.c: Check that int a[1 ? 1 : 1] is not a VLA.
This commit is contained in:
		
							parent
							
								
									30c54c9d43
								
							
						
					
					
						commit
						992cbda8d0
					
				
					 2 changed files with 21 additions and 10 deletions
				
			
		
							
								
								
									
										14
									
								
								tccgen.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								tccgen.c
									
										
									
									
									
								
							|  | @ -4522,9 +4522,13 @@ static void expr_cond(void) | ||||||
|     SValue sv; |     SValue sv; | ||||||
|     CType type, type1, type2; |     CType type, type1, type2; | ||||||
| 
 | 
 | ||||||
|     if (const_wanted) { |     if (const_wanted) | ||||||
|         expr_lor_const(); |         expr_lor_const(); | ||||||
|         if (tok == '?') { |     else | ||||||
|  |         expr_lor(); | ||||||
|  |     if (tok == '?') { | ||||||
|  |         next(); | ||||||
|  |         if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { | ||||||
|             CType boolean; |             CType boolean; | ||||||
|             int c; |             int c; | ||||||
|             boolean.t = VT_BOOL; |             boolean.t = VT_BOOL; | ||||||
|  | @ -4532,7 +4536,6 @@ static void expr_cond(void) | ||||||
|             gen_cast(&boolean); |             gen_cast(&boolean); | ||||||
|             c = vtop->c.i; |             c = vtop->c.i; | ||||||
|             vpop(); |             vpop(); | ||||||
|             next(); |  | ||||||
|             if (tok != ':' || !gnu_ext) { |             if (tok != ':' || !gnu_ext) { | ||||||
|                 vpop(); |                 vpop(); | ||||||
|                 gexpr(); |                 gexpr(); | ||||||
|  | @ -4544,10 +4547,7 @@ static void expr_cond(void) | ||||||
|             if (c) |             if (c) | ||||||
|                 vpop(); |                 vpop(); | ||||||
|         } |         } | ||||||
|     } else { |         else { | ||||||
|         expr_lor(); |  | ||||||
|         if (tok == '?') { |  | ||||||
|             next(); |  | ||||||
|             if (vtop != vstack) { |             if (vtop != vstack) { | ||||||
|                 /* needed to avoid having different registers saved in
 |                 /* needed to avoid having different registers saved in
 | ||||||
|                    each branch */ |                    each branch */ | ||||||
|  |  | ||||||
|  | @ -1,8 +1,7 @@ | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| 
 | 
 | ||||||
| /* This test segfaults as of April 27, 2015. */ | /* This test segfaults as of April 27, 2015. */ | ||||||
| 
 | void f1(int argc) | ||||||
| void f(int argc) |  | ||||||
| { | { | ||||||
|   char test[argc]; |   char test[argc]; | ||||||
|   if(0) |   if(0) | ||||||
|  | @ -13,9 +12,21 @@ void f(int argc) | ||||||
|   goto label; |   goto label; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /* This segfaulted on 2015-11-19. */ | ||||||
|  | void f2(void) | ||||||
|  | { | ||||||
|  |     goto start; | ||||||
|  |     { | ||||||
|  |         int a[1 ? 1 : 1]; /* not a variable-length array */ | ||||||
|  |     start: | ||||||
|  |         a[0] = 0; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int main() | int main() | ||||||
| { | { | ||||||
|   f(2); |   f1(2); | ||||||
|  |   f2(); | ||||||
| 
 | 
 | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue