[llvm] bce2ac9 - Revert "[DebugInfo] Refactor code for emitting DWARF expressions for FP constants"
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 24 00:11:44 PST 2020
Author: Pavel Labath
Date: 2020-11-24T09:11:33+01:00
New Revision: bce2ac9f6d3be91fc744f7efe76d52dbe1b683bf
URL: https://github.com/llvm/llvm-project/commit/bce2ac9f6d3be91fc744f7efe76d52dbe1b683bf
DIFF: https://github.com/llvm/llvm-project/commit/bce2ac9f6d3be91fc744f7efe76d52dbe1b683bf.diff
LOG: Revert "[DebugInfo] Refactor code for emitting DWARF expressions for FP constants"
The commit introduced a crash when emitting (debug info for) complex
floats (pr48277).
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
Removed:
llvm/test/DebugInfo/ARM/implicit_value-_Float16.ll
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index eb20c9cfa487..5054ed81fcfc 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2466,11 +2466,24 @@ void DwarfDebug::emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
// TODO TargetIndexLocation is a target-independent. Currently only the WebAssembly-specific
// encoding is supported.
DwarfExpr.addWasmLocation(Loc.Index, static_cast<uint64_t>(Loc.Offset));
- DwarfExpr.addExpression(std::move(ExprCursor));
- return;
+ DwarfExpr.addExpression(std::move(ExprCursor));
+ return;
} else if (Value.isConstantFP()) {
- DwarfExpr.addConstantFP(Value.getConstantFP()->getValueAPF(), AP);
- return;
+ if (AP.getDwarfVersion() >= 4 && !AP.getDwarfDebug()->tuneForSCE()) {
+ DwarfExpr.addConstantFP(Value.getConstantFP()->getValueAPF(), AP);
+ return;
+ } else if (Value.getConstantFP()
+ ->getValueAPF()
+ .bitcastToAPInt()
+ .getBitWidth() <= 64 /*bits*/)
+ DwarfExpr.addUnsignedConstant(
+ Value.getConstantFP()->getValueAPF().bitcastToAPInt());
+ else
+ LLVM_DEBUG(
+ dbgs()
+ << "Skipped DwarfExpression creation for ConstantFP of size"
+ << Value.getConstantFP()->getValueAPF().bitcastToAPInt().getBitWidth()
+ << " bits\n");
}
DwarfExpr.addExpression(std::move(ExprCursor));
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 21f7ad1b7b80..59ad7646ce1c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -200,29 +200,10 @@ void DwarfExpression::addUnsignedConstant(uint64_t Value) {
emitConstu(Value);
}
-void DwarfExpression::addUnsignedConstant(APInt Value, const AsmPrinter &AP) {
+void DwarfExpression::addUnsignedConstant(const APInt &Value) {
assert(isImplicitLocation() || isUnknownLocation());
LocationKind = Implicit;
- if (AP.getDwarfVersion() >= 4 && !AP.getDwarfDebug()->tuneForSCE()) {
- int NumBytes = Value.getBitWidth() / 8;
- emitOp(dwarf::DW_OP_implicit_value);
- emitUnsigned(NumBytes /*Size of the block in bytes*/);
-
- // The loop below is emitting the value starting at least significant
- // byte, so we need to perform a byte-swap to get the byte order correct
- // in case of a big-endian target.
- if (AP.getDataLayout().isBigEndian())
- Value = Value.byteSwap();
-
- for (int i = 0; i < NumBytes; ++i) {
- emitData1(Value.getRawData()[0] & 0xFF);
- Value = Value.lshr(8);
- }
-
- return;
- }
-
unsigned Size = Value.getBitWidth();
const uint64_t *Data = Value.getRawData();
@@ -231,9 +212,9 @@ void DwarfExpression::addUnsignedConstant(APInt Value, const AsmPrinter &AP) {
unsigned Offset = 0;
while (Offset < Size) {
addUnsignedConstant(*Data++);
- addStackValue();
if (Offset == 0 && Size <= 64)
break;
+ addStackValue();
addOpPiece(std::min(Size - Offset, 64u), Offset);
Offset += 64;
}
@@ -243,13 +224,27 @@ void DwarfExpression::addConstantFP(const APFloat &APF, const AsmPrinter &AP) {
assert(isImplicitLocation() || isUnknownLocation());
APInt API = APF.bitcastToAPInt();
int NumBytes = API.getBitWidth() / 8;
- // FIXME: Add support for `long double`.
- if (NumBytes <= 8 /*double*/)
- addUnsignedConstant(API, AP);
- else
- LLVM_DEBUG(
- dbgs() << "Skipped DwarfExpression creation for ConstantFP of size"
- << API.getBitWidth() << " bits\n");
+ if (NumBytes == 4 /*float*/ || NumBytes == 8 /*double*/) {
+ // FIXME: Add support for `long double`.
+ emitOp(dwarf::DW_OP_implicit_value);
+ emitUnsigned(NumBytes /*Size of the block in bytes*/);
+
+ // The loop below is emitting the value starting at least significant byte,
+ // so we need to perform a byte-swap to get the byte order correct in case
+ // of a big-endian target.
+ if (AP.getDataLayout().isBigEndian())
+ API = API.byteSwap();
+
+ for (int i = 0; i < NumBytes; ++i) {
+ emitData1(API.getZExtValue() & 0xFF);
+ API = API.lshr(8);
+ }
+
+ return;
+ }
+ LLVM_DEBUG(
+ dbgs() << "Skipped DW_OP_implicit_value creation for ConstantFP of size: "
+ << API.getBitWidth() << " bits\n");
}
bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
index 796717b525a2..8fca9f5a630b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
@@ -297,7 +297,7 @@ class DwarfExpression {
void addUnsignedConstant(uint64_t Value);
/// Emit an unsigned constant.
- void addUnsignedConstant(APInt Value, const AsmPrinter &AP);
+ void addUnsignedConstant(const APInt &Value);
/// Emit an floating point constant.
void addConstantFP(const APFloat &Value, const AsmPrinter &AP);
diff --git a/llvm/test/DebugInfo/ARM/implicit_value-_Float16.ll b/llvm/test/DebugInfo/ARM/implicit_value-_Float16.ll
deleted file mode 100644
index 60c9ce40c0af..000000000000
--- a/llvm/test/DebugInfo/ARM/implicit_value-_Float16.ll
+++ /dev/null
@@ -1,51 +0,0 @@
-; RUN: llc -debugger-tune=gdb -filetype=obj %s -o - | llvm-dwarfdump - \
-; RUN: | FileCheck %s --check-prefixes=GDB,BOTH
-; RUN: llc -debugger-tune=sce -filetype=obj %s -o - | llvm-dwarfdump - \
-; RUN: | FileCheck %s --check-prefixes=SCE,BOTH
-
-; BOTH: DW_TAG_variable
-; BOTH-NEXT: DW_AT_location
-; GDB-NEXT: {{.*}}: DW_OP_implicit_value 0x2 0xe0 0x51
-; SCE-NEXT: {{.*}}: DW_OP_constu 0x51e0, DW_OP_stack_value
-; GDB-NEXT: {{.*}}: DW_OP_implicit_value 0x2 0x40 0x51
-; SCE-NEXT: {{.*}}: DW_OP_constu 0x5140, DW_OP_stack_value
-; BOTH-NEXT: DW_AT_name ("a")
-
-source_filename = "-"
-target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
-target triple = "armv7-unknown-unknown"
-
-define dso_local arm_aapcscc void @f() local_unnamed_addr !dbg !8 {
-entry:
- call void @llvm.dbg.value(metadata half 0xH51E0, metadata !13, metadata !DIExpression()), !dbg !15
- call arm_aapcscc void bitcast (void (...)* @g to void ()*)(), !dbg !15
- call void @llvm.dbg.value(metadata half 0xH5140, metadata !13, metadata !DIExpression()), !dbg !15
- call arm_aapcscc void bitcast (void (...)* @g to void ()*)(), !dbg !15
- ret void, !dbg !15
-}
-
-declare dso_local arm_aapcscc void @g(...) local_unnamed_addr
-
-declare void @llvm.dbg.value(metadata, metadata, metadata) #2
-
-attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
-
-!llvm.dbg.cu = !{!0}
-!llvm.module.flags = !{!3, !4, !5, !6}
-!llvm.ident = !{!7}
-
-!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug, enums: !2)
-!1 = !DIFile(filename: "-", directory: "/")
-!2 = !{}
-!3 = !{i32 7, !"Dwarf Version", i32 4}
-!4 = !{i32 2, !"Debug Info Version", i32 3}
-!5 = !{i32 1, !"wchar_size", i32 4}
-!6 = !{i32 1, !"min_enum_size", i32 4}
-!7 = !{!"clang version 12.0.0"}
-!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, type: !10, unit: !0)
-!10 = !DISubroutineType(types: !11)
-!11 = !{null}
-!12 = !{!13}
-!13 = !DILocalVariable(name: "a", scope: !8, file: !1, type: !14)
-!14 = !DIBasicType(name: "_Float16", size: 16, encoding: DW_ATE_float)
-!15 = !DILocation(line: 0, scope: !8)
More information about the llvm-commits
mailing list