Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 3a2a1ee

Browse files
committed
ARM: handle checking aliases with out-of-bounds GEPs
A global alias may use indices which are not considered in bounds. In such a case, accessing the base object will fail as it only peers through inbounds accesses. This pattern is used by the swift compiler to create references to preceeding members in the type metadata. This would cause the code generation to fail when targeting a platform that used ELF as the object file format. Be conservative and fail the read-only check if we run into an alias that we cannot peer through. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345107 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c9c94cd commit 3a2a1ee

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,9 +3184,11 @@ static SDValue promoteToConstantPool(const GlobalValue *GV, SelectionDAG &DAG,
31843184

31853185
bool ARMTargetLowering::isReadOnly(const GlobalValue *GV) const {
31863186
if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
3187-
GV = GA->getBaseObject();
3188-
return (isa<GlobalVariable>(GV) && cast<GlobalVariable>(GV)->isConstant()) ||
3189-
isa<Function>(GV);
3187+
if (!(GV = GA->getBaseObject()))
3188+
return false;
3189+
if (const auto *V = dyn_cast<GlobalVariable>(GV))
3190+
return V->isConstant();
3191+
return isa<Function>(GV);
31903192
}
31913193

31923194
SDValue ARMTargetLowering::LowerGlobalAddress(SDValue Op,

test/CodeGen/ARM/readonly-aliases.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: llc -mtriple thumbv7-unknown-linux-android -filetype asm -o - %s | FileCheck %s
2+
3+
@a = protected constant <{ i32, i32 }> <{ i32 0, i32 0 }>
4+
@b = protected alias i32, getelementptr(i32, i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @a, i32 0, i32 1), i32 -1)
5+
6+
declare void @f(i32*)
7+
8+
define void @g() {
9+
entry:
10+
call void @f(i32* @b)
11+
ret void
12+
}
13+
14+
; CHECK-LABEL: g:
15+
; CHECK: movw [[REGISTER:r[0-9]+]], :lower16:b
16+
; CHECK: movt [[REGISTER]], :upper16:b
17+

0 commit comments

Comments
 (0)