[llvm] r240649 - [AsmPrinter] Fix crash in handleIndirectSymViaGOTPCRel
Bruno Cardoso Lopes
bruno.cardoso at gmail.com
Thu Jun 25 08:17:23 PDT 2015
Author: bruno
Date: Thu Jun 25 10:17:23 2015
New Revision: 240649
URL: http://llvm.org/viewvc/llvm-project?rev=240649&view=rev
Log:
[AsmPrinter] Fix crash in handleIndirectSymViaGOTPCRel
Check for symbols in MCValue before using them. Bail out early in case
they are null. This fixes PR23779.
Differential Revision: http://reviews.llvm.org/D10712
rdar://problem/21532830
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/test/MC/MachO/cstexpr-gotpcrel-64.ll
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=240649&r1=240648&r2=240649&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Thu Jun 25 10:17:23 2015
@@ -2086,8 +2086,12 @@ static void handleIndirectSymViaGOTPCRel
MCValue MV;
if (!(*ME)->evaluateAsRelocatable(MV, nullptr, nullptr) || MV.isAbsolute())
return;
+ const MCSymbolRefExpr *SymA = MV.getSymA();
+ if (!SymA)
+ return;
- const MCSymbol *GOTEquivSym = &MV.getSymA()->getSymbol();
+ // Check that GOT equivalent symbol is cached.
+ const MCSymbol *GOTEquivSym = &SymA->getSymbol();
if (!AP.GlobalGOTEquivs.count(GOTEquivSym))
return;
@@ -2095,8 +2099,11 @@ static void handleIndirectSymViaGOTPCRel
if (!BaseGV)
return;
+ // Check for a valid base symbol
const MCSymbol *BaseSym = AP.getSymbol(BaseGV);
- if (BaseSym != &MV.getSymB()->getSymbol())
+ const MCSymbolRefExpr *SymB = MV.getSymB();
+
+ if (!SymB || BaseSym != &SymB->getSymbol())
return;
// Make sure to match:
Modified: llvm/trunk/test/MC/MachO/cstexpr-gotpcrel-64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/cstexpr-gotpcrel-64.ll?rev=240649&r1=240648&r2=240649&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/cstexpr-gotpcrel-64.ll (original)
+++ llvm/trunk/test/MC/MachO/cstexpr-gotpcrel-64.ll Thu Jun 25 10:17:23 2015
@@ -84,3 +84,12 @@ define i32 @t0(i32 %a) {
define i32** @t1() {
ret i32** @bargotequiv
}
+
+; Do not crash when a pattern cannot be matched as a GOT equivalent
+
+ at a = external global i8
+ at b = internal unnamed_addr constant i8* @a
+
+; X86-LABEL: _c:
+; X86: .quad _b
+ at c = global i8** @b
More information about the llvm-commits
mailing list