Skip to content

Commit

Permalink
[unittests] Use {} instead of std::nullopt to initialize empty ArrayR…
Browse files Browse the repository at this point in the history
…ef (llvm#109388)

Follow up to llvm#109133.
  • Loading branch information
jayfoad authored Sep 21, 2024
1 parent fc5de0a commit eb6e7e8
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 194 deletions.
2 changes: 1 addition & 1 deletion llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ TEST_F(AArch64SelectionDAGTest, ReplaceAllUsesWith) {
EXPECT_FALSE(DAG->getHeapAllocSite(N2.getNode()));
EXPECT_FALSE(DAG->getNoMergeSiteInfo(N2.getNode()));
EXPECT_FALSE(DAG->getPCSections(N2.getNode()));
MDNode *MD = MDNode::get(Context, std::nullopt);
MDNode *MD = MDNode::get(Context, {});
DAG->addHeapAllocSite(N2.getNode(), MD);
DAG->addNoMergeSiteInfo(N2.getNode(), true);
DAG->addPCSections(N2.getNode(), MD);
Expand Down
3 changes: 1 addition & 2 deletions llvm/unittests/CodeGen/InstrRefLDVTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class InstrRefLDVTest : public testing::Test {
OurFile = DIB.createFile("xyzzy.c", "/cave");
OurCU =
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "nou", false, "", 0);
auto OurSubT =
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
OurFunc =
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
DINode::FlagZero, DISubprogram::SPFlagDefinition);
Expand Down
3 changes: 1 addition & 2 deletions llvm/unittests/CodeGen/LexicalScopesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ class LexicalScopesTest : public testing::Test {
OurFile = DIB.createFile("xyzzy.c", "/cave");
OurCU =
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "nou", false, "", 0);
auto OurSubT =
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
OurFunc =
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
DINode::FlagZero, DISubprogram::SPFlagDefinition);
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/CodeGen/MFCommon.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public:
getCalleeSavedRegs(const MachineFunction *MF) const override {
return nullptr;
}
ArrayRef<const uint32_t *> getRegMasks() const override { return std::nullopt; }
ArrayRef<const char *> getRegMaskNames() const override { return std::nullopt; }
ArrayRef<const uint32_t *> getRegMasks() const override { return {}; }
ArrayRef<const char *> getRegMaskNames() const override { return {}; }
BitVector getReservedRegs(const MachineFunction &MF) const override {
return BitVector();
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/unittests/CodeGen/MachineBasicBlockTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ TEST(FindDebugLocTest, DifferentIterators) {
DIFile *OurFile = DIB.createFile("foo.c", "/bar");
DICompileUnit *OurCU =
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "", false, "", 0);
auto OurSubT =
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
DISubprogram *OurFunc =
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
DINode::FlagZero, DISubprogram::SPFlagDefinition);
Expand Down
16 changes: 8 additions & 8 deletions llvm/unittests/CodeGen/MachineInstrTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ TEST(MachineInstrExtraInfo, AddExtraInfo) {
MMOs.push_back(MMO);
MCSymbol *Sym1 = MC->createTempSymbol("pre_label", false);
MCSymbol *Sym2 = MC->createTempSymbol("post_label", false);
MDNode *HAM = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *PCS = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *HAM = MDNode::getDistinct(Ctx, {});
MDNode *PCS = MDNode::getDistinct(Ctx, {});
MDNode *MMRA = MMRAMetadata::getTagMD(Ctx, "foo", "bar");

ASSERT_TRUE(MI->memoperands_empty());
Expand Down Expand Up @@ -357,8 +357,8 @@ TEST(MachineInstrExtraInfo, ChangeExtraInfo) {
MMOs.push_back(MMO);
MCSymbol *Sym1 = MC->createTempSymbol("pre_label", false);
MCSymbol *Sym2 = MC->createTempSymbol("post_label", false);
MDNode *HAM = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *PCS = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *HAM = MDNode::getDistinct(Ctx, {});
MDNode *PCS = MDNode::getDistinct(Ctx, {});

MDNode *MMRA1 = MMRAMetadata::getTagMD(Ctx, "foo", "bar");
MDNode *MMRA2 = MMRAMetadata::getTagMD(Ctx, "bar", "bux");
Expand Down Expand Up @@ -413,8 +413,8 @@ TEST(MachineInstrExtraInfo, RemoveExtraInfo) {
MMOs.push_back(MMO);
MCSymbol *Sym1 = MC->createTempSymbol("pre_label", false);
MCSymbol *Sym2 = MC->createTempSymbol("post_label", false);
MDNode *HAM = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *PCS = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *HAM = MDNode::getDistinct(Ctx, {});
MDNode *PCS = MDNode::getDistinct(Ctx, {});

MDNode *MMRA = MDTuple::get(Ctx, {});

Expand Down Expand Up @@ -506,8 +506,8 @@ MATCHER_P(HasMIMetadata, MIMD, "") {

TEST(MachineInstrBuilder, BuildMI) {
LLVMContext Ctx;
MDNode *PCS = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *DI = MDNode::getDistinct(Ctx, std::nullopt);
MDNode *PCS = MDNode::getDistinct(Ctx, {});
MDNode *DI = MDNode::getDistinct(Ctx, {});
DebugLoc DL(DI);
MIMetadata MIMD(DL, PCS);
EXPECT_EQ(MIMD.getDL(), DL);
Expand Down
3 changes: 1 addition & 2 deletions llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ class OpenMPIRBuilderTest : public testing::Test {
std::optional<StringRef>("/src/test.dbg"));
auto CU =
DIB.createCompileUnit(dwarf::DW_LANG_C, File, "llvm-C", true, "", 0);
auto Type =
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
auto SP = DIB.createFunction(
CU, "foo", "", File, 1, Type, 1, DINode::FlagZero,
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
Expand Down
26 changes: 12 additions & 14 deletions llvm/unittests/IR/IRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ TEST_F(IRBuilderTest, ConstrainedFPFunctionCall) {
// Now call the empty constrained FP function.
Builder.setIsFPConstrained(true);
Builder.setConstrainedFPFunctionAttr();
CallInst *FCall = Builder.CreateCall(Callee, std::nullopt);
CallInst *FCall = Builder.CreateCall(Callee, {});

// Check the attributes to verify the strictfp attribute is on the call.
EXPECT_TRUE(
Expand Down Expand Up @@ -697,24 +697,24 @@ TEST_F(IRBuilderTest, FastMathFlags) {
auto Callee =
Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get());

FCall = Builder.CreateCall(Callee, std::nullopt);
FCall = Builder.CreateCall(Callee, {});
EXPECT_FALSE(FCall->hasNoNaNs());

Function *V =
Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get());
FCall = Builder.CreateCall(V, std::nullopt);
FCall = Builder.CreateCall(V, {});
EXPECT_FALSE(FCall->hasNoNaNs());

FMF.clear();
FMF.setNoNaNs();
Builder.setFastMathFlags(FMF);

FCall = Builder.CreateCall(Callee, std::nullopt);
FCall = Builder.CreateCall(Callee, {});
EXPECT_TRUE(Builder.getFastMathFlags().any());
EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
EXPECT_TRUE(FCall->hasNoNaNs());

FCall = Builder.CreateCall(V, std::nullopt);
FCall = Builder.CreateCall(V, {});
EXPECT_TRUE(Builder.getFastMathFlags().any());
EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
EXPECT_TRUE(FCall->hasNoNaNs());
Expand Down Expand Up @@ -856,7 +856,7 @@ TEST_F(IRBuilderTest, createFunction) {
auto File = DIB.createFile("error.swift", "/");
auto CU =
DIB.createCompileUnit(dwarf::DW_LANG_Swift, File, "swiftc", true, "", 0);
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
auto NoErr = DIB.createFunction(
CU, "noerr", "", File, 1, Type, 1, DINode::FlagZero,
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
Expand Down Expand Up @@ -896,8 +896,7 @@ TEST_F(IRBuilderTest, DIBuilder) {
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74,
DIB.createFile("F.CBL", "/"),
"llvm-cobol74", true, "", 0);
auto Type =
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
auto SP = DIB.createFunction(
CU, "foo", "", File, 1, Type, 1, DINode::FlagZero,
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
Expand Down Expand Up @@ -1014,7 +1013,7 @@ TEST_F(IRBuilderTest, createArtificialSubprogram) {
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "clang",
/*isOptimized=*/true, /*Flags=*/"",
/*Runtime Version=*/0);
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
auto SP = DIB.createFunction(
CU, "foo", /*LinkageName=*/"", File,
/*LineNo=*/1, Type, /*ScopeLine=*/2, DINode::FlagZero,
Expand Down Expand Up @@ -1168,8 +1167,7 @@ TEST_F(IRBuilderTest, DebugLoc) {
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C_plus_plus_11,
DIB.createFile("tmp.cpp", "/"), "", true, "",
0);
auto SPType =
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
auto SP =
DIB.createFunction(CU, "foo", "foo", File, 1, SPType, 1, DINode::FlagZero,
DISubprogram::SPFlagDefinition);
Expand All @@ -1183,13 +1181,13 @@ TEST_F(IRBuilderTest, DebugLoc) {
IRBuilder<> Builder(Ctx);
Builder.SetInsertPoint(Br);
EXPECT_EQ(DL1, Builder.getCurrentDebugLocation());
auto Call1 = Builder.CreateCall(Callee, std::nullopt);
auto Call1 = Builder.CreateCall(Callee, {});
EXPECT_EQ(DL1, Call1->getDebugLoc());

Call1->setDebugLoc(DL2);
Builder.SetInsertPoint(Call1->getParent(), Call1->getIterator());
EXPECT_EQ(DL2, Builder.getCurrentDebugLocation());
auto Call2 = Builder.CreateCall(Callee, std::nullopt);
auto Call2 = Builder.CreateCall(Callee, {});
EXPECT_EQ(DL2, Call2->getDebugLoc());

DIB.finalize();
Expand All @@ -1202,7 +1200,7 @@ TEST_F(IRBuilderTest, DIImportedEntity) {
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74,
F, "llvm-cobol74",
true, "", 0);
MDTuple *Elements = MDTuple::getDistinct(Ctx, std::nullopt);
MDTuple *Elements = MDTuple::getDistinct(Ctx, {});

DIB.createImportedDeclaration(CU, nullptr, F, 1);
DIB.createImportedDeclaration(CU, nullptr, F, 1);
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/IR/InstructionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ TEST(InstructionsTest, AlterCallBundles) {
AttrBuilder AB(C);
AB.addAttribute(Attribute::Cold);
Call->setAttributes(AttributeList::get(C, AttributeList::FunctionIndex, AB));
Call->setDebugLoc(DebugLoc(MDNode::get(C, std::nullopt)));
Call->setDebugLoc(DebugLoc(MDNode::get(C, {})));

OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7));
std::unique_ptr<CallInst> Clone(CallInst::Create(Call.get(), NewBundle));
Expand Down Expand Up @@ -786,7 +786,7 @@ TEST(InstructionsTest, AlterInvokeBundles) {
AB.addAttribute(Attribute::Cold);
Invoke->setAttributes(
AttributeList::get(C, AttributeList::FunctionIndex, AB));
Invoke->setDebugLoc(DebugLoc(MDNode::get(C, std::nullopt)));
Invoke->setDebugLoc(DebugLoc(MDNode::get(C, {})));

OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7));
std::unique_ptr<InvokeInst> Clone(
Expand Down
Loading

0 comments on commit eb6e7e8

Please sign in to comment.