This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] 69517 - [5/6 regression] SEGV on a VLA with excess initializer elements


On 04/10/2016 07:14 PM, Martin Sebor wrote:
+	  if (TREE_CODE (type) == ARRAY_TYPE
+	      && variably_modified_type_p (type, NULL_TREE)
+	      && !processing_template_decl)
+	    {
+	      /* Statically check for overflow in VLA bounds and build
+		 an expression that checks at runtime whether the VLA
+		 is erroneous due to invalid (runtime) bounds.
+		 Another expression to check for excess initializers
+		 is built in build_vec_init.  */

Why do this both in check_initializer and then again in cp_finish_decl right after the call to check_initializer?

+      /* Also check to see if the final array size is zero (the size
+	 is unsigned so the earlier overflow check detects negative
+	 values as well.  */
+      tree zerocheck = fold_build2 (EQ_EXPR, boolean_type_node,
+				    vlasize, size_zero_node);

I'm not sure whether we want this, given that GCC allows zero-length arrays in general. As I recall, with the C++14 stuff whether we checked for zero was dependent on flag_iso, though I wasn't particularly happy with that. If you want to check this unconditionally that's fine.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]