Make it possible to get an empty struct using
authorDuncan Sands <baldrick@free.fr>
Fri, 21 Mar 2008 15:53:17 +0000 (15:53 +0000)
committerDuncan Sands <baldrick@free.fr>
Fri, 21 Mar 2008 15:53:17 +0000 (15:53 +0000)
the new StructType::get method.  The second NULL
is to pacify the gcc warning mechanism.  This
patch compiles but is otherwise untested.

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

include/llvm/DerivedTypes.h
lib/VMCore/Type.cpp

index 7fc7ed6a91cd173acb90ad05f4de36c070ae4090..5f4569cfd15ed6278807811365bb9b5594f27c66 100644 (file)
@@ -221,8 +221,9 @@ public:
                          bool isPacked=false);
 
   /// StructType::get - This static method is a convenience method for
-  /// creating structure types by specifying the elements as arguments.  Note
-  /// that this method always returns a non-packed struct.
+  /// creating structure types by specifying the elements as arguments.
+  /// Note that this method always returns a non-packed struct.  To get
+  /// an empty struct, pass NULL, NULL.
   static StructType *get(const Type *type, ...) END_WITH_NULL;
 
   // Iterator access to the elements
index 4554826c34bbcdd6bc5f96cec11038623bc8c9df..829923e15a176d2b25a863df06e040c6699cddb1 100644 (file)
@@ -1252,9 +1252,10 @@ StructType *StructType::get(const Type *type, ...) {
   va_list ap;
   std::vector<const llvm::Type*> StructFields;
   va_start(ap, type);
-  do {
+  while (type) {
     StructFields.push_back(type);
-  } while ((type = va_arg(ap, llvm::Type*)));
+    type = va_arg(ap, llvm::Type*);
+  }
   return llvm::StructType::get(StructFields);
 }