Skip to content

Commit 67b5bc2

Browse files
aeubankststellar
authored andcommitted
[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 93a20ec)
1 parent 9468a0f commit 67b5bc2

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

llvm/lib/IR/LLVMContextImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,9 @@ template <> struct MDNodeKeyImpl<DIEnumerator> {
391391
IsUnsigned(N->isUnsigned()) {}
392392

393393
bool isKeyOf(const DIEnumerator *RHS) const {
394-
return APInt::isSameValue(Value, RHS->getValue()) &&
395-
IsUnsigned == RHS->isUnsigned() && Name == RHS->getRawName();
394+
return Value.getBitWidth() == RHS->getValue().getBitWidth() &&
395+
Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() &&
396+
Name == RHS->getRawName();
396397
}
397398

398399
unsigned getHashValue() const { return hash_combine(Value, Name); }

llvm/unittests/IR/DebugInfoTest.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/IR/DebugInfo.h"
10-
#include "llvm/IR/DIBuilder.h"
10+
#include "llvm/ADT/APSInt.h"
1111
#include "llvm/AsmParser/Parser.h"
12+
#include "llvm/IR/DIBuilder.h"
1213
#include "llvm/IR/DebugInfoMetadata.h"
1314
#include "llvm/IR/IntrinsicInst.h"
1415
#include "llvm/IR/LLVMContext.h"
@@ -244,4 +245,21 @@ TEST(DIBuilder, CreateSetType) {
244245
EXPECT_TRUE(isa_and_nonnull<DIDerivedType>(SetType));
245246
}
246247

248+
TEST(DIBuilder, DIEnumerator) {
249+
LLVMContext Ctx;
250+
std::unique_ptr<Module> M(new Module("MyModule", Ctx));
251+
DIBuilder DIB(*M);
252+
APSInt I1(APInt(32, 1));
253+
APSInt I2(APInt(33, 1));
254+
255+
auto *E = DIEnumerator::get(Ctx, I1, I1.isSigned(), "name");
256+
EXPECT_TRUE(E);
257+
258+
auto *E1 = DIEnumerator::getIfExists(Ctx, I1, I1.isSigned(), "name");
259+
EXPECT_TRUE(E1);
260+
261+
auto *E2 = DIEnumerator::getIfExists(Ctx, I2, I1.isSigned(), "name");
262+
EXPECT_FALSE(E2);
263+
}
264+
247265
} // end namespace

0 commit comments

Comments
 (0)