Index: lib/Target/ARM/ARMAsmPrinter.h =================================================================== --- lib/Target/ARM/ARMAsmPrinter.h +++ lib/Target/ARM/ARMAsmPrinter.h @@ -119,8 +119,6 @@ MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol); MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const; - MCSymbol *GetARMSJLJEHLabel() const; - MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags); public: Index: lib/Target/ARM/ARMAsmPrinter.cpp =================================================================== --- lib/Target/ARM/ARMAsmPrinter.cpp +++ lib/Target/ARM/ARMAsmPrinter.cpp @@ -210,15 +210,6 @@ return OutContext.GetOrCreateSymbol(Name); } - -MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel() const { - const DataLayout *DL = TM.getDataLayout(); - SmallString<60> Name; - raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "SJLJEH" - << getFunctionNumber(); - return OutContext.GetOrCreateSymbol(Name); -} - bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, unsigned AsmVariant, const char *ExtraCode, raw_ostream &O) { @@ -1666,7 +1657,6 @@ // 1: unsigned SrcReg = MI->getOperand(0).getReg(); unsigned ValReg = MI->getOperand(1).getReg(); - MCSymbol *Label = GetARMSJLJEHLabel(); OutStreamer->AddComment("eh_setjmp begin"); EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr) .addReg(ValReg) @@ -1703,7 +1693,8 @@ .addImm(ARMCC::AL) .addReg(0)); - const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, OutContext); + MCSymbol *LabelRef = OutContext.GetDirectionalLocalSymbol(0, false); + const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(LabelRef, OutContext); EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tB) .addExpr(SymbolExpr) .addImm(ARMCC::AL) @@ -1718,6 +1709,7 @@ .addImm(ARMCC::AL) .addReg(0)); + MCSymbol *Label = OutContext.CreateDirectionalLocalSymbol(0); OutStreamer->EmitLabel(Label); return; } Index: test/CodeGen/Thumb2/setjmp_longjmp.ll =================================================================== --- /dev/null +++ test/CodeGen/Thumb2/setjmp_longjmp.ll @@ -0,0 +1,89 @@ +; RUN: llc %s -o - | FileCheck %s +target triple = "thumbv7-apple-ios" + +declare i32 @llvm.eh.sjlj.setjmp(i8*) +declare void @llvm.eh.sjlj.longjmp(i8*) +declare i8* @llvm.frameaddress(i32) +declare i8* @llvm.stacksave() +@g = external global i32 + +; CHECK-LABEL: double_foobar +; +; setjmp sequence: +; CHECK: mov [[PCREG:r[0-9]+]], pc +; CHECK-NEXT: adds [[PCREG]], [[PCREG]], #7 +; CHECK-NEXT: str [[PCREG]], {{\[}}[[BUFREG:r[0-9]+]], #4] +; CHECK-NEXT: movs r0, #0 +; CHECK-NEXT: b [[LABEL:L[a-zA-Z0-9]+]] +; CHECK-NEXT: movs r0, #1 +; CHECK-NEXT: [[LABEL]]: +; +; setjmp sequence 2: +; CHECK: mov [[PCREG:r[0-9]+]], pc +; CHECK-NEXT: adds [[PCREG]], [[PCREG]], #7 +; CHECK-NEXT: str [[PCREG]], {{\[}}[[BUFREG:r[0-9]+]], #4] +; CHECK-NEXT: movs r0, #0 +; CHECK-NEXT: b [[LABEL:L[a-zA-Z0-9]+]] +; CHECK-NEXT: movs r0, #1 +; CHECK-NEXT: [[LABEL]]: + +; longjmp sequence: +; CHECK: ldr [[TEMPREG:r[0-9]+]], [{{\s*}}[[BUFREG:r[0-9]+]], #8] +; CHECK-NEXT: mov sp, [[TEMPREG]] +; CHECK-NEXT: ldr [[DESTREG:r[0-9]+]], {{\[}}[[BUFREG]], #4] +; CHECK-NEXT: ldr r7, {{\[}}[[BUFREG]]{{\]}} +; CHECK-NEXT: bx [[DESTREG]] +; +; longjmp sequence2: +; CHECK: ldr [[TEMPREG:r[0-9]+]], [{{\s*}}[[BUFREG:r[0-9]+]], #8] +; CHECK-NEXT: mov sp, [[TEMPREG]] +; CHECK-NEXT: ldr [[DESTREG:r[0-9]+]], {{\[}}[[BUFREG]], #4] +; CHECK-NEXT: ldr r7, {{\[}}[[BUFREG]]{{\]}} +; CHECK-NEXT: bx [[DESTREG]] +define void @double_foobar() { +entry: + %buf = alloca [5 x i8*], align 4 + %bufptr = bitcast [5 x i8*]* %buf to i8* + %arraydecay = getelementptr inbounds [5 x i8*], [5 x i8*]* %buf, i32 0, i32 0 + + %fa = tail call i8* @llvm.frameaddress(i32 0) + store i8* %fa, i8** %arraydecay, align 4 + %ss = tail call i8* @llvm.stacksave() + %ssgep = getelementptr [5 x i8*], [5 x i8*]* %buf, i32 0, i32 2 + store i8* %ss, i8** %ssgep, align 4 + + %setjmpres = call i32 @llvm.eh.sjlj.setjmp(i8* %bufptr) + %tobool = icmp ne i32 %setjmpres, 0 + br i1 %tobool, label %if.then, label %if.else + +if.then: + store volatile i32 1, i32* @g, align 4 + br label %if.end + +if.else: + store volatile i32 0, i32* @g, align 4 + call void @llvm.eh.sjlj.longjmp(i8* %bufptr) + unreachable + +if.end: + %fa2 = tail call i8* @llvm.frameaddress(i32 0) + store i8* %fa2, i8** %arraydecay, align 4 + %ss2 = tail call i8* @llvm.stacksave() + store i8* %ss2, i8** %ssgep, align 4 + + %setjmpres2 = call i32 @llvm.eh.sjlj.setjmp(i8* %bufptr) + %tobool2 = icmp ne i32 %setjmpres2, 0 + br i1 %tobool2, label %if2.then, label %if2.else + +if2.then: + store volatile i32 3, i32* @g, align 4 + br label %if2.end + +if2.else: + store volatile i32 2, i32* @g, align 4 + call void @llvm.eh.sjlj.longjmp(i8* %bufptr) + unreachable + +if2.end: + ret void +}