Call abort to encourage the user to fix the program. */
if (warned)
inform (input_location, "if this code is reached, the program will abort");
+ /* Before the abort, allow the evaluation of the va_list
+ expression to exit or longjmp. */
+ gimplify_and_add (valist, pre_p);
t = build_call_expr (implicit_built_in_decls[BUILT_IN_TRAP], 0);
gimplify_and_add (t, pre_p);
/* fntype now gets the type of function pointed to. */
fntype = TREE_TYPE (fntype);
+ /* Convert the parameters to the types declared in the
+ function prototype, or apply default promotions. */
+
+ nargs = list_length (params);
+ argarray = (tree *) alloca (nargs * sizeof (tree));
+ nargs = convert_arguments (nargs, argarray, TYPE_ARG_TYPES (fntype),
+ params, function, fundecl);
+ if (nargs < 0)
+ return error_mark_node;
+
/* Check that the function is called through a compatible prototype.
If it is not, replace the call by a trap, wrapped up in a compound
expression if necessary. This has the nice side-effect to prevent
tree return_type = TREE_TYPE (fntype);
tree trap = build_function_call (built_in_decls[BUILT_IN_TRAP],
NULL_TREE);
+ int i;
/* This situation leads to run-time undefined behavior. We can't,
therefore, simply error unless we can prove that all possible
/* We can, however, treat "undefined" any way we please.
Call abort to encourage the user to fix the program. */
inform (input_location, "if this code is reached, the program will abort");
+ /* Before the abort, allow the function arguments to exit or
+ call longjmp. */
+ for (i = 0; i < nargs; i++)
+ trap = build2 (COMPOUND_EXPR, void_type_node, argarray[i], trap);
if (VOID_TYPE_P (return_type))
return trap;
}
}
- /* Convert the parameters to the types declared in the
- function prototype, or apply default promotions. */
-
- nargs = list_length (params);
- argarray = (tree *) alloca (nargs * sizeof (tree));
- nargs = convert_arguments (nargs, argarray, TYPE_ARG_TYPES (fntype),
- params, function, fundecl);
- if (nargs < 0)
- return error_mark_node;
-
/* Check that arguments to builtin functions match the expectations. */
if (fundecl
&& DECL_BUILT_IN (fundecl)
--- /dev/null
+/* Undefined behavior from a call to va_arg with a type other than
+ that of the argument passed (in particular, with a type such as
+ "float" that can never be the type of an argument passed through
+ "...") does not appear until after the va_list expression is
+ evaluated. PR 38483. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+
+#include <stdarg.h>
+
+extern void exit (int);
+extern void abort (void);
+
+va_list ap;
+float f;
+
+va_list *
+foo (void)
+{
+ exit (0);
+ return ≈
+}
+
+void
+bar (int i, ...)
+{
+ va_start (ap, i);
+ f = va_arg (*foo (), float);
+ va_end (ap);
+}
+
+int
+main (void)
+{
+ bar (1, 0);
+ abort ();
+}