[cfe-commits] r62574 - in /cfe/trunk: include/clang/AST/Builtins.def include/clang/AST/Builtins.h lib/AST/Builtins.cpp lib/CodeGen/CGBuiltin.cpp test/Sema/varargs.c
Eli Friedman
eli.friedman at gmail.com
Mon Jan 19 23:46:23 PST 2009
Author: efriedma
Date: Tue Jan 20 01:46:22 2009
New Revision: 62574
URL: http://llvm.org/viewvc/llvm-project?rev=62574&view=rev
Log:
Fix for PR3350: add special-casing for "references" to va_lists in
builtins.
Also, a minor tweak to va_copy for consistency.
Modified:
cfe/trunk/include/clang/AST/Builtins.def
cfe/trunk/include/clang/AST/Builtins.h
cfe/trunk/lib/AST/Builtins.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/Sema/varargs.c
Modified: cfe/trunk/include/clang/AST/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Builtins.def?rev=62574&r1=62573&r2=62574&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Builtins.def (original)
+++ cfe/trunk/include/clang/AST/Builtins.def Tue Jan 20 01:46:22 2009
@@ -33,6 +33,7 @@
// z -> size_t
// F -> constant CFString
// a -> __builtin_va_list
+// A -> "reference" to __builtin_va_list
// V -> Vector, following num elements and a base type.
// . -> "...". This may only occur at the end of the function list.
//
@@ -115,10 +116,10 @@
BUILTIN(__builtin_constant_p, "Us.", "nc")
BUILTIN(__builtin_classify_type, "i.", "nc")
BUILTIN(__builtin___CFStringMakeConstantString, "FC*cC*", "nc")
-BUILTIN(__builtin_va_start, "va&.", "n")
-BUILTIN(__builtin_va_end, "va&", "n")
-BUILTIN(__builtin_va_copy, "va&a", "n")
-BUILTIN(__builtin_stdarg_start, "va&.", "n")
+BUILTIN(__builtin_va_start, "vA.", "n")
+BUILTIN(__builtin_va_end, "vA", "n")
+BUILTIN(__builtin_va_copy, "vAA", "n")
+BUILTIN(__builtin_stdarg_start, "vA.", "n")
BUILTIN(__builtin_bzero, "vv*z", "n")
BUILTIN(__builtin_memcpy, "v*v*vC*z", "n")
BUILTIN(__builtin_memmove, "v*v*vC*z", "n")
Modified: cfe/trunk/include/clang/AST/Builtins.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Builtins.h?rev=62574&r1=62573&r2=62574&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Builtins.h (original)
+++ cfe/trunk/include/clang/AST/Builtins.h Tue Jan 20 01:46:22 2009
@@ -81,7 +81,7 @@
/// hasVAListUse - Return true of the specified builtin uses __builtin_va_list
/// as an operand or return type.
bool hasVAListUse(unsigned ID) const {
- return strchr(GetRecord(ID).Type, 'a') != 0;
+ return strpbrk(GetRecord(ID).Type, "Aa") != 0;
}
/// GetBuiltinType - Return the type for the specified builtin.
Modified: cfe/trunk/lib/AST/Builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Builtins.cpp?rev=62574&r1=62573&r2=62574&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Builtins.cpp (original)
+++ cfe/trunk/lib/AST/Builtins.cpp Tue Jan 20 01:46:22 2009
@@ -142,6 +142,23 @@
Type = Context.getBuiltinVaListType();
assert(!Type.isNull() && "builtin va list type not initialized!");
break;
+ case 'A':
+ // This is a "reference" to a va_list; however, what exactly
+ // this means depends on how va_list is defined. There are two
+ // different kinds of va_list: ones passed by value, and ones
+ // passed by reference. An example of a by-value va_list is
+ // x86, where va_list is a char*. An example of by-ref va_list
+ // is x86-64, where va_list is a __va_list_tag[1]. For x86,
+ // we want this argument to be a char*&; for x86-64, we want
+ // it to be a __va_list_tag*.
+ Type = Context.getBuiltinVaListType();
+ assert(!Type.isNull() && "builtin va list type not initialized!");
+ if (Type->isArrayType()) {
+ Type = Context.getArrayDecayedType(Type);
+ } else {
+ Type = Context.getReferenceType(Type);
+ }
+ break;
case 'V': {
char *End;
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=62574&r1=62573&r2=62574&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Jan 20 01:46:22 2009
@@ -67,11 +67,7 @@
case Builtin::BI__builtin_va_copy: {
// FIXME: This does not yet handle architectures where va_list is a struct.
Value *DstPtr = EmitLValue(E->getArg(0)).getAddress();
- Value *SrcValue = EmitScalarExpr(E->getArg(1));
-
- Value *SrcPtr = CreateTempAlloca(SrcValue->getType(), "dst_ptr");
-
- Builder.CreateStore(SrcValue, SrcPtr, false);
+ Value *SrcPtr = EmitLValue(E->getArg(1)).getAddress();
const llvm::Type *Type =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
Modified: cfe/trunk/test/Sema/varargs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/varargs.c?rev=62574&r1=62573&r2=62574&view=diff
==============================================================================
--- cfe/trunk/test/Sema/varargs.c (original)
+++ cfe/trunk/test/Sema/varargs.c Tue Jan 20 01:46:22 2009
@@ -43,3 +43,12 @@
__builtin_va_list ap;
__builtin_va_start(ap); // expected-error {{too few arguments to function}}
}
+
+// PR3350
+void
+foo(__builtin_va_list authors, ...) {
+ __builtin_va_start (authors, authors);
+ (void)__builtin_va_arg(authors, int);
+ __builtin_va_end (authors);
+}
+
More information about the cfe-commits
mailing list