[PATCH] D108858: TypeInfo records more information about align requirement

2021-08-28 Thread Steven Wan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG73733ae526a5: TypeInfo records more information about align 
requirement (authored by stevewan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108858/new/

https://reviews.llvm.org/D108858

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1839,7 +1839,7 @@
 
 // Pass over-aligned aggregates on Windows indirectly. This behavior was
 // added in MSVC 2015.
-if (IsWin32StructABI && TI.AlignIsRequired && TI.Align > 32)
+if (IsWin32StructABI && TI.isAlignRequired() && TI.Align > 32)
   return getIndirectResult(Ty, /*ByVal=*/false, State);
 
 // Expand small (<= 128-bit) record types when we know that the stack layout
@@ -6992,7 +6992,7 @@
 TyAlignForABI = CharUnits::fromQuantity(4);
   }
 
-  TypeInfoChars TyInfo(TySize, TyAlignForABI, false);
+  TypeInfoChars TyInfo(TySize, TyAlignForABI, AlignRequirementKind::None);
   return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, TyInfo,
   SlotSize, /*AllowHigherAlign*/ true);
 }
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -847,7 +847,7 @@
 // arguments was not supported and resulted in a compiler error. In 19.14
 // and later versions, such arguments are now passed indirectly.
 TypeInfo Info = getContext().getTypeInfo(RD->getTypeForDecl());
-if (Info.AlignIsRequired && Info.Align > 4)
+if (Info.isAlignRequired() && Info.Align > 4)
   return RAA_Indirect;
 
 // If C++ prohibits us from making a copy, construct the arguments directly
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -52,7 +52,7 @@
 
 static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext ) {
   auto TI = Ctx.getTypeInfo(Ty);
-  return TI.AlignIsRequired ? TI.Align : 0;
+  return TI.isAlignRequired() ? TI.Align : 0;
 }
 
 static uint32_t getTypeAlignIfRequired(QualType Ty, const ASTContext ) {
@@ -4676,7 +4676,7 @@
 llvm::DIType *fieldType;
 if (capture->isByRef()) {
   TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
-  auto Align = PtrInfo.AlignIsRequired ? PtrInfo.Align : 0;
+  auto Align = PtrInfo.isAlignRequired() ? PtrInfo.Align : 0;
   // FIXME: This recomputes the layout of the BlockByRefWrapper.
   uint64_t xoffset;
   fieldType =
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1538,7 +1538,7 @@
   TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
   uint64_t StorageUnitSize = FieldInfo.Width;
   unsigned FieldAlign = FieldInfo.Align;
-  bool AlignIsRequired = FieldInfo.AlignIsRequired;
+  bool AlignIsRequired = FieldInfo.isAlignRequired();
 
   // UnfilledBitsInLastUnit is the difference between the end of the
   // last allocated bitfield (i.e. the first bit offset available for
@@ -1889,7 +1889,7 @@
 
   bool FieldPacked = Packed || D->hasAttr();
 
-  bool AlignIsRequired = false;
+  AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;
   CharUnits FieldAlign;
   // The amount of this class's dsize occupied by the field.
@@ -1904,7 +1904,7 @@
 // aligned appropriately for their element type.
 EffectiveFieldSize = FieldSize =
 IsIncompleteArrayType ? CharUnits::Zero() : TI.Width;
-AlignIsRequired = TI.AlignIsRequired;
+AlignRequirement = TI.AlignRequirement;
   };
 
   if (D->getType()->isIncompleteArrayType()) {
@@ -1978,7 +1978,8 @@
   // and zero-width bit-fields count as prior members; members of empty class
   // types marked `no_unique_address` are not considered to be prior members.
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment &&
+  AlignRequirement == AlignRequirementKind::None &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
 auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
   if (BTy->getKind() == BuiltinType::Double ||
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1858,7 

[PATCH] D108858: TypeInfo records more information about align requirement

2021-08-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108858/new/

https://reviews.llvm.org/D108858

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108858: TypeInfo records more information about align requirement

2021-08-28 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 369258.
stevewan added a comment.

Add RequiredByEnum case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108858/new/

https://reviews.llvm.org/D108858

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1839,7 +1839,7 @@
 
 // Pass over-aligned aggregates on Windows indirectly. This behavior was
 // added in MSVC 2015.
-if (IsWin32StructABI && TI.AlignIsRequired && TI.Align > 32)
+if (IsWin32StructABI && TI.isAlignRequired() && TI.Align > 32)
   return getIndirectResult(Ty, /*ByVal=*/false, State);
 
 // Expand small (<= 128-bit) record types when we know that the stack layout
@@ -6992,7 +6992,7 @@
 TyAlignForABI = CharUnits::fromQuantity(4);
   }
 
-  TypeInfoChars TyInfo(TySize, TyAlignForABI, false);
+  TypeInfoChars TyInfo(TySize, TyAlignForABI, AlignRequirementKind::None);
   return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, TyInfo,
   SlotSize, /*AllowHigherAlign*/ true);
 }
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -847,7 +847,7 @@
 // arguments was not supported and resulted in a compiler error. In 19.14
 // and later versions, such arguments are now passed indirectly.
 TypeInfo Info = getContext().getTypeInfo(RD->getTypeForDecl());
