[PATCH] D105320: [CodeView] Skip emitting values bigger than supported by APInt.
Matheus Izvekov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 1 16:06:22 PDT 2021
mizvekov created this revision.
Herald added subscribers: pengfei, hiraditya.
mizvekov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This fixes an assert firing when compiling code such as:
struct f {
static __int128 g() { return e; }
static const __int128 e = __int128(1) << 128;
};
void h() { f::g(); }
with `clang -cc1 -triple x86_64-w64-windows-gnu -emit-obj -gcodeview -debug-info-kind=limited t.cc`.
Which would trigger following assert:
Assertion failed: getMinSignedBits() <= 64 && "Too many bits for int64_t", file llvm/include/llvm/ADT/APInt.h, line 1646
To get around this, we just stop emitting the Value attribute when
printing constant symbol records.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105320
Files:
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
@@ -315,6 +315,8 @@
void collectDebugInfoForGlobals();
void emitDebugInfoForGlobals();
void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
+ void emitConstantSymbolRecord(const DIType *DTy, APSInt &Value,
+ const std::string &QualifiedName);
void emitDebugInfoForGlobal(const CVGlobalVariable &CVGV);
void emitStaticConstMemberList();
Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -3157,6 +3157,30 @@
}
}
+void CodeViewDebug::emitConstantSymbolRecord(const DIType *DTy, APSInt &Value,
+ const std::string &QualifiedName) {
+ MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
+ OS.AddComment("Type");
+ OS.emitInt32(getTypeIndex(DTy).getIndex());
+
+ // TODO: Need to support bigger ints like __int128.
+ if (Value.getNumWords() <= 1U) {
+ OS.AddComment("Value");
+
+ // Encoded integers shouldn't need more than 10 bytes.
+ uint8_t Data[10];
+ BinaryStreamWriter Writer(Data, llvm::support::endianness::little);
+ CodeViewRecordIO IO(Writer);
+ cantFail(IO.mapEncodedInteger(Value));
+ StringRef SRef((char *)Data, Writer.getOffset());
+ OS.emitBinaryData(SRef);
+ }
+
+ OS.AddComment("Name");
+ emitNullTerminatedSymbolName(OS, QualifiedName);
+ endSymbolRecord(SConstantEnd);
+}
+
void CodeViewDebug::emitStaticConstMemberList() {
for (const DIDerivedType *DTy : StaticConstMembers) {
const DIScope *Scope = DTy->getScope();
@@ -3172,24 +3196,8 @@
else
llvm_unreachable("cannot emit a constant without a value");
- std::string QualifiedName = getFullyQualifiedName(Scope, DTy->getName());
-
- MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
- OS.AddComment("Type");
- OS.emitInt32(getTypeIndex(DTy->getBaseType()).getIndex());
- OS.AddComment("Value");
-
- // Encoded integers shouldn't need more than 10 bytes.
- uint8_t Data[10];
- BinaryStreamWriter Writer(Data, llvm::support::endianness::little);
- CodeViewRecordIO IO(Writer);
- cantFail(IO.mapEncodedInteger(Value));
- StringRef SRef((char *)Data, Writer.getOffset());
- OS.emitBinaryData(SRef);
-
- OS.AddComment("Name");
- emitNullTerminatedSymbolName(OS, QualifiedName);
- endSymbolRecord(SConstantEnd);
+ emitConstantSymbolRecord(DTy->getBaseType(), Value,
+ getFullyQualifiedName(Scope, DTy->getName()));
}
}
@@ -3253,22 +3261,6 @@
? true
: DebugHandlerBase::isUnsignedDIType(DIGV->getType());
APSInt Value(APInt(/*BitWidth=*/64, DIE->getElement(1)), isUnsigned);
-
- MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
- OS.AddComment("Type");
- OS.emitInt32(getTypeIndex(DIGV->getType()).getIndex());
- OS.AddComment("Value");
-
- // Encoded integers shouldn't need more than 10 bytes.
- uint8_t data[10];
- BinaryStreamWriter Writer(data, llvm::support::endianness::little);
- CodeViewRecordIO IO(Writer);
- cantFail(IO.mapEncodedInteger(Value));
- StringRef SRef((char *)data, Writer.getOffset());
- OS.emitBinaryData(SRef);
-
- OS.AddComment("Name");
- emitNullTerminatedSymbolName(OS, QualifiedName);
- endSymbolRecord(SConstantEnd);
+ emitConstantSymbolRecord(DIGV->getType(), Value, QualifiedName);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105320.356037.patch
Type: text/x-patch
Size: 3780 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210701/6ced29ff/attachment.bin>
More information about the llvm-commits
mailing list