Bug Summary

File:build/source/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
Warning:line 56, 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-16/lib/clang/16.0.0 -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-16/lib/clang/16.0.0/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 1670066131 -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-2022-12-03-132955-15984-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/SmallVector.h"
18#include "llvm/IR/DebugInfoMetadata.h"
19#include "llvm/IR/InstIterator.h"
20#include <set>
21#include <stack>
22#include <tuple>
23#include <vector>
24
25using namespace llvm;
26
27using MDNodeList = SmallVector<MDNode *>;
28
29void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
30 SetVector<std::tuple<MDNode *, size_t, MDNode *>> Tuples;
31 std::vector<MDNode *> ToLook;
32 SetVector<MDNode *> Visited;
33
34 // Start by looking at the attachments we collected
35 for (const auto &NMD : MDs)
2
Assuming '__begin1' is equal to '__end1'
36 if (NMD)
37 ToLook.push_back(NMD);
38
39 while (!ToLook.empty()) {
3
Assuming the condition is true
4
Loop condition is true. Entering loop body
40 MDNode *MD = ToLook.back();
41 ToLook.pop_back();
42
43 if (Visited.count(MD))
5
Value assigned to 'MD'
6
Assuming the condition is false
7
Taking false branch
44 continue;
45
46 // Determine if the current MDNode is DebugInfo
47 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
48 // Scan operands and record attached tuples
49 for (size_t I = 0; I < DIM->getNumOperands(); ++I)
50 if (MDTuple *MDT = dyn_cast_or_null<MDTuple>(DIM->getOperand(I)))
51 if (!Visited.count(MDT) && MDT->getNumOperands())
52 Tuples.insert({DIM, I, MDT});
53 }
54
55 // Add all of the operands of the current node to the loop's todo list.
56 for (Metadata *Op : MD->operands())
10
Called C++ object pointer is null
57 if (MDNode *OMD = dyn_cast_or_null<MDNode>(Op))
58 ToLook.push_back(OMD);
59
60 Visited.insert(MD);
61 }
62
63 for (auto &T : Tuples) {
64 auto [DbgNode, OpIdx, Tup] = T;
65 // Remove the operands of the tuple that are not in the desired chunks.
66 SmallVector<Metadata *, 16> TN;
67 for (size_t I = 0; I < Tup->getNumOperands(); ++I) {
68 // Ignore any operands that are not DebugInfo metadata nodes.
69 if (isa_and_nonnull<DINode>(Tup->getOperand(I)))
70 // Don't add uninteresting operands to the tuple.
71 if (!O.shouldKeep())
72 continue;
73
74 TN.push_back(Tup->getOperand(I));
75 }
76 if (TN.size() != Tup->getNumOperands())
77 DbgNode->replaceOperandWith(OpIdx, DbgNode->get(DbgNode->getContext(), TN));
78 }
79}
80
81static void extractDIMetadataFromModule(Oracle &O, Module &Program) {
82 MDNodeList MDs;
83 // Collect all !dbg metadata attachments.
84 for (const auto &DC : Program.debug_compile_units())
85 if (DC)
86 MDs.push_back(DC);
87 for (GlobalVariable &GV : Program.globals())
88 GV.getMetadata(llvm::LLVMContext::MD_dbg, MDs);
89 for (Function &F : Program.functions()) {
90 F.getMetadata(llvm::LLVMContext::MD_dbg, MDs);
91 for (Instruction &I : instructions(F))
92 if (auto *DI = I.getMetadata(llvm::LLVMContext::MD_dbg))
93 MDs.push_back(DI);
94 }
95 identifyUninterestingMDNodes(O, MDs);
1
Calling 'identifyUninterestingMDNodes'
96}
97
98void llvm::reduceDIMetadataDeltaPass(TestRunner &Test) {
99 runDeltaPass(Test, extractDIMetadataFromModule, "Reducing DIMetadata");
100}