Skip to content

Commit 899e3ab

Browse files
committed
[refactor to TargetC.contributesToAggregateAlignment(BitFieldDeclaration) hook]
1 parent 0e7afc4 commit 899e3ab

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

compiler/src/dmd/dsymbolsem.d

+2-6
Original file line numberDiff line numberDiff line change
@@ -7186,15 +7186,11 @@ private extern(C++) class SetFieldOffsetVisitor : Visitor
71867186
error(bfd.loc, "bit field width %d is larger than type", bfd.fieldWidth);
71877187

71887188
const style = target.c.bitFieldStyle;
7189-
if (style != TargetC.BitFieldStyle.MS &&
7190-
style != TargetC.BitFieldStyle.Gcc_Clang &&
7191-
style != TargetC.BitFieldStyle.Gcc_Clang_ARM)
7192-
{
7189+
if (style != TargetC.BitFieldStyle.MS && style != TargetC.BitFieldStyle.Gcc_Clang)
71937190
assert(0, "unsupported bit-field style");
7194-
}
71957191

71967192
const isMicrosoftStyle = style == TargetC.BitFieldStyle.MS;
7197-
const contributesToAggregateAlignment = !anon || style != TargetC.BitFieldStyle.Gcc_Clang;
7193+
const contributesToAggregateAlignment = target.c.contributesToAggregateAlignment(bfd);
71987194

71997195
void startNewField()
72007196
{

compiler/src/dmd/frontend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5938,7 +5938,6 @@ struct TargetC final
59385938
Unspecified = 0u,
59395939
MS = 1u,
59405940
Gcc_Clang = 2u,
5941-
Gcc_Clang_ARM = 3u,
59425941
};
59435942

59445943
bool crtDestructorsSupported;
@@ -5951,6 +5950,7 @@ struct TargetC final
59515950
uint8_t wchar_tsize;
59525951
Runtime runtime;
59535952
BitFieldStyle bitFieldStyle;
5953+
bool contributesToAggregateAlignment(BitFieldDeclaration* bfd);
59545954
TargetC() :
59555955
crtDestructorsSupported(true),
59565956
boolsize(),

compiler/src/dmd/target.d

+20-3
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,8 @@ extern (C++) struct Target
13601360
*/
13611361
struct TargetC
13621362
{
1363+
import dmd.declaration : BitFieldDeclaration;
1364+
13631365
enum Runtime : ubyte
13641366
{
13651367
Unspecified,
@@ -1379,9 +1381,6 @@ struct TargetC
13791381
/// https://docs.microsoft.com/en-us/cpp/c-language/c-bit-fields?view=msvc-160
13801382
/// https://docs.microsoft.com/en-us/cpp/cpp/cpp-bit-fields?view=msvc-160
13811383
Gcc_Clang, /// gcc and clang
1382-
Gcc_Clang_ARM, /// Like `Gcc_Clang`, except that anonymous and 0-length bit fields contribute
1383-
/// to the aggregate alignment. Used for 32 & 64 bit ARM targets, except for
1384-
/// Apple ARM64.
13851384
}
13861385
bool crtDestructorsSupported = true; /// Not all platforms support crt_destructor
13871386
ubyte boolsize; /// size of a C `_Bool` type
@@ -1452,6 +1451,24 @@ struct TargetC
14521451
crtDestructorsSupported = false;
14531452
}
14541453
}
1454+
1455+
/**
1456+
* Indicates whether the specified bit-field contributes to the alignment
1457+
* of the containing aggregate.
1458+
* E.g., (not all) ARM ABIs do NOT ignore anonymous (incl. 0-length)
1459+
* bit-fields.
1460+
*/
1461+
extern (C++) bool contributesToAggregateAlignment(BitFieldDeclaration bfd)
1462+
{
1463+
if (bitFieldStyle == BitFieldStyle.MS)
1464+
return true;
1465+
if (bitFieldStyle == BitFieldStyle.Gcc_Clang)
1466+
{
1467+
// sufficient for DMD's currently supported architectures
1468+
return !bfd.isAnonymous();
1469+
}
1470+
assert(0);
1471+
}
14551472
}
14561473

14571474
////////////////////////////////////////////////////////////////////////////////

compiler/src/dmd/target.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "globals.h"
1717
#include "tokens.h"
1818

19+
class BitFieldDeclaration;
1920
class ClassDeclaration;
2021
class Dsymbol;
2122
class Expression;
@@ -65,9 +66,6 @@ struct TargetC
6566
// https://docs.microsoft.com/en-us/cpp/c-language/c-bit-fields?view=msvc-160
6667
// https://docs.microsoft.com/en-us/cpp/cpp/cpp-bit-fields?view=msvc-160
6768
Gcc_Clang, // gcc and clang
68-
Gcc_Clang_ARM, // Like `Gcc_Clang`, except that anonymous and 0-length bit fields contribute
69-
// to the aggregate alignment. Used for 32 & 64 bit ARM targets, except for
70-
// Apple ARM64.
7169
};
7270

7371
uint8_t crtDestructorsSupported; // Not all platforms support crt_destructor
@@ -80,6 +78,8 @@ struct TargetC
8078
uint8_t wchar_tsize; // size of a C 'wchar_t' type
8179
Runtime runtime;
8280
BitFieldStyle bitFieldStyle; // different C compilers do it differently
81+
82+
bool contributesToAggregateAlignment(BitFieldDeclaration *bfd);
8383
};
8484

8585
struct TargetCPP

compiler/src/dmd/todt.d

-1
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,6 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
958958
switch (target.c.bitFieldStyle)
959959
{
960960
case TargetC.BitFieldStyle.Gcc_Clang:
961-
case TargetC.BitFieldStyle.Gcc_Clang_ARM:
962961
bitFieldSize = (bf.bitOffset + bf.fieldWidth + 7) / 8;
963962
break;
964963

0 commit comments

Comments
 (0)