File indexing completed on 2024-04-28 05:41:06

0001 /*
0002     Copyright (C) 2015 Volker Krause <vkrause@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <https://www.gnu.org/licenses/>.
0016 */
0017 
0018 struct AlignedBase {
0019     void* m_base;
0020 };
0021 
0022 struct AlignedIntermediateA : virtual public AlignedBase {
0023     void* m_a;
0024 };
0025 
0026 struct AlignedIntermediateB : virtual public AlignedBase {
0027     void* m_b;
0028 };
0029 
0030 struct AlignedDereived : public AlignedIntermediateA, public AlignedIntermediateB {
0031     void* m_d;
0032 };
0033 
0034 
0035 struct UnalignedBase {
0036     int m_base;
0037 };
0038 
0039 struct UnalignedIntermediateA : virtual public UnalignedBase {
0040     void* m_a;
0041 };
0042 
0043 struct UnalignedIntermediateB : virtual public UnalignedBase {
0044     bool m_b;
0045 };
0046 
0047 struct UnalignedDerived : public UnalignedIntermediateA, public UnalignedIntermediateB {
0048     short m_d;
0049 };
0050 
0051 
0052 int main (int, char**)
0053 {
0054     // make sure the structures aren't optimized away by the compiler
0055     unsigned long long dummy = 0;
0056     #define USED(StructType) { StructType s; dummy += (unsigned long long)&s; }
0057 
0058     USED(AlignedBase)
0059     USED(AlignedIntermediateA)
0060     USED(AlignedIntermediateB)
0061     USED(AlignedDereived)
0062     USED(UnalignedDerived)
0063 
0064     return dummy;
0065 }