InstrProf: Simplify some logic by using ArrayRef::slice (NFC)
[oota-llvm.git] / unittests / IR / IRBuilderTest.cpp
index 21085755fbadf9114bec9fd1ec4265e502baee15..08a729aba5061f61fb8a79058cca353c5528c86e 100644 (file)
@@ -10,6 +10,7 @@
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DIBuilder.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/LLVMContext.h"
@@ -189,12 +190,16 @@ TEST_F(IRBuilderTest, FastMathFlags) {
 
   Builder.clearFastMathFlags();
 
+  // To test a copy, make sure that a '0' and a '1' change state. 
   F = Builder.CreateFDiv(F, F);
   ASSERT_TRUE(isa<Instruction>(F));
   FDiv = cast<Instruction>(F);
   EXPECT_FALSE(FDiv->getFastMathFlags().any());
+  FDiv->setHasAllowReciprocal(true);
+  FAdd->setHasAllowReciprocal(false);
   FDiv->copyFastMathFlags(FAdd);
   EXPECT_TRUE(FDiv->hasNoNaNs());
+  EXPECT_FALSE(FDiv->hasAllowReciprocal());
 
 }
 
@@ -283,5 +288,22 @@ TEST_F(IRBuilderTest, RAIIHelpersTest) {
   EXPECT_EQ(BB, Builder.GetInsertBlock());
 }
 
+TEST_F(IRBuilderTest, DIBuilder) {
+  IRBuilder<> Builder(BB);
+  DIBuilder DIB(*M);
+  auto File = DIB.createFile("F.CBL", "/");
+  auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, "F.CBL", "/",
+                                  "llvm-cobol74", true, "", 0);
+  auto Type = DIB.createSubroutineType(File, DIB.getOrCreateTypeArray(None));
+  auto SP = DIB.createFunction(CU, "foo", "", File, 1, Type,
+                               false, true, 1, 0, true, F);
+  EXPECT_TRUE(SP.Verify());
+  AllocaInst *I = Builder.CreateAlloca(Builder.getInt8Ty());
+  auto BadScope = DIB.createLexicalBlockFile(DIDescriptor(), File, 0);
+  I->setDebugLoc(DebugLoc::get(2, 0, BadScope));
+  EXPECT_FALSE(SP.Verify());
+  DIB.finalize();
+}
+
 
 }