[llvm-branch-commits] [cfe-branch] r102085 - /cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp

Daniel Dunbar daniel at zuster.org
Thu Apr 22 10:18:08 PDT 2010


Author: ddunbar
Date: Thu Apr 22 12:18:07 2010
New Revision: 102085

URL: http://llvm.org/viewvc/llvm-project?rev=102085&view=rev
Log:
IRgen: Add checking that the LLVM and AST record layout offsets agree (for non-bit-fields).

Modified:
    cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp

Modified: cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=102085&r1=102084&r2=102085&view=diff
==============================================================================
--- cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp Thu Apr 22 12:18:07 2010
@@ -20,6 +20,7 @@
 #include "CodeGenTypes.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Type.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetData.h"
 using namespace clang;
@@ -569,7 +570,25 @@
          getTargetData().getTypeAllocSize(Ty) &&
          "Type size mismatch!");
 
-  // FIXME: We should verify the individual field offsets here as well.
+  // Verify that the LLVM and AST field offsets agree.
+#ifndef NDEBUG
+  const llvm::StructType *ST =
+    dyn_cast<llvm::StructType>(RL->getLLVMType());
+  const llvm::StructLayout *SL = getTargetData().getStructLayout(ST);
+
+  const ASTRecordLayout &AST_RL = getContext().getASTRecordLayout(D);
+  RecordDecl::field_iterator it = D->field_begin();
+  for (unsigned i = 0, e = AST_RL.getFieldCount(); i != e; ++i, ++it) {
+    const FieldDecl *FD = *it;
+    if (FD->isBitField()) {
+      // FIXME: Verify assorted things.
+    } else {
+      unsigned FieldNo = RL->getLLVMFieldNo(FD);
+      assert(AST_RL.getFieldOffset(i) == SL->getElementOffsetInBits(FieldNo) &&
+             "Invalid field offset!");
+    }
+  }
+#endif
 
   return RL;
 }





More information about the llvm-branch-commits mailing list