Skip to content

Commit effcd90

Browse files
committed
[X86] Avoid crashing in PIC mode on narrowing to i8 followed by extention to i32
1 parent 714b2fd commit effcd90

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ void InstrEmitter::EmitSubregNode(SDNode *Node, VRBaseMapType &VRBaseMap,
631631
void
632632
InstrEmitter::EmitCopyToRegClassNode(SDNode *Node,
633633
VRBaseMapType &VRBaseMap) {
634-
Register VReg = getVR(Node->getOperand(0), VRBaseMap);
634+
RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node->getOperand(0));
635+
unsigned VReg = R ? R->getReg() : getVR(Node->getOperand(0), VRBaseMap);
635636

636637
// Create the new VReg in the destination class and emit a copy.
637638
unsigned DstRCIdx = Node->getConstantOperandVal(1);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -relocation-model=pic < %s | FileCheck %s
3+
4+
target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
5+
target triple = "i386-unknown-linux-gnu"
6+
7+
@.str = external dso_local global i32
8+
9+
define i1 @test() {
10+
; CHECK-LABEL: test:
11+
; CHECK: # %bb.0:
12+
; CHECK-NEXT: calll .L0$pb
13+
; CHECK-NEXT: .cfi_adjust_cfa_offset 4
14+
; CHECK-NEXT: .L0$pb:
15+
; CHECK-NEXT: popl %eax
16+
; CHECK-NEXT: .cfi_adjust_cfa_offset -4
17+
; CHECK-NEXT: .Ltmp0:
18+
; CHECK-NEXT: addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax
19+
; CHECK-NEXT: movl $.str@GOTOFF, %ecx
20+
; CHECK-NEXT: addb %al, %cl
21+
; CHECK-NEXT: sete %al
22+
; CHECK-NEXT: retl
23+
%i = ptrtoint ptr @.str to i8
24+
%p = zext i8 %i to i32
25+
%c = icmp eq i32 %p, 0
26+
ret i1 %c
27+
}

0 commit comments

Comments
 (0)