This is the mail archive of the 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]

[patch] to avoid application crash when va_arg arguments need to be promoted

constructs like:

    if ( sizeof(short) < sizeof(int) )
        res = va_arg(ap,int);
        res = va_arg(ap,short); /* meaningless on 32 bit machines */

the current gcc 3.2 compiler will embed a trap instruction (and emit a
that will cause the target program to crash (if executed) for this
syntactically right but meaningless construct.

we find this counter productive, because the developper may not be scanning
all the warnings and therefore may not be aware
of the problem, which may reach the end user before being discovered
causing grief and unnecessary delays and efforts.

this patch to reverses the situation to what it was in gcc 3.0
and 3.1 until April 2002, that is: compilation error (see ) . This patch may be
interest for people who agree with (or need to enforce) the above

the patch does not propose a new option, it just changes the behavior
of the compiler for the va_arg problem, the patch does not invalidate any
other production of the trap instruction within the compiler, it is
applicable to gcc 3.2.

diff -ru gcc/builtins.c gcc/builtins.c
--- builtins.c 2002-03-31 14:31:55.000000000 +0300
+++ builtins.c 2002-11-13 13:20:12.000000000 +0200
@@ -3099,25 +3099,16 @@
      && DECL_NAME (TYPE_NAME (promoted_type)))
      pname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (promoted_type)));
-      /* Unfortunately, this is merely undefined, rather than a constraint
-  violation, so we cannot make this an error.  If this call is never
-  executed, the program is still strictly conforming.  */
-      warning ("`%s' is promoted to `%s' when passed through `...'",
+      /* The best way to handle that is to generate an error */
+      error ("`%s' is promoted to `%s' when passed through `...'",
         name, pname);
       if (! gave_help)
    gave_help = true;
-   warning ("(so you should pass `%s' not `%s' to `va_arg')",
+   error ("(so you should pass `%s' not `%s' to `va_arg')",
      pname, name);

-      /* We can, however, treat "undefined" any way we please.
-  Call abort to encourage the user to fix the program.  */
-      expand_builtin_trap ();
-      /* This is dead code, but go ahead and finish so that the
-  mode of the result comes out right.  */
       addr = const0_rtx;

Attachment: gcc_va_arg_error.patch
Description: Binary data

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