#include "llvm/IR/Metadata.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
#include <optional>
usingnamespacellvm;
namespace {
TEST(ContextAndReplaceableUsesTest, FromContext) { … }
TEST(ContextAndReplaceableUsesTest, FromReplaceableUses) { … }
TEST(ContextAndReplaceableUsesTest, makeReplaceable) { … }
TEST(ContextAndReplaceableUsesTest, takeReplaceableUses) { … }
class MetadataTest : public testing::Test { … };
MDStringTest;
TEST_F(MDStringTest, CreateDifferent) { … }
TEST_F(MDStringTest, CreateSame) { … }
TEST_F(MDStringTest, PrintingSimple) { … }
TEST_F(MDStringTest, PrintingComplex) { … }
MDNodeTest;
TEST_F(MDNodeTest, Simple) { … }
TEST_F(MDNodeTest, Delete) { … }
TEST_F(MDNodeTest, SelfReference) { … }
TEST_F(MDNodeTest, Print) { … }
#define EXPECT_PRINTER_EQ …
TEST_F(MDNodeTest, PrintTemporary) { … }
TEST_F(MDNodeTest, PrintFromModule) { … }
TEST_F(MDNodeTest, PrintFromFunction) { … }
TEST_F(MDNodeTest, PrintFromMetadataAsValue) { … }
TEST_F(MDNodeTest, PrintWithDroppedCallOperand) { … }
TEST_F(MDNodeTest, PrintTree) { … }
#undef EXPECT_PRINTER_EQ
TEST_F(MDNodeTest, NullOperand) { … }
TEST_F(MDNodeTest, DistinctOnUniquingCollision) { … }
TEST_F(MDNodeTest, UniquedOnDeletedOperand) { … }
TEST_F(MDNodeTest, DistinctOnDeletedValueOperand) { … }
TEST_F(MDNodeTest, getDistinct) { … }
TEST_F(MDNodeTest, isUniqued) { … }
TEST_F(MDNodeTest, isDistinct) { … }
TEST_F(MDNodeTest, isTemporary) { … }
TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) { … }
TEST_F(MDNodeTest, handleChangedOperandRecursion) { … }
TEST_F(MDNodeTest, replaceResolvedOperand) { … }
TEST_F(MDNodeTest, replaceWithUniqued) { … }
TEST_F(MDNodeTest, replaceWithUniquedResolvingOperand) { … }
TEST_F(MDNodeTest, replaceWithUniquedDeletedOperand) { … }
TEST_F(MDNodeTest, replaceWithUniquedChangedOperand) { … }
TEST_F(MDNodeTest, replaceWithDistinct) { … }
TEST_F(MDNodeTest, replaceWithPermanent) { … }
TEST_F(MDNodeTest, deleteTemporaryWithTrackingRef) { … }
DILocationTest;
TEST_F(DILocationTest, Merge) { … }
TEST_F(DILocationTest, getDistinct) { … }
TEST_F(DILocationTest, getTemporary) { … }
TEST_F(DILocationTest, cloneTemporary) { … }
TEST_F(DILocationTest, discriminatorEncoding) { … }
TEST_F(DILocationTest, discriminatorEncodingNegativeTests) { … }
TEST_F(DILocationTest, discriminatorSpecialCases) { … }
GenericDINodeTest;
TEST_F(GenericDINodeTest, get) { … }
TEST_F(GenericDINodeTest, getEmptyHeader) { … }
DISubrangeTest;
TEST_F(DISubrangeTest, get) { … }
TEST_F(DISubrangeTest, getEmptyArray) { … }
TEST_F(DISubrangeTest, getVariableCount) { … }
TEST_F(DISubrangeTest, fortranAllocatableInt) { … }
TEST_F(DISubrangeTest, fortranAllocatableVar) { … }
TEST_F(DISubrangeTest, fortranAllocatableExpr) { … }
DIGenericSubrangeTest;
TEST_F(DIGenericSubrangeTest, fortranAssumedRankInt) { … }
TEST_F(DIGenericSubrangeTest, fortranAssumedRankVar) { … }
TEST_F(DIGenericSubrangeTest, useDIBuilder) { … }
DIEnumeratorTest;
TEST_F(DIEnumeratorTest, get) { … }
TEST_F(DIEnumeratorTest, getWithLargeValues) { … }
DIBasicTypeTest;
TEST_F(DIBasicTypeTest, get) { … }
TEST_F(DIBasicTypeTest, getWithLargeValues) { … }
TEST_F(DIBasicTypeTest, getUnspecified) { … }
DITypeTest;
TEST_F(DITypeTest, clone) { … }
TEST_F(DITypeTest, cloneWithFlags) { … }
DIDerivedTypeTest;
TEST_F(DIDerivedTypeTest, get) { … }
TEST_F(DIDerivedTypeTest, getWithLargeValues) { … }
DICompositeTypeTest;
TEST_F(DICompositeTypeTest, get) { … }
TEST_F(DICompositeTypeTest, getWithLargeValues) { … }
TEST_F(DICompositeTypeTest, replaceOperands) { … }
TEST_F(DICompositeTypeTest, variant_part) { … }
TEST_F(DICompositeTypeTest, dynamicArray) { … }
DISubroutineTypeTest;
TEST_F(DISubroutineTypeTest, get) { … }
DIFileTest;
TEST_F(DIFileTest, get) { … }
TEST_F(DIFileTest, EmptySource) { … }
TEST_F(DIFileTest, ScopeGetFile) { … }
DICompileUnitTest;
TEST_F(DICompileUnitTest, get) { … }
TEST_F(DICompileUnitTest, replaceArrays) { … }
DISubprogramTest;
TEST_F(DISubprogramTest, get) { … }
DILexicalBlockTest;
TEST_F(DILexicalBlockTest, get) { … }
TEST_F(DILexicalBlockTest, Overflow) { … }
DILexicalBlockFileTest;
TEST_F(DILexicalBlockFileTest, get) { … }
DINamespaceTest;
TEST_F(DINamespaceTest, get) { … }
DIModuleTest;
TEST_F(DIModuleTest, get) { … }
DITemplateTypeParameterTest;
TEST_F(DITemplateTypeParameterTest, get) { … }
DITemplateValueParameterTest;
TEST_F(DITemplateValueParameterTest, get) { … }
DIGlobalVariableTest;
TEST_F(DIGlobalVariableTest, get) { … }
DIGlobalVariableExpressionTest;
TEST_F(DIGlobalVariableExpressionTest, get) { … }
DILocalVariableTest;
TEST_F(DILocalVariableTest, get) { … }
TEST_F(DILocalVariableTest, getArg256) { … }
DIExpressionTest;
TEST_F(DIExpressionTest, get) { … }
TEST_F(DIExpressionTest, Fold) { … }
TEST_F(DIExpressionTest, Append) { … }
TEST_F(DIExpressionTest, isValid) { … }
TEST_F(DIExpressionTest, createFragmentExpression) { … }
TEST_F(DIExpressionTest, extractLeadingOffset) { … }
TEST_F(DIExpressionTest, convertToUndefExpression) { … }
TEST_F(DIExpressionTest, convertToVariadicExpression) { … }
TEST_F(DIExpressionTest, convertToNonVariadicExpression) { … }
TEST_F(DIExpressionTest, replaceArg) { … }
TEST_F(DIExpressionTest, isEqualExpression) { … }
TEST_F(DIExpressionTest, foldConstant) { … }
TEST_F(DIExpressionTest, appendToStackAssert) { … }
DIObjCPropertyTest;
TEST_F(DIObjCPropertyTest, get) { … }
DIImportedEntityTest;
TEST_F(DIImportedEntityTest, get) { … }
MetadataAsValueTest;
TEST_F(MetadataAsValueTest, MDNode) { … }
TEST_F(MetadataAsValueTest, MDNodeMDNode) { … }
TEST_F(MetadataAsValueTest, MDNodeConstant) { … }
ValueAsMetadataTest;
TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) { … }
TEST_F(ValueAsMetadataTest, handleRAUWWithTypeChange) { … }
TEST_F(ValueAsMetadataTest, TempTempReplacement) { … }
TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) { … }
DIArgListTest;
TEST_F(DIArgListTest, get) { … }
TEST_F(DIArgListTest, UpdatesOnRAUW) { … }
TrackingMDRefTest;
TEST_F(TrackingMDRefTest, UpdatesOnRAUW) { … }
TEST_F(TrackingMDRefTest, UpdatesOnDeletion) { … }
TEST(NamedMDNodeTest, Search) { … }
FunctionAttachmentTest;
TEST_F(FunctionAttachmentTest, setMetadata) { … }
TEST_F(FunctionAttachmentTest, getAll) { … }
TEST_F(FunctionAttachmentTest, Verifier) { … }
TEST_F(FunctionAttachmentTest, RealEntryCount) { … }
TEST_F(FunctionAttachmentTest, SyntheticEntryCount) { … }
TEST_F(FunctionAttachmentTest, SubprogramAttachment) { … }
DistinctMDOperandPlaceholderTest;
TEST_F(DistinctMDOperandPlaceholderTest, getID) { … }
TEST_F(DistinctMDOperandPlaceholderTest, replaceUseWith) { … }
TEST_F(DistinctMDOperandPlaceholderTest, replaceUseWithNoUser) { … }
#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG) && !defined(GTEST_HAS_SEH)
TEST_F(DistinctMDOperandPlaceholderTest, MetadataAsValue) {
DistinctMDOperandPlaceholder PH(7);
EXPECT_DEATH(MetadataAsValue::get(Context, &PH),
"Unexpected callback to owner");
}
TEST_F(DistinctMDOperandPlaceholderTest, UniquedMDNode) {
DistinctMDOperandPlaceholder PH(7);
EXPECT_DEATH(MDTuple::get(Context, &PH), "Unexpected callback to owner");
}
TEST_F(DistinctMDOperandPlaceholderTest, SecondDistinctMDNode) {
DistinctMDOperandPlaceholder PH(7);
MDTuple::getDistinct(Context, &PH);
EXPECT_DEATH(MDTuple::getDistinct(Context, &PH),
"Placeholders can only be used once");
}
TEST_F(DistinctMDOperandPlaceholderTest, TrackingMDRefAndDistinctMDNode) {
{
DistinctMDOperandPlaceholder PH(7);
MDTuple::getDistinct(Context, &PH);
EXPECT_DEATH(TrackingMDRef Ref(&PH), "Placeholders can only be used once");
}
{
DistinctMDOperandPlaceholder PH(7);
TrackingMDRef Ref(&PH);
EXPECT_DEATH(MDTuple::getDistinct(Context, &PH),
"Placeholders can only be used once");
}
}
#endif
DebugVariableTest;
TEST_F(DebugVariableTest, DenseMap) { … }
MDTupleAllocationTest;
TEST_F(MDTupleAllocationTest, Tracking) { … }
TEST_F(MDTupleAllocationTest, Resize) { … }
TEST_F(MDTupleAllocationTest, Tracking2) { … }
#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG) && !defined(GTEST_HAS_SEH)
typedef MetadataTest MDTupleAllocationDeathTest;
TEST_F(MDTupleAllocationDeathTest, ResizeRejected) {
MDTuple *A = MDTuple::get(Context, std::nullopt);
auto *Value1 = getConstantAsMetadata();
EXPECT_DEATH(A->push_back(Value1),
"Resizing is not supported for uniqued nodes");
auto *Value2 = getConstantAsMetadata();
auto B = MDTuple::getTemporary(Context, {Value2});
B->push_back(Value2);
MDTuple *BUniqued = MDNode::replaceWithUniqued(std::move(B));
EXPECT_EQ(BUniqued->getNumOperands(), 2u);
EXPECT_EQ(BUniqued->getOperand(1), Value2);
EXPECT_DEATH(BUniqued->push_back(Value2),
"Resizing is not supported for uniqued nodes");
}
#endif
}