clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name ReduceDIMetadata.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-17/lib/clang/17 -I tools/llvm-reduce -I /build/source/llvm/tools/llvm-reduce -I include -I /build/source/llvm/include -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-17/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/source/= -source-date-epoch 1675682001 -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2023-02-06-130241-16458-1 -x c++ /build/source/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #include "ReduceDIMetadata.h" |
15 | #include "Delta.h" |
16 | #include "llvm/ADT/Sequence.h" |
17 | #include "llvm/ADT/SetVector.h" |
18 | #include "llvm/ADT/SmallSet.h" |
19 | #include "llvm/ADT/SmallVector.h" |
20 | #include "llvm/IR/DebugInfoMetadata.h" |
21 | #include "llvm/IR/InstIterator.h" |
22 | #include <set> |
23 | #include <stack> |
24 | #include <tuple> |
25 | #include <vector> |
26 | |
27 | using namespace llvm; |
28 | |
29 | using MDNodeList = SmallVector<MDNode *>; |
30 | |
31 | void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) { |
32 | SetVector<std::tuple<MDNode *, size_t, MDNode *>> Tuples; |
33 | std::vector<MDNode *> ToLook; |
34 | SetVector<MDNode *> Visited; |
35 | |
36 | |
37 | for (const auto &NMD : MDs) |
| 2 | | Assuming '__begin1' is equal to '__end1' | |
|
38 | if (NMD) |
39 | ToLook.push_back(NMD); |
40 | |
41 | while (!ToLook.empty()) { |
| 3 | | Assuming the condition is true | |
|
| 4 | | Loop condition is true. Entering loop body | |
|
42 | MDNode *MD = ToLook.back(); |
43 | ToLook.pop_back(); |
44 | |
45 | if (Visited.count(MD)) |
| |
| 6 | | Assuming the condition is false | |
|
| |
46 | continue; |
47 | |
48 | |
49 | if (DINode *DIM = dyn_cast_or_null<DINode>(MD)) { |
| 8 | | Assuming null pointer is passed into cast | |
|
| |
50 | |
51 | for (size_t I = 0; I < DIM->getNumOperands(); ++I) |
52 | if (MDTuple *MDT = dyn_cast_or_null<MDTuple>(DIM->getOperand(I))) |
53 | if (!Visited.count(MDT) && MDT->getNumOperands()) |
54 | Tuples.insert({DIM, I, MDT}); |
55 | } |
56 | |
57 | |
58 | for (Metadata *Op : MD->operands()) |
| 10 | | Called C++ object pointer is null |
|
59 | if (MDNode *OMD = dyn_cast_or_null<MDNode>(Op)) |
60 | ToLook.push_back(OMD); |
61 | |
62 | Visited.insert(MD); |
63 | } |
64 | |
65 | for (auto &T : Tuples) { |
66 | auto [DbgNode, OpIdx, Tup] = T; |
67 | |
68 | SmallVector<Metadata *, 16> TN; |
69 | for (size_t I = 0; I < Tup->getNumOperands(); ++I) { |
70 | |
71 | if (isa_and_nonnull<DINode>(Tup->getOperand(I))) |
72 | |
73 | if (!O.shouldKeep()) |
74 | continue; |
75 | |
76 | TN.push_back(Tup->getOperand(I)); |
77 | } |
78 | if (TN.size() != Tup->getNumOperands()) |
79 | DbgNode->replaceOperandWith(OpIdx, DbgNode->get(DbgNode->getContext(), TN)); |
80 | } |
81 | } |
82 | |
83 | static void extractDIMetadataFromModule(Oracle &O, ReducerWorkItem &WorkItem) { |
84 | Module &Program = WorkItem.getModule(); |
85 | |
86 | MDNodeList MDs; |
87 | |
88 | for (const auto &DC : Program.debug_compile_units()) |
89 | if (DC) |
90 | MDs.push_back(DC); |
91 | for (GlobalVariable &GV : Program.globals()) |
92 | GV.getMetadata(llvm::LLVMContext::MD_dbg, MDs); |
93 | for (Function &F : Program.functions()) { |
94 | F.getMetadata(llvm::LLVMContext::MD_dbg, MDs); |
95 | for (Instruction &I : instructions(F)) |
96 | if (auto *DI = I.getMetadata(llvm::LLVMContext::MD_dbg)) |
97 | MDs.push_back(DI); |
98 | } |
99 | identifyUninterestingMDNodes(O, MDs); |
| 1 | Calling 'identifyUninterestingMDNodes' | |
|
100 | } |
101 | |
102 | void llvm::reduceDIMetadataDeltaPass(TestRunner &Test) { |
103 | runDeltaPass(Test, extractDIMetadataFromModule, "Reducing DIMetadata"); |
104 | } |