[llvm] r248863 - [safestack] Fix a stupid mix-up in the direct-tls code path.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 17:01:48 PDT 2015


Author: eugenis
Date: Tue Sep 29 19:01:47 2015
New Revision: 248863

URL: http://llvm.org/viewvc/llvm-project?rev=248863&view=rev
Log:
[safestack] Fix a stupid mix-up in the direct-tls code path.

Added:
    llvm/trunk/test/CodeGen/X86/safestack.ll
Modified:
    llvm/trunk/lib/Transforms/Instrumentation/SafeStack.cpp
    llvm/trunk/test/Transforms/SafeStack/X86/abi.ll

Modified: llvm/trunk/lib/Transforms/Instrumentation/SafeStack.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/SafeStack.cpp?rev=248863&r1=248862&r2=248863&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/SafeStack.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/SafeStack.cpp Tue Sep 29 19:01:47 2015
@@ -254,7 +254,7 @@ Value *SafeStack::getOrCreateUnsafeStack
   unsigned Offset;
   unsigned AddressSpace;
   // Check if the target keeps the unsafe stack pointer at a fixed offset.
-  if (TLI && TLI->getSafeStackPointerLocation(Offset, AddressSpace)) {
+  if (TLI && TLI->getSafeStackPointerLocation(AddressSpace, Offset)) {
     Constant *OffsetVal =
         ConstantInt::get(Type::getInt32Ty(F.getContext()), Offset);
     return ConstantExpr::getIntToPtr(OffsetVal,

Added: llvm/trunk/test/CodeGen/X86/safestack.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/safestack.ll?rev=248863&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/safestack.ll (added)
+++ llvm/trunk/test/CodeGen/X86/safestack.ll Tue Sep 29 19:01:47 2015
@@ -0,0 +1,32 @@
+; RUN: llc -mtriple=i386-linux < %s -o - | FileCheck --check-prefix=LINUX-I386 %s
+; RUN: llc -mtriple=x86_64-linux < %s -o - | FileCheck --check-prefix=LINUX-X64 %s
+; RUN: llc -mtriple=i386-linux-android < %s -o - | FileCheck --check-prefix=ANDROID-I386 %s
+; RUN: llc -mtriple=x86_64-linux-android < %s -o - | FileCheck --check-prefix=ANDROID-X64 %s
+
+define void @_Z1fv() safestack {
+entry:
+  %x = alloca i32, align 4
+  %0 = bitcast i32* %x to i8*
+  call void @_Z7CapturePi(i32* nonnull %x)
+  ret void
+}
+
+declare void @_Z7CapturePi(i32*)
+
+; LINUX-X64: movq __safestack_unsafe_stack_ptr at GOTTPOFF(%rip), %[[A:.*]]
+; LINUX-X64: movq %fs:(%[[A]]), %[[B:.*]]
+; LINUX-X64: leaq -16(%[[B]]), %[[C:.*]]
+; LINUX-X64: movq %[[C]], %fs:(%[[A]])
+
+; LINUX-I386: movl __safestack_unsafe_stack_ptr at INDNTPOFF, %[[A:.*]]
+; LINUX-I386: movl %gs:(%[[A]]), %[[B:.*]]
+; LINUX-I386: leal -16(%[[B]]), %[[C:.*]]
+; LINUX-I386: movl %[[C]], %gs:(%[[A]])
+
+; ANDROID-I386: movl %gs:36, %[[A:.*]]
+; ANDROID-I386: leal -16(%[[A]]), %[[B:.*]]
+; ANDROID-I386: movl %[[B]], %gs:36
+
+; ANDROID-X64: movq %fs:72, %[[A:.*]]
+; ANDROID-X64: leaq -16(%[[A]]), %[[B:.*]]
+; ANDROID-X64: movq %[[B]], %fs:72

Modified: llvm/trunk/test/Transforms/SafeStack/X86/abi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SafeStack/X86/abi.ll?rev=248863&r1=248862&r2=248863&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SafeStack/X86/abi.ll (original)
+++ llvm/trunk/test/Transforms/SafeStack/X86/abi.ll Tue Sep 29 19:01:47 2015
@@ -10,20 +10,20 @@ entry:
 ; TLS: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
 ; TLS: store i8* %[[USST]], i8** @__safestack_unsafe_stack_ptr
 
-; DIRECT-TLS32: %[[USP:.*]] = load i8*, i8* addrspace(36)* inttoptr (i32 256 to i8* addrspace(36)*)
+; DIRECT-TLS32: %[[USP:.*]] = load i8*, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
 ; DIRECT-TLS32: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
-; DIRECT-TLS32: store i8* %[[USST]], i8* addrspace(36)* inttoptr (i32 256 to i8* addrspace(36)*)
+; DIRECT-TLS32: store i8* %[[USST]], i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
 
-; DIRECT-TLS64: %[[USP:.*]] = load i8*, i8* addrspace(72)* inttoptr (i32 257 to i8* addrspace(72)*)
+; DIRECT-TLS64: %[[USP:.*]] = load i8*, i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
 ; DIRECT-TLS64: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
-; DIRECT-TLS64: store i8* %[[USST]], i8* addrspace(72)* inttoptr (i32 257 to i8* addrspace(72)*)
+; DIRECT-TLS64: store i8* %[[USST]], i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
 
   %a = alloca i8, align 8
   call void @Capture(i8* %a)
 
 ; TLS: store i8* %[[USP]], i8** @__safestack_unsafe_stack_ptr
-; DIRECT-TLS32: store i8* %[[USP]], i8* addrspace(36)* inttoptr (i32 256 to i8* addrspace(36)*)
-; DIRECT-TLS64: store i8* %[[USP]], i8* addrspace(72)* inttoptr (i32 257 to i8* addrspace(72)*)
+; DIRECT-TLS32: store i8* %[[USP]], i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
+; DIRECT-TLS64: store i8* %[[USP]], i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
   ret void
 }
 




More information about the llvm-commits mailing list