-if (Info.AlignIsRequired && Info.Align > 4)
+if (Info.isAlignRequired() && Info.Align > 4)
   return RAA_Indirect;
 
 // If C++ prohibits us from making a copy, construct the arguments directly
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -52,7 +52,7 @@
 
 static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext ) {
   auto TI = Ctx.getTypeInfo(Ty);
-  return TI.AlignIsRequired ? TI.Align : 0;
+  return TI.isAlignRequired() ? TI.Align : 0;
 }
 
 static uint32_t getTypeAlignIfRequired(QualType Ty, const ASTContext ) {
@@ -4676,7 +4676,7 @@
 llvm::DIType *fieldType;
 if (capture->isByRef()) {
   TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
-  auto Align = PtrInfo.AlignIsRequired ? PtrInfo.Align : 0;
+  auto Align = PtrInfo.isAlignRequired() ? PtrInfo.Align : 0;
   // FIXME: This recomputes the layout of the BlockByRefWrapper.
   uint64_t xoffset;
   fieldType =
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1538,7 +1538,7 @@
   TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
   uint64_t StorageUnitSize = FieldInfo.Width;
   unsigned FieldAlign = FieldInfo.Align;
-  bool AlignIsRequired = FieldInfo.AlignIsRequired;
+  bool AlignIsRequired = FieldInfo.isAlignRequired();
 
   // UnfilledBitsInLastUnit is the difference between the end of the
   // last allocated bitfield (i.e. the first bit offset available for
@@ -1889,7 +1889,7 @@
 
   bool FieldPacked = Packed || D->hasAttr();
 
-  bool AlignIsRequired = false;
+  AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;
   CharUnits FieldAlign;
   // The amount of this class's dsize occupied by the field.
@@ -1904,7 +1904,7 @@
 // aligned appropriately for their element type.
 EffectiveFieldSize = FieldSize =
 IsIncompleteArrayType ? CharUnits::Zero() : TI.Width;
-AlignIsRequired = TI.AlignIsRequired;
+AlignRequirement = TI.AlignRequirement;
   };
 
   if (D->getType()->isIncompleteArrayType()) {
@@ -1978,7 +1978,8 @@
   // and zero-width bit-fields count as prior members; members of empty class
   // types marked `no_unique_address` are not considered to be prior members.
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment &&
+  AlignRequirement == AlignRequirementKind::None &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
 auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
   if (BTy->getKind() == BuiltinType::Double ||
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1858,7 +1858,7 @@
 Width = llvm::alignTo(Width, Align);
   return 

[PATCH] D108858: TypeInfo records more information about align requirement

2021-08-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks.  Generally looks good; feel free to commit after adding a 
`RequiredByEnum` case and making sure it compiles.




Comment at: clang/lib/AST/ASTContext.cpp:2300
 Info.Align = AttrAlign;
-Info.AlignIsRequired = true;
+Info.AlignRequirement = AlignRequirementKind::RequiredByRecord;
   }

Oh, I guess "record" is imprecise here.  We might as well add a 
`RequiredByEnum` case, then, just to be fully accurate; there's no real harm to 
it.



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:1981
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment && !isAlignRequired() &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {

Bug here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108858/new/

https://reviews.llvm.org/D108858

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108858: TypeInfo records more information about align requirement

2021-08-28 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 369240.
stevewan added a comment.

Fix enum usage


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108858/new/

https://reviews.llvm.org/D108858

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1839,7 +1839,7 @@
 
 // Pass over-aligned aggregates on Windows indirectly. This behavior was
 // added in MSVC 2015.
-if (IsWin32StructABI && TI.AlignIsRequired && TI.Align > 32)
+if (IsWin32StructABI && TI.isAlignRequired() && TI.Align > 32)
   return getIndirectResult(Ty, /*ByVal=*/false, State);
 
 // Expand small (<= 128-bit) record types when we know that the stack layout
@@ -6992,7 +6992,7 @@
 TyAlignForABI = CharUnits::fromQuantity(4);
   }
 
-  TypeInfoChars TyInfo(TySize, TyAlignForABI, false);
+  TypeInfoChars TyInfo(TySize, TyAlignForABI, AlignRequirementKind::None);
   return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, TyInfo,
   SlotSize, /*AllowHigherAlign*/ true);
 }
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -847,7 +847,7 @@
 // arguments was not supported and resulted in a compiler error. In 19.14
 // and later versions, such arguments are now passed indirectly.
 TypeInfo Info = getContext().getTypeInfo(RD->getTypeForDecl());
