Re: [edk2] VA_LIST bug in CatVSPrint()

Subject: Re: [edk2] VA_LIST bug in CatVSPrint()

From: Sergey Isakov <isakov-sl@bk.ru>

To: edk2-devel@lists.sourceforge.net

Date: 2012-01-08 20:39:19

Hi Andrew,
Yes, I think it is Clang bug and I am not sure that only one.
Test results:
1. Clang from XCode 3.2.5
--------
Apple clang version 1.6 (tags/Apple/clang-70)
Target: i386-apple-darwin10
Thread model: posix
-------
$ clang v.c -ccc-host-triple x86_64-pc-win32-macho -S
In file included from v.c:1:
/usr/lib/clang/1.6/include/stdarg.h(30) :  error: unknown type name '__builtin_va_list'
typedef __builtin_va_list va_list;
        ^
/usr/lib/clang/1.6/include/stdarg.h(48) :  error: unknown type name '__builtin_va_list'
typedef __builtin_va_list __gnuc_va_list;
        ^
v.c(3) :  error: unknown type name '__builtin_va_list'
typedef __builtin_va_list VA_LIST;
        ^
0  clang             0x00f00e48 PrintStackTrace(void*) + 40
1  clang             0x00f0139d SignalHandler(int) + 349
-------
2. Recent Clang 3.1
-------------------------
llvm/Release/bin/clang v.c -ccc-host-triple x86_64-pc-win32-macho -S
v.c:18:26: warning: second argument to 'va_arg' is of promotable type 'short'; this va_arg has
      undefined behavior because arguments will be promoted to 'int'
  return VA_ARG (Marker, short);
         ~~~~~~~~~~~~~~~~^~~~~~
v.c:7:158: note: expanded from macro 'VA_ARG'
  ...? (TYPE)(__builtin_va_arg (Marker, long long)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))
                                                                                       ^
1 warning generated.
-------------------------
llvm/Release/bin/clang v.c
v.c:18:26: warning: second argument to 'va_arg' is of promotable type 'short'; this va_arg has
      undefined behavior because arguments will be promoted to 'int'
  return VA_ARG (Marker, short);
         ~~~~~~~~~~~~~~~~^~~~~~
v.c:7:158: note: expanded from macro 'VA_ARG'
  ...? (TYPE)(__builtin_va_arg (Marker, long long)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))
                                                                                       ^
1 warning generated.
-------------------
But sorry I am not propose to be a llvm/clang developer, I have another tasks.

And I wish to say that Duet generated with new Clang is not working. Old Clang can't compile it at all.

Sergey


On 07.01.2012, at 22:53, Andrew Fish wrote:

For Xcode 4.2.1 clang I don't get an error on the following test program? Do you get an error with the open source clang? If yes we need to post to the open source clang developer list, as it seems like a bug in clang?

~/work/compiler>cat v.c
#include <stdarg.h>

typedef __builtin_va_list VA_LIST;

#define VA_START(Marker, Parameter)  __builtin_va_start (Marker, Parameter)

#define VA_ARG(Marker, TYPE)         ((sizeof (TYPE) < sizeof (long long)) ? (TYPE)(__builtin_va_arg (Marker, long long)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))

#define VA_END(Marker)               __builtin_va_end (Marker)

#define NULL ((void *)0)

int
ReturnMarker (
  VA_LIST  Marker
  )
{
  return VA_ARG (Marker, short);
}

int
Test (
  void  *Handle,
  ...
  )
{
  VA_LIST   Marker;
  int       ret;
  
  VA_START (Marker, Handle);
  ret = ReturnMarker (Marker);
  VA_END (Marker);
  
  return ret;
}

int
Test2 ()
{
  return sizeof (VA_LIST);
}

int
main ()
{
  return Test (NULL, 123);
}


~/work/compiler>/Developer/usr/bin/clang v.c -ccc-host-triple x86_64-pc-win32-macho -S
~/work/compiler>/Developer/usr/bin/clang v.c 

Note when using the crazy ccc-host-triple the compiler does not know how to link the image, so you have to compile to assembly or object. 

Andrew Fish





On Jan 6, 2012, at 11:18 PM, Sergey Isakov wrote:

#define VA_ARG(Marker, TYPE)         ((sizeof (TYPE) < sizeof (UINTN)) ? (TYPE)(__builtin_va_arg (Marker, UINTN)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel