diff options
author | Arthur Eubanks <aeubanks@google.com> | 2021-12-03 11:01:25 -0800 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2022-01-04 21:59:16 -0800 |
commit | 67b5bc26bde81a60688ae5c049a001ffbc6dd614 (patch) | |
tree | 3e988d6f229d132793240d1ad07f32f4cd32f779 | |
parent | 9468a0f953858c696fc5a454420ef4c96e35637c (diff) | |
download | llvm-67b5bc26bde81a60688ae5c049a001ffbc6dd614.zip llvm-67b5bc26bde81a60688ae5c049a001ffbc6dd614.tar.gz llvm-67b5bc26bde81a60688ae5c049a001ffbc6dd614.tar.bz2 |
[DebugInfo] Check DIEnumerator bit width when comparing for equality
As mentioned in D106585, this causes non-determinism, which can also be
shown by this test case being flaky without this patch.
We were using the APSInt's bit width for hashing, but not for checking
for equality. APInt::isSameValue() does not check bit width.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D115054
(cherry picked from commit 93a20ecee4b6c6618e0a8e1112f4f929d55ffcbb)
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.h | 5 | ||||
-rw-r--r-- | llvm/unittests/IR/DebugInfoTest.cpp | 20 |
2 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index 2ae23fd..655319e 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -391,8 +391,9 @@ template <> struct MDNodeKeyImpl<DIEnumerator> { IsUnsigned(N->isUnsigned()) {} bool isKeyOf(const DIEnumerator *RHS) const { - return APInt::isSameValue(Value, RHS->getValue()) && - IsUnsigned == RHS->isUnsigned() && Name == RHS->getRawName(); + return Value.getBitWidth() == RHS->getValue().getBitWidth() && + Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() && + Name == RHS->getRawName(); } unsigned getHashValue() const { return hash_combine(Value, Name); } diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp index 060a5c2..17b6e54 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -7,8 +7,9 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/DebugInfo.h" -#include "llvm/IR/DIBuilder.h" +#include "llvm/ADT/APSInt.h" #include "llvm/AsmParser/Parser.h" +#include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" @@ -244,4 +245,21 @@ TEST(DIBuilder, CreateSetType) { EXPECT_TRUE(isa_and_nonnull<DIDerivedType>(SetType)); } +TEST(DIBuilder, DIEnumerator) { + LLVMContext Ctx; + std::unique_ptr<Module> M(new Module("MyModule", Ctx)); + DIBuilder DIB(*M); + APSInt I1(APInt(32, 1)); + APSInt I2(APInt(33, 1)); + + auto *E = DIEnumerator::get(Ctx, I1, I1.isSigned(), "name"); + EXPECT_TRUE(E); + + auto *E1 = DIEnumerator::getIfExists(Ctx, I1, I1.isSigned(), "name"); + EXPECT_TRUE(E1); + + auto *E2 = DIEnumerator::getIfExists(Ctx, I2, I1.isSigned(), "name"); + EXPECT_FALSE(E2); +} + } // end namespace |