r218889 - [x32/NaCl] Check if method pointers straddle an eightbyte to classify Hi
Jan Wen Voung
jvoung at google.com
Thu Oct 2 09:56:57 PDT 2014
Author: jvoung
Date: Thu Oct 2 11:56:57 2014
New Revision: 218889
URL: http://llvm.org/viewvc/llvm-project?rev=218889&view=rev
Log:
[x32/NaCl] Check if method pointers straddle an eightbyte to classify Hi
Summary:
Currently, with struct my_struct { int x; method_ptr y; };
a call to foo(my_struct s) may end up dropping the last 4 bytes
of the method pointer for x86_64 NaCl and x32.
When checking Has64BitPointers, also check if the method pointer
straddles an eightbyte boundary and classify Hi as well as Lo if needed.
Test Plan: test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp
Reviewers: dschuff, pavel.v.chupin
Subscribers: jfb
Differential Revision: http://reviews.llvm.org/D5555
Added:
cfe/trunk/test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp (with props)
Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp
Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=218889&r1=218888&r2=218889&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Oct 2 11:56:57 2014
@@ -1695,10 +1695,25 @@ void X86_64ABIInfo::classify(QualType Ty
}
if (Ty->isMemberPointerType()) {
- if (Ty->isMemberFunctionPointerType() && Has64BitPointers)
- Lo = Hi = Integer;
- else
+ if (Ty->isMemberFunctionPointerType()) {
+ if (Has64BitPointers) {
+ // If Has64BitPointers, this is an {i64, i64}, so classify both
+ // Lo and Hi now.
+ Lo = Hi = Integer;
+ } else {
+ // Otherwise, with 32-bit pointers, this is an {i32, i32}. If that
+ // straddles an eightbyte boundary, Hi should be classified as well.
+ uint64_t EB_FuncPtr = (OffsetBase) / 64;
+ uint64_t EB_ThisAdj = (OffsetBase + 64 - 1) / 64;
+ if (EB_FuncPtr != EB_ThisAdj) {
+ Lo = Hi = Integer;
+ } else {
+ Current = Integer;
+ }
+ }
+ } else {
Current = Integer;
+ }
return;
}
Added: cfe/trunk/test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp?rev=218889&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp Thu Oct 2 11:56:57 2014
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-nacl -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnux32 -emit-llvm -o - %s | FileCheck %s
+
+struct test_struct {};
+typedef int test_struct::* test_struct_mdp;
+typedef int (test_struct::*test_struct_mfp)();
+
+// CHECK-LABEL: define i32 @{{.*}}f_mdp{{.*}}(i32 %a)
+test_struct_mdp f_mdp(test_struct_mdp a) { return a; }
+
+// CHECK-LABEL: define {{.*}} @{{.*}}f_mfp{{.*}}(i64 %a.coerce)
+test_struct_mfp f_mfp(test_struct_mfp a) { return a; }
+
+// A struct with <= 12 bytes before a member data pointer should still
+// be allowed in registers, since the member data pointer is only 4 bytes.
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mdp{{.*}}(i64 %a.coerce0, i64 %a.coerce1)
+struct struct_with_mdp { char *a; char *b; char *c; test_struct_mdp d; };
+void f_struct_with_mdp(struct_with_mdp a) { (void)a; }
+
+struct struct_with_mdp_too_much {
+ char *a; char *b; char *c; char *d; test_struct_mdp e;
+};
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mdp_too_much{{.*}}({{.*}} byval {{.*}} %a)
+void f_struct_with_mdp_too_much(struct_with_mdp_too_much a) {
+ (void)a;
+}
+
+// A struct with <= 8 bytes before a member function pointer should still
+// be allowed in registers, since the member function pointer is only 8 bytes.
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_0{{.*}}(i64 %a.coerce0, i32 %a.coerce1)
+struct struct_with_mfp_0 { char *a; test_struct_mfp b; };
+void f_struct_with_mfp_0(struct_with_mfp_0 a) { (void)a; }
+
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_1{{.*}}(i64 %a.coerce0, i64 %a.coerce1)
+struct struct_with_mfp_1 { char *a; char *b; test_struct_mfp c; };
+void f_struct_with_mfp_1(struct_with_mfp_1 a) { (void)a; }
+
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_too_much{{.*}}({{.*}} byval {{.*}} %a, i32 %x)
+struct struct_with_mfp_too_much {
+ char *a; char *b; char *c; test_struct_mfp d;
+};
+void f_struct_with_mfp_too_much(struct_with_mfp_too_much a, int x) {
+ (void)a;
+}
Propchange: cfe/trunk/test/CodeGenCXX/x86_64-arguments-nacl-x32.cpp
------------------------------------------------------------------------------
svn:eol-style = LF
Modified: cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp?rev=218889&r1=218888&r2=218889&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp Thu Oct 2 11:56:57 2014
@@ -32,6 +32,21 @@ typedef int (s4::*s4_mfp)();
s4_mdp f4_0(s4_mdp a) { return a; }
s4_mfp f4_1(s4_mfp a) { return a; }
+// A struct with <= one eightbyte before a member data pointer should still
+// be allowed in registers.
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mdp{{.*}}(i8* %a.coerce0, i64 %a.coerce1)
+struct struct_with_mdp { char *a; s4_mdp b; };
+void f_struct_with_mdp(struct_with_mdp a) { (void)a; }
+
+// A struct with anything before a member function will be too big and
+// goes in memory.
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_0{{.*}}(%struct{{.*}} byval align 8 %a)
+struct struct_with_mfp_0 { char a; s4_mfp b; };
+void f_struct_with_mfp_0(struct_with_mfp_0 a) { (void)a; }
+
+// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_1{{.*}}(%struct{{.*}} byval align 8 %a)
+struct struct_with_mfp_1 { void *a; s4_mfp b; };
+void f_struct_with_mfp_1(struct_with_mfp_1 a) { (void)a; }
namespace PR7523 {
struct StringRef {
More information about the cfe-commits
mailing list