[cfe-commits] r56809 - in /cfe/trunk: lib/AST/Builtins.cpp test/Sema/varargs.c

Chris Lattner sabre at nondot.org
Mon Sep 29 15:28:25 PDT 2008


Author: lattner
Date: Mon Sep 29 17:28:25 2008
New Revision: 56809

URL: http://llvm.org/viewvc/llvm-project?rev=56809&view=rev
Log:
Fix va_arg handling to do argument decaying at the correct place.  This
fixes problems handling references of va_list, which happens on x86_64.
This fixes PR2841 and rdar://6252231

Modified:
    cfe/trunk/lib/AST/Builtins.cpp
    cfe/trunk/test/Sema/varargs.c

Modified: cfe/trunk/lib/AST/Builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Builtins.cpp?rev=56809&r1=56808&r2=56809&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Builtins.cpp (original)
+++ cfe/trunk/lib/AST/Builtins.cpp Mon Sep 29 17:28:25 2008
@@ -137,9 +137,6 @@
   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 @@
   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!");

Modified: cfe/trunk/test/Sema/varargs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/varargs.c?rev=56809&r1=56808&r2=56809&view=diff

==============================================================================
--- cfe/trunk/test/Sema/varargs.c (original)
+++ cfe/trunk/test/Sema/varargs.c Mon Sep 29 17:28:25 2008
@@ -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)
 {





More information about the cfe-commits mailing list