diff --git a/ipc/ipdl/ipdl/cxx/ast.py b/ipc/ipdl/ipdl/cxx/ast.py index 90c87e9d0a9..1698e2932b7 100644 --- a/ipc/ipdl/ipdl/cxx/ast.py +++ b/ipc/ipdl/ipdl/cxx/ast.py @@ -358,9 +358,21 @@ class TypeUnion(Node): Node.__init__(self) self.name = name self.components = [ ] # [ Decl ] + # Expr -- evaluates to a constant value representing + # the maximum alignment of all types in the union + self.alignment = None - def addComponent(self, type, name): - self.components.append(Decl(type, name)) + def addComponent(self, c): + self.components.append(Decl(c.unionType(), c.name)) + alignme = ExprCall(ExprVar('MOZ_ALIGNOF'), [ c.internalType() ]) + if self.alignment: + self.alignment = ExprCall(ExprVar('PR_MAX'), [ alignme, self.alignment ]) + else: + self.alignment = alignme + + def addAlignment(self): + if self.alignment: + self.components.append(Decl(Type('mozilla::AlignedElem', T=self.alignment), '__align')) class Typedef(Node): def __init__(self, fromtype, totypename): diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 1fa87ec0fa1..84c9c39e142 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -2098,7 +2098,9 @@ def _generateCxxUnion(ud): # the C++ union the discunion use for storage valueunion = TypeUnion(valuetype.name) for c in ud.components: - valueunion.addComponent(c.unionType(), c.name) + valueunion.addComponent(c); + valueunion.addAlignment(); + cls.addstmts([ StmtDecl(Decl(valueunion,'')), Whitespace.NL ])