[PATCH] Perform calculation of array size in chars instead of bits to prevent an assertion.

Richard Smith richard at metafoo.co.uk
Mon May 13 13:32:51 PDT 2013



================
Comment at: test/Sema/offsetof.c:74
@@ +73,3 @@
+// PR15216
+// Don't crash on when taking computing the offset of structs with large arrays.
+const unsigned long Size = (1l << 62);
----------------
Comment slightly mangled?

================
Comment at: lib/AST/ASTContext.cpp:1358
@@ +1357,3 @@
+  unsigned Align = EltInfo.second / CharWidth;
+  Width = llvm::RoundUpToAlignment(Width, Align);
+  return std::make_pair(CharUnits::fromQuantity(Width),
----------------
This shouldn't be necessary; EltInfo.first / CharWidth should have been a multiple of EltInfo.second / CharWidth. Maybe convert this to an assertion?

================
Comment at: test/Sema/offsetof.c:77-80
@@ +76,6 @@
+
+struct Chunk {
+  char padding[Size];
+  char data;
+};
+
----------------
Does sizeof(Chunk) work here? Or 'char padding[1][Size];'? I suspect we'll need a more comprehensive solution to this problem -- perhaps reformulating the whole computation in terms of CharUnits.


http://llvm-reviews.chandlerc.com/D781



More information about the cfe-commits mailing list