XCore target: fix handling of unsized global arrays in large code model

Richard Osborne richard at xmos.com
Thu Nov 28 13:19:54 PST 2013


diff --git a/lib/Target/XCore/XCoreISelLowering.cpp b/lib/Target/XCore/XCoreISelLowering.cpp
index b3fbb61..d40ec1b 100644
--- a/lib/Target/XCore/XCoreISelLowering.cpp
+++ b/lib/Target/XCore/XCoreISelLowering.cpp
@@ -276,9 +276,17 @@ LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
   SDLoc DL(GN);
   int64_t Offset = GN->getOffset();
   Type *ObjType = GV->getType()->getPointerElementType();
-  if (getTargetMachine().getCodeModel() == CodeModel::Small ||
-      !ObjType->isSized() ||
-      getDataLayout()->getTypeAllocSize(ObjType) < CodeModelLargeSize) {
+
+  bool SmallObject = true;
+  if (ObjType->isSized() &&
+      getTargetMachine().getCodeModel() == CodeModel::Large) {
+    unsigned ObjSize = getDataLayout()->getTypeAllocSize(ObjType);
+    if (ObjSize >= CodeModelLargeSize ||
+        (ObjType->isArrayTy() && ObjSize == 0))
+      SmallObject = false;
+  }
+

This conditional is getting pretty complicated - maybe extract it into a static helper function? Also does the code also handle the following case correctly? 

// Incomplete structure type
extern struct foo x;

struct foo *f() {
  return &x;
}





More information about the llvm-commits mailing list