Avoid passing nullptr to std::equal.
authorYaron Keren <yaron.keren@gmail.com>
Tue, 4 Aug 2015 15:57:04 +0000 (15:57 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Tue, 4 Aug 2015 15:57:04 +0000 (15:57 +0000)
As documented in the LLVM Coding Standards, indeed MSVC incorrectly asserts
on this in Debug mode. This happens when building clang with Visual C++ and
-triple i686-pc-windows-gnu on these clang regression tests:

 clang/test/CodeGen/2011-03-08-ZeroFieldUnionInitializer.c
 clang/test/CodeGen/empty-union-init.c

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

lib/IR/Type.cpp

index 18c2e8c2b483ba95c0d8fe912b593f1934fe8a1a..2f6dbab720156c2819eabf3c089f66cf5898a8e1 100644 (file)
@@ -612,7 +612,8 @@ bool StructType::isLayoutIdentical(StructType *Other) const {
       getNumElements() != Other->getNumElements())
     return false;
   
-  return std::equal(element_begin(), element_end(), Other->element_begin());
+  return element_begin() &&
+         std::equal(element_begin(), element_end(), Other->element_begin());
 }
 
 /// getTypeByName - Return the type with the specified name, or null if there