-if (Info.AlignIsRequired && Info.Align > 4)
+if (Info.isAlignRequired() && Info.Align > 4)
   return RAA_Indirect;
 
 // If C++ prohibits us from making a copy, construct the arguments directly
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -52,7 +52,7 @@
 
 static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext ) {
   auto TI = Ctx.getTypeInfo(Ty);
-  return TI.AlignIsRequired ? TI.Align : 0;
+  return TI.isAlignRequired() ? TI.Align : 0;
 }
 
 static uint32_t getTypeAlignIfRequired(QualType Ty, const ASTContext ) {
@@ -4676,7 +4676,7 @@
 llvm::DIType *fieldType;
 if (capture->isByRef()) {
   TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
-  auto Align = PtrInfo.AlignIsRequired ? PtrInfo.Align : 0;
+  auto Align = PtrInfo.isAlignRequired() ? PtrInfo.Align : 0;
   // FIXME: This recomputes the layout of the BlockByRefWrapper.
   uint64_t xoffset;
   fieldType =
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1538,7 +1538,7 @@
   TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
   uint64_t StorageUnitSize = FieldInfo.Width;
   unsigned FieldAlign = FieldInfo.Align;
-  bool AlignIsRequired = FieldInfo.AlignIsRequired;
+  bool AlignIsRequired = FieldInfo.isAlignRequired();
 
   // UnfilledBitsInLastUnit is the difference between the end of the
   // last allocated bitfield (i.e. the first bit offset available for
@@ -1889,7 +1889,7 @@
 
   bool FieldPacked = Packed || D->hasAttr();
 
-  bool AlignIsRequired = false;
+  AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;
   CharUnits FieldAlign;
   // The amount of this class's dsize occupied by the field.
@@ -1904,7 +1904,7 @@
 // aligned appropriately for their element type.
 EffectiveFieldSize = FieldSize =
 IsIncompleteArrayType ? CharUnits::Zero() : TI.Width;
-AlignIsRequired = TI.AlignIsRequired;
+AlignRequirement = TI.AlignRequirement;
   };
 
   if (D->getType()->isIncompleteArrayType()) {
@@ -1978,7 +1978,8 @@
   // and zero-width bit-fields count as prior members; members of empty class
   // types marked `no_unique_address` are not considered to be prior members.
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment &&
+  AlignRequirement == AlignRequirementKind::None &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
 auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
   if (BTy->getKind() == BuiltinType::Double ||
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1858,7 +1858,7 @@
 Width = llvm::alignTo(Width, Align);
   return 

[PATCH] D108858: TypeInfo records more information about align requirement

2021-08-27 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 369235.
stevewan added a comment.

Oops missed one flag.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108858/new/

https://reviews.llvm.org/D108858

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1839,7 +1839,7 @@
 
 // Pass over-aligned aggregates on Windows indirectly. This behavior was
 // added in MSVC 2015.
-if (IsWin32StructABI && TI.AlignIsRequired && TI.Align > 32)
+if (IsWin32StructABI && TI.isAlignRequired() && TI.Align > 32)
   return getIndirectResult(Ty, /*ByVal=*/false, State);
 
 // Expand small (<= 128-bit) record types when we know that the stack layout
@@ -6992,7 +6992,7 @@
 TyAlignForABI = CharUnits::fromQuantity(4);
   }
 
-  TypeInfoChars TyInfo(TySize, TyAlignForABI, false);
+  TypeInfoChars TyInfo(TySize, TyAlignForABI, AlignRequirementKind::None);
   return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, TyInfo,
   SlotSize, /*AllowHigherAlign*/ true);
 }
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -847,7 +847,7 @@
 // arguments was not supported and resulted in a compiler error. In 19.14
 // and later versions, such arguments are now passed indirectly.
 TypeInfo Info = getContext().getTypeInfo(RD->getTypeForDecl());
