From da0c65fa1b144d698fb7dabd13d058d0121df522 Mon Sep 17 00:00:00 2001 From: arrowten Date: Mon, 28 Jul 2025 15:39:32 +0530 Subject: [PATCH] Fix: Changed parameter to const reference instead of pass-by-value --- llvm/include/llvm/IR/Metadata.h | 2 +- llvm/unittests/IR/MetadataTest.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index af252aa24567a..9cd8533069c21 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -237,7 +237,7 @@ class DebugValueUser { /// `resetDebugValue(Idx, NewDebugValue)` should be used instead. LLVM_ABI void handleChangedValue(void *Old, Metadata *NewDebugValue); DebugValueUser() = default; - explicit DebugValueUser(std::array DebugValues) + explicit DebugValueUser(const std::array &DebugValues) : DebugValues(DebugValues) { trackDebugValues(); } diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp index ba8367f4a396e..0e8e0831ac9d6 100644 --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/unittests/IR/MetadataTest.cpp @@ -5497,4 +5497,29 @@ TEST_F(MDTupleAllocationDeathTest, ResizeRejected) { } #endif +typedef MetadataTest DebugValueUserTest; + +namespace { +struct DebugValueUserTestHelper: public llvm::DebugValueUser { + using llvm::DebugValueUser::DebugValueUser; + using llvm::DebugValueUser::getDebugValues; +}; +} + +TEST_F(DebugValueUserTest, GetDebugValues) { + auto *V = getConstantAsMetadata(); + auto *V2 = getConstantAsMetadata(); + auto *V3 = getConstantAsMetadata(); + std::array Debugs = {V, V2, V3}; + DebugValueUserTestHelper User(Debugs); + ArrayRef Result = User.getDebugValues(); + + // Verify the size of the returned array is correct, + // and each element is correctly stored and returned. + EXPECT_EQ(Result.size(), 3u); + EXPECT_EQ(Result[0], V); + EXPECT_EQ(Result[1], V2); + EXPECT_EQ(Result[2], V3); +} + } // end namespace