Commit d4f7bff1 authored by svenpanne's avatar svenpanne Committed by Commit bot

Replace OFFSET_OF with offsetof as far as possible.

The remaining uses need some non-mechanical work:

  * non-standard-layout type, probably due to mixed access control

  * extended field designators

Review URL: https://codereview.chromium.org/1173343006

Cr-Commit-Position: refs/heads/master@{#29071}
parent b4d3e1ce
......@@ -823,7 +823,7 @@ class Redirection {
static Redirection* FromSwiInstruction(Instruction* swi_instruction) {
char* addr_of_swi = reinterpret_cast<char*>(swi_instruction);
char* addr_of_redirection =
addr_of_swi - OFFSET_OF(Redirection, swi_instruction_);
addr_of_swi - offsetof(Redirection, swi_instruction_);
return reinterpret_cast<Redirection*>(addr_of_redirection);
}
......
......@@ -490,7 +490,7 @@ class Redirection {
static Redirection* FromHltInstruction(Instruction* redirect_call) {
char* addr_of_hlt = reinterpret_cast<char*>(redirect_call);
char* addr_of_redirection =
addr_of_hlt - OFFSET_OF(Redirection, redirect_call_);
addr_of_hlt - offsetof(Redirection, redirect_call_);
return reinterpret_cast<Redirection*>(addr_of_redirection);
}
......
......@@ -15,12 +15,9 @@
#include "src/base/logging.h"
// The expression OFFSET_OF(type, field) computes the byte-offset
// of the specified field relative to the containing type. This
// corresponds to 'offsetof' (in stddef.h), except that it doesn't
// use 0 or NULL, which causes a problem with the compiler warnings
// we have enabled (which is also why 'offsetof' doesn't seem to work).
// Here we simply use the aligned, non-zero value 16.
// TODO(all) Replace all uses of this macro with C++'s offsetof. To do that, we
// have to make sure that only standard-layout types and simple field
// designators are used.
#define OFFSET_OF(type, field) \
(reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(16)->field)) - 16)
......
......@@ -896,23 +896,19 @@ class FrameDescription {
}
static int frame_size_offset() {
return OFFSET_OF(FrameDescription, frame_size_);
return offsetof(FrameDescription, frame_size_);
}
static int pc_offset() {
return OFFSET_OF(FrameDescription, pc_);
}
static int pc_offset() { return offsetof(FrameDescription, pc_); }
static int state_offset() {
return OFFSET_OF(FrameDescription, state_);
}
static int state_offset() { return offsetof(FrameDescription, state_); }
static int continuation_offset() {
return OFFSET_OF(FrameDescription, continuation_);
return offsetof(FrameDescription, continuation_);
}
static int frame_content_offset() {
return OFFSET_OF(FrameDescription, frame_content_);
return offsetof(FrameDescription, frame_content_);
}
private:
......
......@@ -39,13 +39,13 @@ class GlobalHandles::Node {
// Maps handle location (slot) to the containing node.
static Node* FromLocation(Object** location) {
DCHECK(OFFSET_OF(Node, object_) == 0);
DCHECK(offsetof(Node, object_) == 0);
return reinterpret_cast<Node*>(location);
}
Node() {
DCHECK(OFFSET_OF(Node, class_id_) == Internals::kNodeClassIdOffset);
DCHECK(OFFSET_OF(Node, flags_) == Internals::kNodeFlagsOffset);
DCHECK(offsetof(Node, class_id_) == Internals::kNodeClassIdOffset);
DCHECK(offsetof(Node, flags_) == Internals::kNodeFlagsOffset);
STATIC_ASSERT(static_cast<int>(NodeState::kMask) ==
Internals::kNodeStateMask);
STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue);
......
......@@ -1035,7 +1035,7 @@ class Redirection {
static Redirection* FromSwiInstruction(Instruction* swi_instruction) {
char* addr_of_swi = reinterpret_cast<char*>(swi_instruction);
char* addr_of_redirection =
addr_of_swi - OFFSET_OF(Redirection, swi_instruction_);
addr_of_swi - offsetof(Redirection, swi_instruction_);
return reinterpret_cast<Redirection*>(addr_of_redirection);
}
......
......@@ -965,7 +965,7 @@ class Redirection {
static Redirection* FromSwiInstruction(Instruction* swi_instruction) {
char* addr_of_swi = reinterpret_cast<char*>(swi_instruction);
char* addr_of_redirection =
addr_of_swi - OFFSET_OF(Redirection, swi_instruction_);
addr_of_swi - offsetof(Redirection, swi_instruction_);
return reinterpret_cast<Redirection*>(addr_of_redirection);
}
......
......@@ -880,7 +880,7 @@ class Redirection {
static Redirection* FromSwiInstruction(Instruction* swi_instruction) {
char* addr_of_swi = reinterpret_cast<char*>(swi_instruction);
char* addr_of_redirection =
addr_of_swi - OFFSET_OF(Redirection, swi_instruction_);
addr_of_swi - offsetof(Redirection, swi_instruction_);
return reinterpret_cast<Redirection*>(addr_of_redirection);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -194,21 +194,21 @@ TEST(3) {
__ mr(r4, r3);
// modify field int i of struct
__ lwz(r3, MemOperand(r4, OFFSET_OF(T, i)));
__ lwz(r3, MemOperand(r4, offsetof(T, i)));
__ srwi(r5, r3, Operand(1));
__ stw(r5, MemOperand(r4, OFFSET_OF(T, i)));
__ stw(r5, MemOperand(r4, offsetof(T, i)));
// modify field char c of struct
__ lbz(r5, MemOperand(r4, OFFSET_OF(T, c)));
__ lbz(r5, MemOperand(r4, offsetof(T, c)));
__ add(r3, r5, r3);
__ slwi(r5, r5, Operand(2));
__ stb(r5, MemOperand(r4, OFFSET_OF(T, c)));
__ stb(r5, MemOperand(r4, offsetof(T, c)));
// modify field int16_t s of struct
__ lhz(r5, MemOperand(r4, OFFSET_OF(T, s)));
__ lhz(r5, MemOperand(r4, offsetof(T, s)));
__ add(r3, r5, r3);
__ srwi(r5, r5, Operand(3));
__ sth(r5, MemOperand(r4, OFFSET_OF(T, s)));
__ sth(r5, MemOperand(r4, offsetof(T, s)));
// restore frame
#if V8_TARGET_ARCH_PPC64
......@@ -278,59 +278,59 @@ TEST(4) {
__ sub(fp, ip, Operand(4));
__ mov(r4, Operand(r0));
__ vldr(d6, r4, OFFSET_OF(T, a));
__ vldr(d7, r4, OFFSET_OF(T, b));
__ vldr(d6, r4, offsetof(T, a));
__ vldr(d7, r4, offsetof(T, b));
__ vadd(d5, d6, d7);
__ vstr(d5, r4, OFFSET_OF(T, c));
__ vstr(d5, r4, offsetof(T, c));
__ vmov(r2, r3, d5);
__ vmov(d4, r2, r3);
__ vstr(d4, r4, OFFSET_OF(T, b));
__ vstr(d4, r4, offsetof(T, b));
// Load t.x and t.y, switch values, and store back to the struct.
__ vldr(s0, r4, OFFSET_OF(T, x));
__ vldr(s31, r4, OFFSET_OF(T, y));
__ vldr(s0, r4, offsetof(T, x));
__ vldr(s31, r4, offsetof(T, y));
__ vmov(s16, s0);
__ vmov(s0, s31);
__ vmov(s31, s16);
__ vstr(s0, r4, OFFSET_OF(T, x));
__ vstr(s31, r4, OFFSET_OF(T, y));
__ vstr(s0, r4, offsetof(T, x));
__ vstr(s31, r4, offsetof(T, y));
// Move a literal into a register that can be encoded in the instruction.
__ vmov(d4, 1.0);
__ vstr(d4, r4, OFFSET_OF(T, e));
__ vstr(d4, r4, offsetof(T, e));
// Move a literal into a register that requires 64 bits to encode.
// 0x3ff0000010000000 = 1.000000059604644775390625
__ vmov(d4, 1.000000059604644775390625);
__ vstr(d4, r4, OFFSET_OF(T, d));
__ vstr(d4, r4, offsetof(T, d));
// Convert from floating point to integer.
__ vmov(d4, 2.0);
__ vcvt_s32_f64(s31, d4);
__ vstr(s31, r4, OFFSET_OF(T, i));
__ vstr(s31, r4, offsetof(T, i));
// Convert from integer to floating point.
__ mov(lr, Operand(42));
__ vmov(s31, lr);
__ vcvt_f64_s32(d4, s31);
__ vstr(d4, r4, OFFSET_OF(T, f));
__ vstr(d4, r4, offsetof(T, f));
// Test vabs.
__ vldr(d1, r4, OFFSET_OF(T, g));
__ vldr(d1, r4, offsetof(T, g));
__ vabs(d0, d1);
__ vstr(d0, r4, OFFSET_OF(T, g));
__ vldr(d2, r4, OFFSET_OF(T, h));
__ vstr(d0, r4, offsetof(T, g));
__ vldr(d2, r4, offsetof(T, h));
__ vabs(d0, d2);
__ vstr(d0, r4, OFFSET_OF(T, h));
__ vstr(d0, r4, offsetof(T, h));
// Test vneg.
__ vldr(d1, r4, OFFSET_OF(T, m));
__ vldr(d1, r4, offsetof(T, m));
__ vneg(d0, d1);
__ vstr(d0, r4, OFFSET_OF(T, m));
__ vldr(d1, r4, OFFSET_OF(T, n));
__ vstr(d0, r4, offsetof(T, m));
__ vldr(d1, r4, offsetof(T, n));
__ vneg(d0, d1);
__ vstr(d0, r4, OFFSET_OF(T, n));
__ vstr(d0, r4, offsetof(T, n));
__ ldm(ia_w, sp, r4.bit() | fp.bit() | pc.bit());
......@@ -677,19 +677,19 @@ TEST(8) {
__ stm(db_w, sp, r4.bit() | fp.bit() | lr.bit());
__ sub(fp, ip, Operand(4));
__ addi(r4, r0, Operand(OFFSET_OF(D, a)));
__ addi(r4, r0, Operand(offsetof(D, a)));
__ vldm(ia_w, r4, d0, d3);
__ vldm(ia_w, r4, d4, d7);
__ addi(r4, r0, Operand(OFFSET_OF(D, a)));
__ addi(r4, r0, Operand(offsetof(D, a)));
__ vstm(ia_w, r4, d6, d7);
__ vstm(ia_w, r4, d0, d5);
__ addi(r4, r1, Operand(OFFSET_OF(F, a)));
__ addi(r4, r1, Operand(offsetof(F, a)));
__ vldm(ia_w, r4, s0, s3);
__ vldm(ia_w, r4, s4, s7);
__ addi(r4, r1, Operand(OFFSET_OF(F, a)));
__ addi(r4, r1, Operand(offsetof(F, a)));
__ vstm(ia_w, r4, s6, s7);
__ vstm(ia_w, r4, s0, s5);
......@@ -789,22 +789,22 @@ TEST(9) {
__ stm(db_w, sp, r4.bit() | fp.bit() | lr.bit());
__ sub(fp, ip, Operand(4));
__ addi(r4, r0, Operand(OFFSET_OF(D, a)));
__ addi(r4, r0, Operand(offsetof(D, a)));
__ vldm(ia, r4, d0, d3);
__ addi(r4, r4, Operand(4 * 8));
__ vldm(ia, r4, d4, d7);
__ addi(r4, r0, Operand(OFFSET_OF(D, a)));
__ addi(r4, r0, Operand(offsetof(D, a)));
__ vstm(ia, r4, d6, d7);
__ addi(r4, r4, Operand(2 * 8));
__ vstm(ia, r4, d0, d5);
__ addi(r4, r1, Operand(OFFSET_OF(F, a)));
__ addi(r4, r1, Operand(offsetof(F, a)));
__ vldm(ia, r4, s0, s3);
__ addi(r4, r4, Operand(4 * 4));
__ vldm(ia, r4, s4, s7);
__ addi(r4, r1, Operand(OFFSET_OF(F, a)));
__ addi(r4, r1, Operand(offsetof(F, a)));
__ vstm(ia, r4, s6, s7);
__ addi(r4, r4, Operand(2 * 4));
__ vstm(ia, r4, s0, s5);
......@@ -905,19 +905,19 @@ TEST(10) {
__ stm(db_w, sp, r4.bit() | fp.bit() | lr.bit());
__ sub(fp, ip, Operand(4));
__ addi(r4, r0, Operand(OFFSET_OF(D, h) + 8));
__ addi(r4, r0, Operand(offsetof(D, h) + 8));
__ vldm(db_w, r4, d4, d7);
__ vldm(db_w, r4, d0, d3);
__ addi(r4, r0, Operand(OFFSET_OF(D, h) + 8));
__ addi(r4, r0, Operand(offsetof(D, h) + 8));
__ vstm(db_w, r4, d0, d5);
__ vstm(db_w, r4, d6, d7);
__ addi(r4, r1, Operand(OFFSET_OF(F, h) + 4));
__ addi(r4, r1, Operand(offsetof(F, h) + 4));
__ vldm(db_w, r4, s4, s7);
__ vldm(db_w, r4, s0, s3);
__ addi(r4, r1, Operand(OFFSET_OF(F, h) + 4));
__ addi(r4, r1, Operand(offsetof(F, h) + 4));
__ vstm(db_w, r4, s0, s5);
__ vstm(db_w, r4, s6, s7);
......@@ -996,28 +996,28 @@ TEST(11) {
Assembler assm(isolate, NULL, 0);
// Test HeapObject untagging.
__ ldr(r1, MemOperand(r0, OFFSET_OF(I, a)));
__ ldr(r1, MemOperand(r0, offsetof(I, a)));
__ mov(r1, Operand(r1, ASR, 1), SetCC);
__ adc(r1, r1, Operand(r1), LeaveCC, cs);
__ str(r1, MemOperand(r0, OFFSET_OF(I, a)));
__ str(r1, MemOperand(r0, offsetof(I, a)));
__ ldr(r2, MemOperand(r0, OFFSET_OF(I, b)));
__ ldr(r2, MemOperand(r0, offsetof(I, b)));
__ mov(r2, Operand(r2, ASR, 1), SetCC);
__ adc(r2, r2, Operand(r2), LeaveCC, cs);
__ str(r2, MemOperand(r0, OFFSET_OF(I, b)));
__ str(r2, MemOperand(r0, offsetof(I, b)));
// Test corner cases.
__ mov(r1, Operand(0xffffffff));
__ mov(r2, Operand::Zero());
__ mov(r3, Operand(r1, ASR, 1), SetCC); // Set the carry.
__ adc(r3, r1, Operand(r2));
__ str(r3, MemOperand(r0, OFFSET_OF(I, c)));
__ str(r3, MemOperand(r0, offsetof(I, c)));
__ mov(r1, Operand(0xffffffff));
__ mov(r2, Operand::Zero());
__ mov(r3, Operand(r2, ASR, 1), SetCC); // Unset the carry.
__ adc(r3, r1, Operand(r2));
__ str(r3, MemOperand(r0, OFFSET_OF(I, d)));
__ str(r3, MemOperand(r0, offsetof(I, d)));
__ mov(pc, Operand(lr));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment