Skip to content

Commit eb6e7e8

Browse files
authored
[unittests] Use {} instead of std::nullopt to initialize empty ArrayRef (#109388)
Follow up to #109133.
1 parent fc5de0a commit eb6e7e8

16 files changed

+150
-194
lines changed

llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ TEST_F(AArch64SelectionDAGTest, ReplaceAllUsesWith) {
709709
EXPECT_FALSE(DAG->getHeapAllocSite(N2.getNode()));
710710
EXPECT_FALSE(DAG->getNoMergeSiteInfo(N2.getNode()));
711711
EXPECT_FALSE(DAG->getPCSections(N2.getNode()));
712-
MDNode *MD = MDNode::get(Context, std::nullopt);
712+
MDNode *MD = MDNode::get(Context, {});
713713
DAG->addHeapAllocSite(N2.getNode(), MD);
714714
DAG->addNoMergeSiteInfo(N2.getNode(), true);
715715
DAG->addPCSections(N2.getNode(), MD);

llvm/unittests/CodeGen/InstrRefLDVTest.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ class InstrRefLDVTest : public testing::Test {
102102
OurFile = DIB.createFile("xyzzy.c", "/cave");
103103
OurCU =
104104
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "nou", false, "", 0);
105-
auto OurSubT =
106-
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
105+
auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
107106
OurFunc =
108107
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
109108
DINode::FlagZero, DISubprogram::SPFlagDefinition);

llvm/unittests/CodeGen/LexicalScopesTest.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ class LexicalScopesTest : public testing::Test {
103103
OurFile = DIB.createFile("xyzzy.c", "/cave");
104104
OurCU =
105105
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "nou", false, "", 0);
106-
auto OurSubT =
107-
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
106+
auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
108107
OurFunc =
109108
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
110109
DINode::FlagZero, DISubprogram::SPFlagDefinition);

llvm/unittests/CodeGen/MFCommon.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public:
3333
getCalleeSavedRegs(const MachineFunction *MF) const override {
3434
return nullptr;
3535
}
36-
ArrayRef<const uint32_t *> getRegMasks() const override { return std::nullopt; }
37-
ArrayRef<const char *> getRegMaskNames() const override { return std::nullopt; }
36+
ArrayRef<const uint32_t *> getRegMasks() const override { return {}; }
37+
ArrayRef<const char *> getRegMaskNames() const override { return {}; }
3838
BitVector getReservedRegs(const MachineFunction &MF) const override {
3939
return BitVector();
4040
}

llvm/unittests/CodeGen/MachineBasicBlockTest.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ TEST(FindDebugLocTest, DifferentIterators) {
4242
DIFile *OurFile = DIB.createFile("foo.c", "/bar");
4343
DICompileUnit *OurCU =
4444
DIB.createCompileUnit(dwarf::DW_LANG_C99, OurFile, "", false, "", 0);
45-
auto OurSubT =
46-
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
45+
auto OurSubT = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
4746
DISubprogram *OurFunc =
4847
DIB.createFunction(OurCU, "bees", "", OurFile, 1, OurSubT, 1,
4948
DINode::FlagZero, DISubprogram::SPFlagDefinition);

llvm/unittests/CodeGen/MachineInstrTest.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ TEST(MachineInstrExtraInfo, AddExtraInfo) {
276276
MMOs.push_back(MMO);
277277
MCSymbol *Sym1 = MC->createTempSymbol("pre_label", false);
278278
MCSymbol *Sym2 = MC->createTempSymbol("post_label", false);
279-
MDNode *HAM = MDNode::getDistinct(Ctx, std::nullopt);
280-
MDNode *PCS = MDNode::getDistinct(Ctx, std::nullopt);
279+
MDNode *HAM = MDNode::getDistinct(Ctx, {});
280+
MDNode *PCS = MDNode::getDistinct(Ctx, {});
281281
MDNode *MMRA = MMRAMetadata::getTagMD(Ctx, "foo", "bar");
282282

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

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

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

@@ -506,8 +506,8 @@ MATCHER_P(HasMIMetadata, MIMD, "") {
506506

507507
TEST(MachineInstrBuilder, BuildMI) {
508508
LLVMContext Ctx;
509-
MDNode *PCS = MDNode::getDistinct(Ctx, std::nullopt);
510-
MDNode *DI = MDNode::getDistinct(Ctx, std::nullopt);
509+
MDNode *PCS = MDNode::getDistinct(Ctx, {});
510+
MDNode *DI = MDNode::getDistinct(Ctx, {});
511511
DebugLoc DL(DI);
512512
MIMetadata MIMD(DL, PCS);
513513
EXPECT_EQ(MIMD.getDL(), DL);

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ class OpenMPIRBuilderTest : public testing::Test {
175175
std::optional<StringRef>("/src/test.dbg"));
176176
auto CU =
177177
DIB.createCompileUnit(dwarf::DW_LANG_C, File, "llvm-C", true, "", 0);
178-
auto Type =
179-
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
178+
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
180179
auto SP = DIB.createFunction(
181180
CU, "foo", "", File, 1, Type, 1, DINode::FlagZero,
182181
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);

llvm/unittests/IR/IRBuilderTest.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ TEST_F(IRBuilderTest, ConstrainedFPFunctionCall) {
438438
// Now call the empty constrained FP function.
439439
Builder.setIsFPConstrained(true);
440440
Builder.setConstrainedFPFunctionAttr();
441-
CallInst *FCall = Builder.CreateCall(Callee, std::nullopt);
441+
CallInst *FCall = Builder.CreateCall(Callee, {});
442442

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

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

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

708708
FMF.clear();
709709
FMF.setNoNaNs();
710710
Builder.setFastMathFlags(FMF);
711711

712-
FCall = Builder.CreateCall(Callee, std::nullopt);
712+
FCall = Builder.CreateCall(Callee, {});
713713
EXPECT_TRUE(Builder.getFastMathFlags().any());
714714
EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
715715
EXPECT_TRUE(FCall->hasNoNaNs());
716716

717-
FCall = Builder.CreateCall(V, std::nullopt);
717+
FCall = Builder.CreateCall(V, {});
718718
EXPECT_TRUE(Builder.getFastMathFlags().any());
719719
EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
720720
EXPECT_TRUE(FCall->hasNoNaNs());
@@ -856,7 +856,7 @@ TEST_F(IRBuilderTest, createFunction) {
856856
auto File = DIB.createFile("error.swift", "/");
857857
auto CU =
858858
DIB.createCompileUnit(dwarf::DW_LANG_Swift, File, "swiftc", true, "", 0);
859-
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
859+
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
860860
auto NoErr = DIB.createFunction(
861861
CU, "noerr", "", File, 1, Type, 1, DINode::FlagZero,
862862
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
@@ -896,8 +896,7 @@ TEST_F(IRBuilderTest, DIBuilder) {
896896
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74,
897897
DIB.createFile("F.CBL", "/"),
898898
"llvm-cobol74", true, "", 0);
899-
auto Type =
900-
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
899+
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
901900
auto SP = DIB.createFunction(
902901
CU, "foo", "", File, 1, Type, 1, DINode::FlagZero,
903902
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized);
@@ -1014,7 +1013,7 @@ TEST_F(IRBuilderTest, createArtificialSubprogram) {
10141013
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "clang",
10151014
/*isOptimized=*/true, /*Flags=*/"",
10161015
/*Runtime Version=*/0);
1017-
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
1016+
auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
10181017
auto SP = DIB.createFunction(
10191018
CU, "foo", /*LinkageName=*/"", File,
10201019
/*LineNo=*/1, Type, /*ScopeLine=*/2, DINode::FlagZero,
@@ -1168,8 +1167,7 @@ TEST_F(IRBuilderTest, DebugLoc) {
11681167
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C_plus_plus_11,
11691168
DIB.createFile("tmp.cpp", "/"), "", true, "",
11701169
0);
1171-
auto SPType =
1172-
DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt));
1170+
auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray({}));
11731171
auto SP =
11741172
DIB.createFunction(CU, "foo", "foo", File, 1, SPType, 1, DINode::FlagZero,
11751173
DISubprogram::SPFlagDefinition);
@@ -1183,13 +1181,13 @@ TEST_F(IRBuilderTest, DebugLoc) {
11831181
IRBuilder<> Builder(Ctx);
11841182
Builder.SetInsertPoint(Br);
11851183
EXPECT_EQ(DL1, Builder.getCurrentDebugLocation());
1186-
auto Call1 = Builder.CreateCall(Callee, std::nullopt);
1184+
auto Call1 = Builder.CreateCall(Callee, {});
11871185
EXPECT_EQ(DL1, Call1->getDebugLoc());
11881186

11891187
Call1->setDebugLoc(DL2);
11901188
Builder.SetInsertPoint(Call1->getParent(), Call1->getIterator());
11911189
EXPECT_EQ(DL2, Builder.getCurrentDebugLocation());
1192-
auto Call2 = Builder.CreateCall(Callee, std::nullopt);
1190+
auto Call2 = Builder.CreateCall(Callee, {});
11931191
EXPECT_EQ(DL2, Call2->getDebugLoc());
11941192

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

12071205
DIB.createImportedDeclaration(CU, nullptr, F, 1);
12081206
DIB.createImportedDeclaration(CU, nullptr, F, 1);

llvm/unittests/IR/InstructionsTest.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ TEST(InstructionsTest, AlterCallBundles) {
756756
AttrBuilder AB(C);
757757
AB.addAttribute(Attribute::Cold);
758758
Call->setAttributes(AttributeList::get(C, AttributeList::FunctionIndex, AB));
759-
Call->setDebugLoc(DebugLoc(MDNode::get(C, std::nullopt)));
759+
Call->setDebugLoc(DebugLoc(MDNode::get(C, {})));
760760

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

791791
OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7));
792792
std::unique_ptr<InvokeInst> Clone(

0 commit comments

Comments
 (0)