-if (Info.AlignIsRequired && Info.Align > 4)
+if (Info.isAlignRequired() && Info.Align > 4)
   return RAA_Indirect;
 
 // If C++ prohibits us from making a copy, construct the arguments directly
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -52,7 +52,7 @@
 
 static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext ) {
   auto TI = Ctx.getTypeInfo(Ty);
-  return TI.AlignIsRequired ? TI.Align : 0;
+  return TI.isAlignRequired() ? TI.Align : 0;
 }
 
 static uint32_t getTypeAlignIfRequired(QualType Ty, const ASTContext ) {
@@ -4676,7 +4676,7 @@
 llvm::DIType *fieldType;
 if (capture->isByRef()) {
   TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
-  auto Align = PtrInfo.AlignIsRequired ? PtrInfo.Align : 0;
+  auto Align = PtrInfo.isAlignRequired() ? PtrInfo.Align : 0;
   // FIXME: This recomputes the layout of the BlockByRefWrapper.
   uint64_t xoffset;
   fieldType =
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1538,7 +1538,7 @@
   TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
   uint64_t StorageUnitSize = FieldInfo.Width;
   unsigned FieldAlign = FieldInfo.Align;
-  bool AlignIsRequired = FieldInfo.AlignIsRequired;
+  bool AlignIsRequired = FieldInfo.isAlignRequired();
 
   // UnfilledBitsInLastUnit is the difference between the end of the
   // last allocated bitfield (i.e. the first bit offset available for
@@ -1889,7 +1889,7 @@
 
   bool FieldPacked = Packed || D->hasAttr();
 
-  bool AlignIsRequired = false;
+  AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;
   CharUnits FieldAlign;
   // The amount of this class's dsize occupied by the field.
@@ -1904,7 +1904,7 @@
 // aligned appropriately for their element type.
 EffectiveFieldSize = FieldSize =
 IsIncompleteArrayType ? CharUnits::Zero() : TI.Width;
-AlignIsRequired = TI.AlignIsRequired;
+AlignRequirement = TI.AlignRequirement;
   };
 
   if (D->getType()->isIncompleteArrayType()) {
@@ -1978,7 +1978,7 @@
   // and zero-width bit-fields count as prior members; members of empty class
   // types marked `no_unique_address` are not considered to be prior members.
   CharUnits PreferredAlign = FieldAlign;
-  if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+  if (DefaultsToAIXPowerAlignment && !isAlignRequired() &&
   (FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
 auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
   if (BTy->getKind() == BuiltinType::Double ||
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1858,7 +1858,7 @@
 Width = llvm::alignTo(Width, Align);
   return TypeInfoChars(CharUnits::fromQuantity(Width),

[PATCH] D108858: TypeInfo records more information about align requirement

2021-08-27 Thread Steven Wan via Phabricator via cfe-commits
stevewan created this revision.
stevewan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Extend the information preserved in `TypeInfo` by replacing the
`AlignIsRequired` bool flag with a three-valued enum, the enum also
indicates where the alignment attribute come from, which could be
helpful in determining whether the attribute should overrule.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108858

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1839,7 +1839,7 @@
 
 // Pass over-aligned aggregates on Windows indirectly. This behavior was
 // added in MSVC 2015.
-if (IsWin32StructABI && TI.AlignIsRequired && TI.Align > 32)
+if (IsWin32StructABI && TI.isAlignRequired() && TI.Align > 32)
   return getIndirectResult(Ty, /*ByVal=*/false, State);
 
 // Expand small (<= 128-bit) record types when we know that the stack layout
@@ -6992,7 +6992,7 @@
 TyAlignForABI = CharUnits::fromQuantity(4);
   }
 
-  TypeInfoChars TyInfo(TySize, TyAlignForABI, false);
+  TypeInfoChars TyInfo(TySize, TyAlignForABI, AlignRequirementKind::None);
   return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, TyInfo,
   SlotSize, /*AllowHigherAlign*/ true);
 }
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -847,7 +847,7 @@
 // arguments was not supported and resulted in a compiler error. In 19.14
 // and later versions, such arguments are now passed indirectly.
 TypeInfo Info = getContext().getTypeInfo(RD->getTypeForDecl());
-if (Info.AlignIsRequired && Info.Align > 4)
+if (Info.isAlignRequired() && Info.Align > 4)
   return RAA_Indirect;
 
 // If C++ prohibits us from making a copy, construct the arguments directly
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -52,7 +52,7 @@
 
 static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext ) {
   auto TI = Ctx.getTypeInfo(Ty);
-  return TI.AlignIsRequired ? TI.Align : 0;
+  return TI.isAlignRequired() ? TI.Align : 0;
 }
 
 static uint32_t getTypeAlignIfRequired(QualType Ty, const ASTContext ) {
@@ -4676,7 +4676,7 @@
 llvm::DIType *fieldType;
 if (capture->isByRef()) {
   TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
-  auto Align = PtrInfo.AlignIsRequired ? PtrInfo.Align : 0;
+  auto Align = PtrInfo.isAlignRequired() ? PtrInfo.Align : 0;
   // FIXME: This recomputes the layout of the BlockByRefWrapper.
   uint64_t xoffset;
   fieldType =
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1538,7 +1538,7 @@
   TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
   uint64_t StorageUnitSize = FieldInfo.Width;
   unsigned FieldAlign = FieldInfo.Align;
-  bool AlignIsRequired = FieldInfo.AlignIsRequired;
+  bool AlignIsRequired = FieldInfo.isAlignRequired();
 
   // UnfilledBitsInLastUnit is the difference between the end of the
   // last allocated bitfield (i.e. the first bit offset available for
@@ -1889,7 +1889,7 @@
 
   bool FieldPacked = Packed || D->hasAttr();
 
-  bool AlignIsRequired = false;
+  AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;
   CharUnits FieldAlign;
   // The amount of this class's dsize occupied by the field.
@@ -1904,7 +1904,7 @@
 // aligned appropriately for their element type.
 EffectiveFieldSize = FieldSize =
 IsIncompleteArrayType ? CharUnits::Zero() : TI.Width;
-AlignIsRequired = TI.AlignIsRequired;
+AlignRequirement = TI.AlignRequirement;
   };
 
   if (D->getType()->isIncompleteArrayType()) {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1858,7 +1858,7 @@
 Width = llvm::alignTo(Width, Align);
   return TypeInfoChars(CharUnits::fromQuantity(Width),
CharUnits::fromQuantity(Align),
-   EltInfo.AlignIsRequired);
+   EltInfo.AlignRequirement);
 }
 
 TypeInfoChars ASTContext::getTypeInfoInChars(const Type *T) const {
@@ -1866,8 +1866,7 @@
 return getConstantArrayInfoInChars(*this, CAT);
   TypeInfo