Changeset View
Changeset View
Standalone View
Standalone View
llvm/unittests/IR/DebugInfoTest.cpp
//===- llvm/unittest/IR/DebugInfo.cpp - DebugInfo tests -------------------===// | //===- llvm/unittest/IR/DebugInfo.cpp - DebugInfo tests -------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "llvm/IR/DebugInfo.h" | #include "llvm/IR/DebugInfo.h" | ||||
#include "llvm/AsmParser/Parser.h" | #include "llvm/AsmParser/Parser.h" | ||||
#include "llvm/IR/DebugInfoMetadata.h" | #include "llvm/IR/DebugInfoMetadata.h" | ||||
#include "llvm/IR/IntrinsicInst.h" | |||||
#include "llvm/IR/LLVMContext.h" | #include "llvm/IR/LLVMContext.h" | ||||
#include "llvm/IR/Module.h" | #include "llvm/IR/Module.h" | ||||
#include "llvm/IR/Verifier.h" | #include "llvm/IR/Verifier.h" | ||||
#include "llvm/Support/SourceMgr.h" | #include "llvm/Support/SourceMgr.h" | ||||
#include "llvm/Transforms/Utils/Local.h" | |||||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | ||||
using namespace llvm; | using namespace llvm; | ||||
static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) { | static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) { | ||||
SMDiagnostic Err; | SMDiagnostic Err; | ||||
std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C); | std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C); | ||||
if (!Mod) | if (!Mod) | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | )"); | ||||
EXPECT_EQ(getEmissionKind(), DICompileUnit::LineTablesOnly); | EXPECT_EQ(getEmissionKind(), DICompileUnit::LineTablesOnly); | ||||
bool BrokenDebugInfo = false; | bool BrokenDebugInfo = false; | ||||
bool HardError = verifyModule(*M, &errs(), &BrokenDebugInfo); | bool HardError = verifyModule(*M, &errs(), &BrokenDebugInfo); | ||||
EXPECT_FALSE(HardError); | EXPECT_FALSE(HardError); | ||||
EXPECT_FALSE(BrokenDebugInfo); | EXPECT_FALSE(BrokenDebugInfo); | ||||
} | } | ||||
TEST(MetadataTest, DeleteInstUsedByDbgValue) { | |||||
LLVMContext C; | |||||
std::unique_ptr<Module> M = parseIR(C, R"( | |||||
define i16 @f(i16 %a) !dbg !6 { | |||||
%b = add i16 %a, 1, !dbg !11 | |||||
call void @llvm.dbg.value(metadata i16 %b, metadata !9, metadata !DIExpression()), !dbg !11 | |||||
ret i16 0, !dbg !11 | |||||
} | |||||
declare void @llvm.dbg.value(metadata, metadata, metadata) #0 | |||||
attributes #0 = { nounwind readnone speculatable willreturn } | |||||
!llvm.dbg.cu = !{!0} | |||||
!llvm.module.flags = !{!5} | |||||
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) | |||||
!1 = !DIFile(filename: "t.ll", directory: "/") | |||||
!2 = !{} | |||||
!5 = !{i32 2, !"Debug Info Version", i32 3} | |||||
!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8) | |||||
!7 = !DISubroutineType(types: !2) | |||||
!8 = !{!9} | |||||
!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10) | |||||
!10 = !DIBasicType(name: "ty16", size: 16, encoding: DW_ATE_unsigned) | |||||
!11 = !DILocation(line: 1, column: 1, scope: !6) | |||||
)"); | |||||
// Find %b = add ... | |||||
Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI(); | |||||
// Find the dbg.value using %b. | |||||
SmallVector<DbgValueInst *, 1> DVIs; | |||||
findDbgValues(DVIs, &I); | |||||
// Delete %b. The dbg.value should now point to undef. | |||||
I.eraseFromParent(); | |||||
EXPECT_TRUE(isa<UndefValue>(DVIs[0]->getValue())); | |||||
} | |||||
} // end namespace | } // end namespace |