]> granicus.if.org Git - clang/commitdiff
Fix for PR2631; make va_arg work correctly on x86-64.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 9 Aug 2008 23:32:40 +0000 (23:32 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 9 Aug 2008 23:32:40 +0000 (23:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54600 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/va_arg_x86_64.c [new file with mode: 0644]

index 2982c45865e8c3508f814ce77575719b8202ba94..003f3dea59fea2ada402b86ce81a68a97b419de9 100644 (file)
@@ -2604,9 +2604,16 @@ Sema::ExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc,
   QualType T = QualType::getFromOpaquePtr(type);
 
   InitBuiltinVaListType();
-  
-  if (CheckAssignmentConstraints(Context.getBuiltinVaListType(), E->getType())
-      != Compatible)
+
+  // Get the va_list type
+  QualType VaListType = Context.getBuiltinVaListType();
+  // Deal with implicit array decay; for example, on x86-64,
+  // va_list is an array, but it's supposed to decay to
+  // a pointer for va_arg.
+  if (VaListType->isArrayType())
+    VaListType = Context.getArrayDecayedType(VaListType);
+
+  if (CheckAssignmentConstraints(VaListType, E->getType()) != Compatible)
     return Diag(E->getLocStart(),
                 diag::err_first_argument_to_va_arg_not_of_type_va_list,
                 E->getType().getAsString(),
diff --git a/test/Sema/va_arg_x86_64.c b/test/Sema/va_arg_x86_64.c
new file mode 100644 (file)
index 0000000..8651134
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only -verify -triple=x86_64-unknown-freebsd7.0 %s
+
+char* foo(char *fmt, __builtin_va_list ap)
+{
+  return __builtin_va_arg((ap), char *);
+}