Bug 10179 - alignment attributes are not inherited correctly with empty classes
Summary: alignment attributes are not inherited correctly with empty classes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.2
: P3 normal
Target Milestone: 4.3.0
Assignee: Jason Merrill
URL:
Keywords: wrong-code
: 34747 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-21 11:46 UTC by jamagallon
Modified: 2016-05-08 00:02 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work: 4.3.0
Known to fail:
Last reconfirmed: 2007-09-27 21:21:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jamagallon 2003-03-21 11:46:01 UTC
__attribute__((__aligned__(16))) is applied to an empty base class, used just to propagate that and new/delete operators, not defined in the example (do you remember SSE...).
If derived class T is smaller than the alignment, it is obeyed so arrays of T give aligned alements. If size of T is bigger that alignment, elements in T[] are unaligned. If base is not empty, it works ok. Is this expected behaviour ?

Release:
gcc-3.2.2

Environment:
Linux Mandrake 9.1

How-To-Repeat:
#include <iostream>

using namespace std;
#define __class class __attribute__((__aligned__(16)))

__class A
{
public:
    void id() { cout << this << endl; };
};

class T : public A
{
public:
//    with 3 floats, sizeof(T)==16
//    with 5 floats, sizeof(T)==20
      float   f[5];
};

int main()
{
    A a;
    cout << "sizeof(A) = " << sizeof(A) << endl;
    cout << &a << endl;
    A aa[2];
    cout << "sizeof(A[2]) = " << sizeof(aa) << endl;
    cout << &aa[0] << endl;
    cout << &aa[1] << endl;

    T t;
    cout << "sizeof(T) = " << sizeof(T) << endl;
    cout << &t << endl;
    T tt[2];
    cout << "sizeof(T[2]) = " << sizeof(tt) << endl;
    cout << &tt[0] << endl;
    cout << &tt[1] << endl;

    return 0;
}
Comment 1 Dara Hazeghi 2003-05-31 19:50:33 UTC
Hello,

I can confirm that the behavior you observed still occurs on gcc 3.3 branch and mainline 
(20030525). Unfortunately, someone with a better grasp of alignment will have to determine if this 
is in fact a bug or not...

Dara
Comment 2 Andrew Pinski 2003-11-29 20:59:01 UTC
I can confirm this.
Comment 3 gcc_bz 2007-05-04 05:10:56 UTC
Bitten and confirmed.  gcc-4.1.1 (from cellsdk-2.0).
Comment 4 gcc_bz 2007-05-04 05:58:12 UTC
Also present in mainline as of 20070406.
Comment 5 Jason Merrill 2007-09-28 18:08:09 UTC
Subject: Bug 10179

Author: jason
Date: Fri Sep 28 18:07:57 2007
New Revision: 128871

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128871
Log:
        PR c++/10179
        * class.c (layout_empty_base): Take rli parameter, update
        rli->record_align if empty base has user-specified alignment.
        (build_base_field): Pass rli to it.

Added:
    trunk/gcc/testsuite/g++.dg/ext/align2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c

Comment 6 Jason Merrill 2007-09-28 18:11:38 UTC
Fixed for 4.3.0.
Comment 7 Martin Sebor 2016-05-08 00:02:47 UTC
*** Bug 34747 has been marked as a duplicate of this bug. ***