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

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 07:56:14 PST 2018


Author: arichardson
Date: Fri Jan 26 07:56:14 2018
New Revision: 323536

URL: http://llvm.org/viewvc/llvm-project?rev=323536&view=rev
Log:
[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

Added:
    llvm/trunk/test/CodeGen/Mips/unsized-global.ll
Modified:
    llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp

Modified: llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp?rev=323536&r1=323535&r2=323536&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp Fri Jan 26 07:56:14 2018
@@ -136,6 +136,13 @@ IsGlobalInSmallSectionImpl(const GlobalO
     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));
 }

Added: llvm/trunk/test/CodeGen/Mips/unsized-global.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/unsized-global.ll?rev=323536&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/unsized-global.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/unsized-global.ll Fri Jan 26 07:56:14 2018
@@ -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
+
+ at 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
+}




More information about the llvm-commits mailing list