[DebugInfo] Use per-enumerator signedness for DIEnumerator

Allegedly the DWARF backend ignores this field of DIEnumerator, but we
set it nonetheless in case we decide to use it in the future.
Alternatively, we could remove it, but it is simpler to pass down the
signed bit as it is in the AST for now.

Implemented to address comments on D106585
This commit is contained in:
Reid Kleckner 2021-07-26 16:06:17 -07:00
parent beff86e8ff
commit f9f56488e0
2 changed files with 2 additions and 8 deletions

View File

@ -3084,17 +3084,11 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
// Create elements for each enumerator. Use the signed-ness of the enum type,
// not the signedness of the enumerator. This matches the DWARF produced by
// GCC for C enums with positive enumerators.
SmallVector<llvm::Metadata *, 16> Enumerators;
ED = ED->getDefinition();
bool IsSigned = ED->getIntegerType()->isSignedIntegerType();
for (const auto *Enum : ED->enumerators()) {
llvm::APSInt Value = Enum->getInitVal();
Value.setIsSigned(IsSigned);
Enumerators.push_back(
DBuilder.createEnumerator(Enum->getName(), std::move(Value)));
DBuilder.createEnumerator(Enum->getName(), Enum->getInitVal()));
}
// Return a CompositeType for the enum itself.

View File

@ -12,4 +12,4 @@ void foo (void)
// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
// CHECK: ![[LONG]] = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
// CHECK: ![[ELTS]] = !{![[MAX:[0-9]+]]}
// CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0, isUnsigned: true)
// CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0)