[PATCH] D106585: Fix clang debug info irgen of i128 enums
Reid Kleckner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 22 12:46:56 PDT 2021
rnk created this revision.
rnk added reviewers: mizvekov, dblaikie, MaskRay.
Herald added subscribers: dexonsmith, hiraditya.
rnk requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: llvm-commits.
DIEnumerator stores an APInt as of April 2020, so now we don't need to
truncate the enumerator value to 64 bits. Fixes assertions during IRGen.
Split from D105320 <https://reviews.llvm.org/D105320>, thanks to Matheus Izvekov for the test case and
report.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106585
Files:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-enum-i128.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp
Index: llvm/lib/IR/DIBuilder.cpp
===================================================================
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -250,6 +250,11 @@
Name);
}
+DIEnumerator *DIBuilder::createEnumerator(StringRef Name, APSInt Value) {
+ assert(!Name.empty() && "Unable to create enumerator without name");
+ return DIEnumerator::get(VMContext, APInt(Value), Value.isUnsigned(), Name);
+}
+
DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
assert(!Name.empty() && "Unable to create type without name");
return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
Index: llvm/include/llvm/IR/DIBuilder.h
===================================================================
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -181,7 +181,9 @@
DIFile *File);
/// Create a single enumerator value.
- DIEnumerator *createEnumerator(StringRef Name, int64_t Val, bool IsUnsigned = false);
+ DIEnumerator *createEnumerator(StringRef Name, APSInt Value);
+ DIEnumerator *createEnumerator(StringRef Name, int64_t Val,
+ bool IsUnsigned = false);
/// Create a DWARF unspecified type.
DIBasicType *createUnspecifiedType(StringRef Name);
Index: clang/test/CodeGenCXX/debug-info-enum-i128.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-enum-i128.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-linux-gnu -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+
+enum class uns : __uint128_t { unsval = __uint128_t(1) << 64 };
+uns t1() { return uns::unsval; }
+
+enum class sig : __int128 { sigval = -(__int128(1) << 64) };
+sig t2() { return sig::sigval; }
+
+
+// CHECK-LABEL: !DICompositeType(tag: DW_TAG_enumeration_type, name: "uns", {{.*}})
+// CHECK: !DIEnumerator(name: "unsval", value: 18446744073709551616, isUnsigned: true)
+
+// CHECK-LABEL: !DICompositeType(tag: DW_TAG_enumeration_type, name: "sig", {{.*}})
+// CHECK: !DIEnumerator(name: "sigval", value: -18446744073709551616)
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3113,10 +3113,9 @@
ED = ED->getDefinition();
bool IsSigned = ED->getIntegerType()->isSignedIntegerType();
for (const auto *Enum : ED->enumerators()) {
- const auto &InitVal = Enum->getInitVal();
- auto Value = IsSigned ? InitVal.getSExtValue() : InitVal.getZExtValue();
- Enumerators.push_back(
- DBuilder.createEnumerator(Enum->getName(), Value, !IsSigned));
+ llvm::APSInt Value = Enum->getInitVal();
+ Value.setIsSigned(IsSigned);
+ Enumerators.push_back(DBuilder.createEnumerator(Enum->getName(), Value));
}
// Return a CompositeType for the enum itself.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106585.360933.patch
Type: text/x-patch
Size: 3098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210722/6ead8c41/attachment-0001.bin>
More information about the cfe-commits
mailing list