From 650d9427f075becaa35a675af8169f60eeb8e756 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 16 Jul 2015 22:34:20 +0000 Subject: [PATCH] Arm: Don't define a label twice with two setjmps in a function. Constructing a name based on the function name didn't give us a unique symbol if we had more than one setjmp in a function. Using MCContext::createTempSymbol() always gives us a unique name. Differential Revision: http://reviews.llvm.org/D9314 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242482 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMAsmPrinter.cpp | 15 +---- lib/Target/ARM/ARMAsmPrinter.h | 2 - test/CodeGen/Thumb2/setjmp_longjmp.ll | 89 +++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 test/CodeGen/Thumb2/setjmp_longjmp.ll diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp index e490af50b34..7f982eeabb9 100644 --- a/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/ARMAsmPrinter.cpp @@ -205,15 +205,6 @@ GetARMJTIPICJumpTableLabel(unsigned uid) const { return OutContext.getOrCreateSymbol(Name); } - -MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel() const { - const DataLayout &DL = 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) { @@ -1649,12 +1640,12 @@ void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) { // adds $val, #7 // str $val, [$src, #4] // movs r0, #0 - // b 1f + // b LSJLJEH // movs r0, #1 - // 1: + // LSJLJEH: unsigned SrcReg = MI->getOperand(0).getReg(); unsigned ValReg = MI->getOperand(1).getReg(); - MCSymbol *Label = GetARMSJLJEHLabel(); + MCSymbol *Label = OutContext.createTempSymbol("SJLJEH", false, true); OutStreamer->AddComment("eh_setjmp begin"); EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr) .addReg(ValReg) diff --git a/lib/Target/ARM/ARMAsmPrinter.h b/lib/Target/ARM/ARMAsmPrinter.h index 53b29204d57..fb925f162f7 100644 --- a/lib/Target/ARM/ARMAsmPrinter.h +++ b/lib/Target/ARM/ARMAsmPrinter.h @@ -119,8 +119,6 @@ private: MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol); MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const; - MCSymbol *GetARMSJLJEHLabel() const; - MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags); public: diff --git a/test/CodeGen/Thumb2/setjmp_longjmp.ll b/test/CodeGen/Thumb2/setjmp_longjmp.ll new file mode 100644 index 00000000000..9e0fad00c14 --- /dev/null +++ b/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 +} -- 2.34.1