mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-12 20:48:17 +00:00

Introduces memory leak in FunctionTest.GetPointerAlignment that breaks sanitizer buildbots: ``` ================================================================= ==2453==ERROR: LeakSanitizer: detected memory leaks Direct leak of 128 byte(s) in 1 object(s) allocated from: #0 0x610428 in operator new(unsigned long) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:105 #1 0x16936bc in llvm::User::operator new(unsigned long) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/IR/User.cpp:151:19 #2 0x7c3fe9 in Create /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/IR/Function.h:144:12 #3 0x7c3fe9 in (anonymous namespace)::FunctionTest_GetPointerAlignment_Test::TestBody() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/unittests/IR/FunctionTest.cpp:136 #4 0x1a836a0 in HandleExceptionsInMethodIfSupported<testing::Test, void> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc #5 0x1a836a0 in testing::Test::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2474 #6 0x1a85c55 in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11 #7 0x1a870d0 in testing::TestCase::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28 #8 0x1aa5b84 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43 #9 0x1aa4d30 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc #10 0x1aa4d30 in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4257 #11 0x1a6b656 in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46 #12 0x1a6b656 in main /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50 #13 0x7f5af37a22e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) Indirect leak of 40 byte(s) in 1 object(s) allocated from: #0 0x610428 in operator new(unsigned long) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:105 #1 0x151be6b in make_unique<llvm::ValueSymbolTable> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/ADT/STLExtras.h:1349:29 #2 0x151be6b in llvm::Function::Function(llvm::FunctionType*, llvm::GlobalValue::LinkageTypes, unsigned int, llvm::Twine const&, llvm::Module*) /b/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/IR/Function.cpp:241 #3 0x7c4006 in Create /b/sanitizer-x86_64-linux-bootstrap/build/llvm/include/llvm/IR/Function.h:144:16 #4 0x7c4006 in (anonymous namespace)::FunctionTest_GetPointerAlignment_Test::TestBody() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/unittests/IR/FunctionTest.cpp:136 #5 0x1a836a0 in HandleExceptionsInMethodIfSupported<testing::Test, void> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc #6 0x1a836a0 in testing::Test::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2474 #7 0x1a85c55 in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11 #8 0x1a870d0 in testing::TestCase::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28 #9 0x1aa5b84 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43 #10 0x1aa4d30 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc #11 0x1aa4d30 in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/src/gtest.cc:4257 #12 0x1a6b656 in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46 #13 0x1a6b656 in main /b/sanitizer-x86_64-linux-bootstrap/build/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50 #14 0x7f5af37a22e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) SUMMARY: AddressSanitizer: 168 byte(s) leaked in 2 allocation(s). ``` See http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/11358/steps/check-llvm%20asan/logs/stdio for more information. Also introduces use-of-uninitialized-value in ConstantsTest.FoldGlobalVariablePtr: ``` ==7070==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x14e703c in User /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/User.h:79:5 #1 0x14e703c in Constant /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/Constant.h:44 #2 0x14e703c in llvm::GlobalValue::GlobalValue(llvm::Type*, llvm::Value::ValueTy, llvm::Use*, unsigned int, llvm::GlobalValue::LinkageTypes, llvm::Twine const&, unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/GlobalValue.h:78 #3 0x14e5467 in GlobalObject /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/GlobalObject.h:34:9 #4 0x14e5467 in llvm::GlobalVariable::GlobalVariable(llvm::Type*, bool, llvm::GlobalValue::LinkageTypes, llvm::Constant*, llvm::Twine const&, llvm::GlobalValue::ThreadLocalMode, unsigned int, bool) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/Globals.cpp:314 #5 0x6938f1 in llvm::(anonymous namespace)::ConstantsTest_FoldGlobalVariablePtr_Test::TestBody() /b/sanitizer-x86_64-linux-fast/build/llvm/unittests/IR/ConstantsTest.cpp:565:18 #6 0x1a240a1 in HandleExceptionsInMethodIfSupported<testing::Test, void> /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc #7 0x1a240a1 in testing::Test::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:2474 #8 0x1a26d26 in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:2656:11 #9 0x1a2815f in testing::TestCase::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:2774:28 #10 0x1a43de8 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:4649:43 #11 0x1a42c47 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc #12 0x1a42c47 in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/src/gtest.cc:4257 #13 0x1a0dfba in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46 #14 0x1a0dfba in main /b/sanitizer-x86_64-linux-fast/build/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50 #15 0x7f2081c412e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) #16 0x4dff49 in _start (/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/unittests/IR/IRTests+0x4dff49) SUMMARY: MemorySanitizer: use-of-uninitialized-value /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/IR/User.h:79:5 in User ``` See http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/30222/steps/check-llvm%20msan/logs/stdio for more information. llvm-svn: 355616
133 lines
4.0 KiB
C++
133 lines
4.0 KiB
C++
//===- FunctionTest.cpp - Function unit tests -----------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "gtest/gtest.h"
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
TEST(FunctionTest, hasLazyArguments) {
|
|
LLVMContext C;
|
|
|
|
Type *ArgTypes[] = {Type::getInt8Ty(C), Type::getInt32Ty(C)};
|
|
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false);
|
|
|
|
// Functions start out with lazy arguments.
|
|
std::unique_ptr<Function> F(
|
|
Function::Create(FTy, GlobalValue::ExternalLinkage, "F"));
|
|
EXPECT_TRUE(F->hasLazyArguments());
|
|
|
|
// Checking for empty or size shouldn't force arguments to be instantiated.
|
|
EXPECT_FALSE(F->arg_empty());
|
|
EXPECT_TRUE(F->hasLazyArguments());
|
|
EXPECT_EQ(2u, F->arg_size());
|
|
EXPECT_TRUE(F->hasLazyArguments());
|
|
|
|
// The argument list should be populated at first access.
|
|
(void)F->arg_begin();
|
|
EXPECT_FALSE(F->hasLazyArguments());
|
|
}
|
|
|
|
TEST(FunctionTest, stealArgumentListFrom) {
|
|
LLVMContext C;
|
|
|
|
Type *ArgTypes[] = {Type::getInt8Ty(C), Type::getInt32Ty(C)};
|
|
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false);
|
|
std::unique_ptr<Function> F1(
|
|
Function::Create(FTy, GlobalValue::ExternalLinkage, "F1"));
|
|
std::unique_ptr<Function> F2(
|
|
Function::Create(FTy, GlobalValue::ExternalLinkage, "F1"));
|
|
EXPECT_TRUE(F1->hasLazyArguments());
|
|
EXPECT_TRUE(F2->hasLazyArguments());
|
|
|
|
// Steal arguments before they've been accessed. Nothing should change; both
|
|
// functions should still have lazy arguments.
|
|
//
|
|
// steal(empty); drop (empty)
|
|
F1->stealArgumentListFrom(*F2);
|
|
EXPECT_TRUE(F1->hasLazyArguments());
|
|
EXPECT_TRUE(F2->hasLazyArguments());
|
|
|
|
// Save arguments from F1 for later assertions. F1 won't have lazy arguments
|
|
// anymore.
|
|
SmallVector<Argument *, 4> Args;
|
|
for (Argument &A : F1->args())
|
|
Args.push_back(&A);
|
|
EXPECT_EQ(2u, Args.size());
|
|
EXPECT_FALSE(F1->hasLazyArguments());
|
|
|
|
// Steal arguments from F1 to F2. F1's arguments should be lazy again.
|
|
//
|
|
// steal(real); drop (empty)
|
|
F2->stealArgumentListFrom(*F1);
|
|
EXPECT_TRUE(F1->hasLazyArguments());
|
|
EXPECT_FALSE(F2->hasLazyArguments());
|
|
unsigned I = 0;
|
|
for (Argument &A : F2->args()) {
|
|
EXPECT_EQ(Args[I], &A);
|
|
I++;
|
|
}
|
|
EXPECT_EQ(2u, I);
|
|
|
|
// Check that arguments in F1 don't have pointer equality with the saved ones.
|
|
// This also instantiates F1's arguments.
|
|
I = 0;
|
|
for (Argument &A : F1->args()) {
|
|
EXPECT_NE(Args[I], &A);
|
|
I++;
|
|
}
|
|
EXPECT_EQ(2u, I);
|
|
EXPECT_FALSE(F1->hasLazyArguments());
|
|
EXPECT_FALSE(F2->hasLazyArguments());
|
|
|
|
// Steal back from F2. F2's arguments should be lazy again.
|
|
//
|
|
// steal(real); drop (real)
|
|
F1->stealArgumentListFrom(*F2);
|
|
EXPECT_FALSE(F1->hasLazyArguments());
|
|
EXPECT_TRUE(F2->hasLazyArguments());
|
|
I = 0;
|
|
for (Argument &A : F1->args()) {
|
|
EXPECT_EQ(Args[I], &A);
|
|
I++;
|
|
}
|
|
EXPECT_EQ(2u, I);
|
|
|
|
// Steal from F2 a second time. Now both functions should have lazy
|
|
// arguments.
|
|
//
|
|
// steal(empty); drop (real)
|
|
F1->stealArgumentListFrom(*F2);
|
|
EXPECT_TRUE(F1->hasLazyArguments());
|
|
EXPECT_TRUE(F2->hasLazyArguments());
|
|
}
|
|
|
|
// Test setting and removing section information
|
|
TEST(FunctionTest, setSection) {
|
|
LLVMContext C;
|
|
Module M("test", C);
|
|
|
|
llvm::Function *F =
|
|
Function::Create(llvm::FunctionType::get(llvm::Type::getVoidTy(C), false),
|
|
llvm::GlobalValue::ExternalLinkage, "F", &M);
|
|
|
|
F->setSection(".text.test");
|
|
EXPECT_TRUE(F->getSection() == ".text.test");
|
|
EXPECT_TRUE(F->hasSection());
|
|
F->setSection("");
|
|
EXPECT_FALSE(F->hasSection());
|
|
F->setSection(".text.test");
|
|
F->setSection(".text.test2");
|
|
EXPECT_TRUE(F->getSection() == ".text.test2");
|
|
EXPECT_TRUE(F->hasSection());
|
|
}
|
|
|
|
} // end namespace
|