diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2015-07-21 21:45:42 +0000 |
---|---|---|
committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2015-07-21 21:45:42 +0000 |
commit | e8640518a983eccbe7990885acf53bd6976c5067 (patch) | |
tree | 421d189af1033cd1d64ac1e3cb6dc651d621ce63 | |
parent | 402a4f10886cf3ceee58f5614df9606f719d6793 (diff) | |
download | bcm5719-llvm-e8640518a983eccbe7990885acf53bd6976c5067.tar.gz bcm5719-llvm-e8640518a983eccbe7990885acf53bd6976c5067.zip |
[AsmPrinter] Check for valid constants in handleIndirectSymViaGOTPCRel
Check whether BaseCst is valid before extracting a GlobalValue.
This fixes PR24163.
Patch by David Majnemer.
llvm-svn: 242840
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 | ||||
-rw-r--r-- | llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 068b9172e9f..ecdc7fa8b35 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2101,7 +2101,7 @@ static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME, if (!AP.GlobalGOTEquivs.count(GOTEquivSym)) return; - const GlobalValue *BaseGV = dyn_cast<GlobalValue>(BaseCst); + const GlobalValue *BaseGV = dyn_cast_or_null<GlobalValue>(BaseCst); if (!BaseGV) return; diff --git a/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll b/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll index bafddcb3db6..41abeb0179c 100644 --- a/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll +++ b/llvm/test/MC/MachO/cstexpr-gotpcrel-64.ll @@ -1,6 +1,7 @@ ; RUN: llc -mtriple=x86_64-apple-darwin %s -o %t ; RUN: FileCheck %s -check-prefix=X86 < %t ; RUN: FileCheck %s -check-prefix=X86-GOT-EQUIV < %t +; RUN: FileCheck %s -check-prefix=X86-NOGOT-EQUIV < %t ; GOT equivalent globals references can be replaced by the GOT entry of the ; final symbol instead. @@ -86,10 +87,15 @@ define i32** @t1() { } ; Do not crash when a pattern cannot be matched as a GOT equivalent - +define void @foo() { +; X86-NOGOT-EQUIV-LABEL: _foo: +; X86-NOGOT-EQUIV: leaq _b(%rip), %rax + store i8** @b, i8*** null + ret void +} @a = external global i8 @b = internal unnamed_addr constant i8* @a -; X86-LABEL: _c: -; X86: .quad _b +; X86-NOGOT-EQUIV-LABEL: _c: +; X86-NOGOT-EQUIV: .quad _b @c = global i8** @b |