Bug Summary

File:build/source/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
Warning:line 58, column 25
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

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//===- ReduceDIMetadata.cpp - Specialized Delta pass for DebugInfo --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements two functions used by the Generic Delta Debugging
10// Algorithm, which are used to reduce DebugInfo metadata nodes.
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
27using namespace llvm;
28
29using MDNodeList = SmallVector<MDNode *>;
30
31void 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 // Start by looking at the attachments we collected
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))
5
Value assigned to 'MD'
6
Assuming the condition is false
7
Taking false branch
46 continue;
47
48 // Determine if the current MDNode is DebugInfo
49 if (DINode *DIM
8.1
'DIM' is null
= dyn_cast_or_null<DINode>(MD)) {
8
Assuming null pointer is passed into cast
9
Taking false branch
50 // Scan operands and record attached tuples
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 // Add all of the operands of the current node to the loop's todo list.
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 // Remove the operands of the tuple that are not in the desired chunks.
68 SmallVector<Metadata *, 16> TN;
69 for (size_t I = 0; I < Tup->getNumOperands(); ++I) {
70 // Ignore any operands that are not DebugInfo metadata nodes.
71 if (isa_and_nonnull<DINode>(Tup->getOperand(I)))
72 // Don't add uninteresting operands to the tuple.
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
83static void extractDIMetadataFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
84 Module &Program = WorkItem.getModule();
85
86 MDNodeList MDs;
87 // Collect all !dbg metadata attachments.
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
102void llvm::reduceDIMetadataDeltaPass(TestRunner &Test) {
103 runDeltaPass(Test, extractDIMetadataFromModule, "Reducing DIMetadata");
104}