Struct GEPs must use i32, not whatever size_t is. It should be safe
authorJohn McCall <rjmccall@apple.com>
Thu, 1 Dec 2016 23:51:30 +0000 (23:51 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 1 Dec 2016 23:51:30 +0000 (23:51 +0000)
to do this unconditionally, given that the indices will always be small
constant integers anyway.

llvm-svn: 288440

clang/lib/CodeGen/ConstantBuilder.h

index 6c5a5e5..40b34a9 100644 (file)
@@ -248,11 +248,13 @@ public:
       // Otherwise, add an index to drill into the first level of pointer. 
       } else {
         assert(indices.empty());
-        indices.push_back(llvm::ConstantInt::get(Builder.CGM.SizeTy, 0));
+        indices.push_back(llvm::ConstantInt::get(Builder.CGM.Int32Ty, 0));
       }
 
       assert(position >= Begin);
-      indices.push_back(llvm::ConstantInt::get(Builder.CGM.SizeTy,
+      // We have to use i32 here because struct GEPs demand i32 indices.
+      // It's rather unlikely to matter in practice.
+      indices.push_back(llvm::ConstantInt::get(Builder.CGM.Int32Ty,
                                                position - Begin));
     }
   };