]> granicus.if.org Git - clang/commitdiff
Fix va_arg handling to do argument decaying at the correct place. This
authorChris Lattner <sabre@nondot.org>
Mon, 29 Sep 2008 22:28:25 +0000 (22:28 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 29 Sep 2008 22:28:25 +0000 (22:28 +0000)
fixes problems handling references of va_list, which happens on x86_64.
This fixes PR2841 and rdar://6252231

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56809 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Builtins.cpp
test/Sema/varargs.c

index 31e099af4ee5ba5fb8e4ed31a8806cf70fcd60e8..3980d205217973db5519952228344d2396baa773 100644 (file)
@@ -137,9 +137,6 @@ static QualType DecodeTypeFromStr(const char *&Str, ASTContext &Context,
   case 'a':
     Type = Context.getBuiltinVaListType();
     assert(!Type.isNull() && "builtin va list type not initialized!");
-    // Do array -> pointer decay.  The builtin should use the decayed type.
-    if (Type->isArrayType())
-      Type = Context.getArrayDecayedType(Type);
     break;
   case 'V': {
     char *End;
@@ -185,8 +182,15 @@ QualType Builtin::Context::GetBuiltinType(unsigned id,
   llvm::SmallVector<QualType, 8> ArgTypes;
   
   QualType ResType = DecodeTypeFromStr(TypeStr, Context);
-  while (TypeStr[0] && TypeStr[0] != '.')
-    ArgTypes.push_back(DecodeTypeFromStr(TypeStr, Context)); 
+  while (TypeStr[0] && TypeStr[0] != '.') {
+    QualType Ty = DecodeTypeFromStr(TypeStr, Context);
+    
+    // Do array -> pointer decay.  The builtin should use the decayed type.
+    if (Ty->isArrayType())
+      Ty = Context.getArrayDecayedType(Ty);
+   
+    ArgTypes.push_back(Ty);
+  }
 
   assert((TypeStr[0] != '.' || TypeStr[1] == 0) &&
          "'.' should only occur at end of builtin type list!");
index f52921c5fca6dac0f9e608c80099ce9b7a573153..90568e02988457d8d1a6865b7befb741bd607f72 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -verify %s &&
+// RUN: clang -fsyntax-only -verify %s -triple x86_64-apple-darwin9
 
 void f1(int a)
 {