-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Fix AsmWriter to account for dynamic bit offsets #146704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-llvm-ir Author: Tom Tromey (tromey) ChangesPR #141106 changed the debug metadata to allow dynamic bit offsets and sizes. In that patch, I forgot to update AsmWriter to handle this case. This patch corrects the oversight. Full diff: https://github.com/llvm/llvm-project/pull/146704.diff 2 Files Affected:
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index af268b4fc6941..029246e375aa4 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2226,13 +2226,14 @@ static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N,
}
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N,
- AsmWriterContext &) {
+ AsmWriterContext &WriterCtx) {
Out << "!DIBasicType(";
- MDFieldPrinter Printer(Out);
+ MDFieldPrinter Printer(Out, WriterCtx);
if (N->getTag() != dwarf::DW_TAG_base_type)
Printer.printTag(N);
Printer.printString("name", N->getName());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDwarfEnum("encoding", N->getEncoding(),
dwarf::AttributeEncodingString);
@@ -2242,13 +2243,14 @@ static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N,
}
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N,
- AsmWriterContext &) {
+ AsmWriterContext &WriterCtx) {
Out << "!DIFixedPointType(";
- MDFieldPrinter Printer(Out);
+ MDFieldPrinter Printer(Out, WriterCtx);
if (N->getTag() != dwarf::DW_TAG_base_type)
Printer.printTag(N);
Printer.printString("name", N->getName());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDwarfEnum("encoding", N->getEncoding(),
dwarf::AttributeEncodingString);
@@ -2275,7 +2277,8 @@ static void writeDIStringType(raw_ostream &Out, const DIStringType *N,
Printer.printMetadata("stringLengthExpression", N->getRawStringLengthExp());
Printer.printMetadata("stringLocationExpression",
N->getRawStringLocationExp());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDwarfEnum("encoding", N->getEncoding(),
dwarf::AttributeEncodingString);
@@ -2293,9 +2296,11 @@ static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N,
Printer.printInt("line", N->getLine());
Printer.printMetadata("baseType", N->getRawBaseType(),
/* ShouldSkipNull */ false);
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
- Printer.printInt("offset", N->getOffsetInBits());
+ if (N->getRawOffsetInBits())
+ Printer.printMetadata("offset", N->getRawOffsetInBits());
Printer.printDIFlags("flags", N->getFlags());
Printer.printMetadata("extraData", N->getRawExtraData());
if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
@@ -2323,7 +2328,8 @@ static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N,
Printer.printMetadata("scope", N->getRawScope());
Printer.printMetadata("file", N->getRawFile());
Printer.printInt("line", N->getLine());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDIFlags("flags", N->getFlags());
Printer.printMetadata("baseType", N->getRawBaseType(),
@@ -2345,9 +2351,11 @@ static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N,
Printer.printMetadata("file", N->getRawFile());
Printer.printInt("line", N->getLine());
Printer.printMetadata("baseType", N->getRawBaseType());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
- Printer.printInt("offset", N->getOffsetInBits());
+ if (N->getRawOffsetInBits())
+ Printer.printMetadata("offset", N->getRawOffsetInBits());
Printer.printInt("num_extra_inhabitants", N->getNumExtraInhabitants());
Printer.printDIFlags("flags", N->getFlags());
Printer.printMetadata("elements", N->getRawElements());
diff --git a/llvm/test/DebugInfo/X86/dynamic-bitfield.ll b/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
index eda4ff0f8f6d1..320560172c28a 100644
--- a/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
+++ b/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
@@ -1,4 +1,4 @@
-; RUN: llc -mtriple=x86_64 -O0 -filetype=obj -o - %s | llvm-dwarfdump -v -debug-info - | FileCheck %s
+; RUN: llvm-as < %s | llvm-dis | llc -mtriple=x86_64 -O0 -filetype=obj -o - | llvm-dwarfdump -v -debug-info - | FileCheck %s
; A basic test of using a DIExpression for DW_AT_data_bit_offset and
; DW_AT_bit_size.
|
|
@llvm/pr-subscribers-debuginfo Author: Tom Tromey (tromey) ChangesPR #141106 changed the debug metadata to allow dynamic bit offsets and sizes. In that patch, I forgot to update AsmWriter to handle this case. This patch corrects the oversight. Full diff: https://github.com/llvm/llvm-project/pull/146704.diff 2 Files Affected:
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index af268b4fc6941..029246e375aa4 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2226,13 +2226,14 @@ static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N,
}
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N,
- AsmWriterContext &) {
+ AsmWriterContext &WriterCtx) {
Out << "!DIBasicType(";
- MDFieldPrinter Printer(Out);
+ MDFieldPrinter Printer(Out, WriterCtx);
if (N->getTag() != dwarf::DW_TAG_base_type)
Printer.printTag(N);
Printer.printString("name", N->getName());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDwarfEnum("encoding", N->getEncoding(),
dwarf::AttributeEncodingString);
@@ -2242,13 +2243,14 @@ static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N,
}
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N,
- AsmWriterContext &) {
+ AsmWriterContext &WriterCtx) {
Out << "!DIFixedPointType(";
- MDFieldPrinter Printer(Out);
+ MDFieldPrinter Printer(Out, WriterCtx);
if (N->getTag() != dwarf::DW_TAG_base_type)
Printer.printTag(N);
Printer.printString("name", N->getName());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDwarfEnum("encoding", N->getEncoding(),
dwarf::AttributeEncodingString);
@@ -2275,7 +2277,8 @@ static void writeDIStringType(raw_ostream &Out, const DIStringType *N,
Printer.printMetadata("stringLengthExpression", N->getRawStringLengthExp());
Printer.printMetadata("stringLocationExpression",
N->getRawStringLocationExp());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDwarfEnum("encoding", N->getEncoding(),
dwarf::AttributeEncodingString);
@@ -2293,9 +2296,11 @@ static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N,
Printer.printInt("line", N->getLine());
Printer.printMetadata("baseType", N->getRawBaseType(),
/* ShouldSkipNull */ false);
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
- Printer.printInt("offset", N->getOffsetInBits());
+ if (N->getRawOffsetInBits())
+ Printer.printMetadata("offset", N->getRawOffsetInBits());
Printer.printDIFlags("flags", N->getFlags());
Printer.printMetadata("extraData", N->getRawExtraData());
if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
@@ -2323,7 +2328,8 @@ static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N,
Printer.printMetadata("scope", N->getRawScope());
Printer.printMetadata("file", N->getRawFile());
Printer.printInt("line", N->getLine());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
Printer.printDIFlags("flags", N->getFlags());
Printer.printMetadata("baseType", N->getRawBaseType(),
@@ -2345,9 +2351,11 @@ static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N,
Printer.printMetadata("file", N->getRawFile());
Printer.printInt("line", N->getLine());
Printer.printMetadata("baseType", N->getRawBaseType());
- Printer.printInt("size", N->getSizeInBits());
+ if (N->getRawSizeInBits())
+ Printer.printMetadata("size", N->getRawSizeInBits());
Printer.printInt("align", N->getAlignInBits());
- Printer.printInt("offset", N->getOffsetInBits());
+ if (N->getRawOffsetInBits())
+ Printer.printMetadata("offset", N->getRawOffsetInBits());
Printer.printInt("num_extra_inhabitants", N->getNumExtraInhabitants());
Printer.printDIFlags("flags", N->getFlags());
Printer.printMetadata("elements", N->getRawElements());
diff --git a/llvm/test/DebugInfo/X86/dynamic-bitfield.ll b/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
index eda4ff0f8f6d1..320560172c28a 100644
--- a/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
+++ b/llvm/test/DebugInfo/X86/dynamic-bitfield.ll
@@ -1,4 +1,4 @@
-; RUN: llc -mtriple=x86_64 -O0 -filetype=obj -o - %s | llvm-dwarfdump -v -debug-info - | FileCheck %s
+; RUN: llvm-as < %s | llvm-dis | llc -mtriple=x86_64 -O0 -filetype=obj -o - | llvm-dwarfdump -v -debug-info - | FileCheck %s
; A basic test of using a DIExpression for DW_AT_data_bit_offset and
; DW_AT_bit_size.
|
|
I clearly didn't test this enough and I wonder if some other approach here is needed, because: ... maybe not all of those need to be changed, but still. |
|
I think I will replicate the approach taken for |
PR llvm#141106 changed the debug metadata to allow dynamic bit offsets and sizes. In that patch, I forgot to update AsmWriter to handle this case. This patch corrects the oversight.
d40e3ef to
16f9ec0
Compare
|
Thank you for the review & approval. I don't have write access, so could you please merge this for me? |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/8884 Here is the relevant piece of the build log for the reference |
PR #141106 changed the debug metadata to allow dynamic bit offsets and sizes. In that patch, I forgot to update AsmWriter to handle this case.
This patch corrects the oversight.