[cfe-dev] [PATCH] adding flag for generating va_arg instructions

Will Dietz willdtz at gmail.com
Sat Apr 21 18:00:04 PDT 2012

On Fri, Apr 20, 2012 at 12:10 PM, John Criswell <criswell at illinois.edu> wrote:
> On 4/17/12 9:16 PM, David Lazar wrote:
> This patch is a minor change which adds a flag to generate LLVM's
> va_arg instruction instead of target-specific instructions for
> handling variadic arguments. The flag is called -fuse-llvm-variadics,
> but feel free to pick a better name :-). By default, this flag is
> disabled, which preserves the existing behavior.
> This functionality is useful for Clang users who want to do program
> analysis in LLVM in a platform-independent way. Currently, there is no
> way to disable the platform-specific instructions. We needed this
> functionality for our research and we are aware of other groups who
> want this as well.
> I'd like to add that this functionality would be useful for projects like
> DSA (a points-to analysis) and SAFECode (a memory safety tool).  Currently,
> these tools have platform-specific code in them so that they understand the
> format of the varargs objects generated by the C/C++ front-ends.  This
> prevents them from handling varargs functions in a platform-independent way.
> For example, DSA has code to understand the x86 and x86_64 varargs
> structures, but it is very conservative for all other platforms.  DSA could
> be more aggressive and platform-independent if it could just analyze varargs
> intrinsics like the ones that LLVM had originally.
> -- John T.

As John mentioned, many analysis passes would benefit from such a
feature, including a few of my own, and I'd personally be very happy
to see this included in clang.

Coincidentally, a while back I also submitted a similar patch, and I
think the resulting discussion absolutely work revisiting:
http://old.nabble.com/Is-va_arg-deprecated--tp29208110p32284898.html .

In short, this isn't as a simple as just tweaking clang, and is of
somewhat limited (doomed?) use since the resulting IR is
non-functional on many targets (including x86_64).  This is also
mentioned in the LangRef (see

So this leaves us with a few questions: What would it take to fix
these issues?  Is it okay to accept this feature as a stepping-stone
of sorts?  Does this properly work on any target?

I apologize that I don't have the answers to these questions, but
hopefully others do.  Thanks for rekindling this discussion/feature,
and submitting the patch! :) *crosses fingers*


More information about the cfe-dev mailing list