]> granicus.if.org Git - llvm/commitdiff
Merging r323536:
authorHans Wennborg <hans@hanshq.net>
Fri, 2 Feb 2018 13:47:07 +0000 (13:47 +0000)
committerHans Wennborg <hans@hanshq.net>
Fri, 2 Feb 2018 13:47:07 +0000 (13:47 +0000)
------------------------------------------------------------------------
r323536 | arichardson | 2018-01-26 16:56:14 +0100 (Fri, 26 Jan 2018) | 11 lines

[MIPS] Don't crash on unsized extern types with -mgpopt

Summary: This fixes an assertion when building the FreeBSD MIPS64 kernel.

Reviewers: atanasyan, sdardis, emaste

Reviewed By: sdardis

Subscribers: krytarowski, llvm-commits

Differential Revision: https://reviews.llvm.org/D42571
------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@324087 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/MipsTargetObjectFile.cpp
test/CodeGen/Mips/unsized-global.ll [new file with mode: 0644]

index 9db6b7b1bcd6adb3cece95a953270027a44abe97..f767c83219883e03f90ea4bedcc57ec53885677c 100644 (file)
@@ -136,6 +136,13 @@ IsGlobalInSmallSectionImpl(const GlobalObject *GO,
     return false;
 
   Type *Ty = GVA->getValueType();
+
+  // It is possible that the type of the global is unsized, i.e. a declaration
+  // of a extern struct. In this case don't presume it is in the small data
+  // section. This happens e.g. when building the FreeBSD kernel.
+  if (!Ty->isSized())
+    return false;
+
   return IsInSmallSection(
       GVA->getParent()->getDataLayout().getTypeAllocSize(Ty));
 }
diff --git a/test/CodeGen/Mips/unsized-global.ll b/test/CodeGen/Mips/unsized-global.ll
new file mode 100644 (file)
index 0000000..a89ecc1
--- /dev/null
@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; Check that -mgpopt doesn't crash on unsized externals
+; RUN: llc -mtriple=mips64-unknown-freebsd -mattr=+noabicalls -target-abi n64 -mgpopt -o - %s | FileCheck %s
+
+%struct.a = type opaque
+
+@b = external global %struct.a, align 1
+
+; Function Attrs: norecurse nounwind readnone
+define %struct.a* @d() {
+; CHECK-LABEL: d:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    lui $1, %highest(b)
+; CHECK-NEXT:    daddiu $1, $1, %higher(b)
+; CHECK-NEXT:    dsll $1, $1, 16
+; CHECK-NEXT:    daddiu $1, $1, %hi(b)
+; CHECK-NEXT:    dsll $1, $1, 16
+; CHECK-NEXT:    jr $ra
+; CHECK-NEXT:    daddiu $2, $1, %lo(b)
+entry:
+  ret %struct.a* @b
+}