Bug Summary

File:build/source/mlir/lib/TableGen/Interfaces.cpp
Warning:line 80, column 27
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 Interfaces.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 -D MLIR_CUDA_CONVERSIONS_ENABLED=1 -D MLIR_ROCM_CONVERSIONS_ENABLED=1 -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/mlir/lib/TableGen -I /build/source/mlir/lib/TableGen -I include -I /build/source/llvm/include -I /build/source/mlir/include -I tools/mlir/include -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 1683717183 -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-05-10-133810-16478-1 -x c++ /build/source/mlir/lib/TableGen/Interfaces.cpp
1//===- Interfaces.cpp - Interface classes ---------------------------------===//
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#include "mlir/TableGen/Interfaces.h"
10#include "llvm/ADT/FunctionExtras.h"
11#include "llvm/ADT/StringExtras.h"
12#include "llvm/Support/FormatVariadic.h"
13#include "llvm/TableGen/Error.h"
14#include "llvm/TableGen/Record.h"
15
16using namespace mlir;
17using namespace mlir::tblgen;
18
19//===----------------------------------------------------------------------===//
20// InterfaceMethod
21//===----------------------------------------------------------------------===//
22
23InterfaceMethod::InterfaceMethod(const llvm::Record *def) : def(def) {
24 llvm::DagInit *args = def->getValueAsDag("arguments");
25 for (unsigned i = 0, e = args->getNumArgs(); i != e; ++i) {
26 arguments.push_back(
27 {llvm::cast<llvm::StringInit>(args->getArg(i))->getValue(),
28 args->getArgNameStr(i)});
29 }
30}
31
32StringRef InterfaceMethod::getReturnType() const {
33 return def->getValueAsString("returnType");
34}
35
36// Return the name of this method.
37StringRef InterfaceMethod::getName() const {
38 return def->getValueAsString("name");
39}
40
41// Return if this method is static.
42bool InterfaceMethod::isStatic() const {
43 return def->isSubClassOf("StaticInterfaceMethod");
44}
45
46// Return the body for this method if it has one.
47std::optional<StringRef> InterfaceMethod::getBody() const {
48 auto value = def->getValueAsString("body");
49 return value.empty() ? std::optional<StringRef>() : value;
50}
51
52// Return the default implementation for this method if it has one.
53std::optional<StringRef> InterfaceMethod::getDefaultImplementation() const {
54 auto value = def->getValueAsString("defaultBody");
55 return value.empty() ? std::optional<StringRef>() : value;
56}
57
58// Return the description of this method if it has one.
59std::optional<StringRef> InterfaceMethod::getDescription() const {
60 auto value = def->getValueAsString("description");
61 return value.empty() ? std::optional<StringRef>() : value;
62}
63
64ArrayRef<InterfaceMethod::Argument> InterfaceMethod::getArguments() const {
65 return arguments;
66}
67
68bool InterfaceMethod::arg_empty() const { return arguments.empty(); }
69
70//===----------------------------------------------------------------------===//
71// Interface
72//===----------------------------------------------------------------------===//
73
74Interface::Interface(const llvm::Record *def) : def(def) {
75 assert(def->isSubClassOf("Interface") &&(static_cast <bool> (def->isSubClassOf("Interface") &&
"must be subclass of TableGen 'Interface' class") ? void (0)
: __assert_fail ("def->isSubClassOf(\"Interface\") && \"must be subclass of TableGen 'Interface' class\""
, "mlir/lib/TableGen/Interfaces.cpp", 76, __extension__ __PRETTY_FUNCTION__
))
1
Assuming the condition is true
2
'?' condition is true
76 "must be subclass of TableGen 'Interface' class")(static_cast <bool> (def->isSubClassOf("Interface") &&
"must be subclass of TableGen 'Interface' class") ? void (0)
: __assert_fail ("def->isSubClassOf(\"Interface\") && \"must be subclass of TableGen 'Interface' class\""
, "mlir/lib/TableGen/Interfaces.cpp", 76, __extension__ __PRETTY_FUNCTION__
))
;
77
78 // Initialize the interface methods.
79 auto *listInit = dyn_cast<llvm::ListInit>(def->getValueInit("methods"));
3
Assuming the object is not a 'CastReturnType'
4
'listInit' initialized to a null pointer value
80 for (llvm::Init *init : listInit->getValues())
5
Called C++ object pointer is null
81 methods.emplace_back(cast<llvm::DefInit>(init)->getDef());
82
83 // Initialize the interface base classes.
84 auto *basesInit =
85 dyn_cast<llvm::ListInit>(def->getValueInit("baseInterfaces"));
86 llvm::unique_function<void(Interface)> addBaseInterfaceFn =
87 [&](const Interface &baseInterface) {
88 // Inherit any base interfaces.
89 for (const auto &baseBaseInterface : baseInterface.getBaseInterfaces())
90 addBaseInterfaceFn(baseBaseInterface);
91
92 // Add the base interface.
93 baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
94 };
95 for (llvm::Init *init : basesInit->getValues())
96 addBaseInterfaceFn(Interface(cast<llvm::DefInit>(init)->getDef()));
97}
98
99// Return the name of this interface.
100StringRef Interface::getName() const {
101 return def->getValueAsString("cppInterfaceName");
102}
103
104// Returns this interface's name prefixed with namespaces.
105std::string Interface::getFullyQualifiedName() const {
106 StringRef cppNamespace = getCppNamespace();
107 StringRef name = getName();
108 if (cppNamespace.empty())
109 return name.str();
110 return (cppNamespace + "::" + name).str();
111}
112
113// Return the C++ namespace of this interface.
114StringRef Interface::getCppNamespace() const {
115 return def->getValueAsString("cppNamespace");
116}
117
118// Return the methods of this interface.
119ArrayRef<InterfaceMethod> Interface::getMethods() const { return methods; }
120
121// Return the description of this method if it has one.
122std::optional<StringRef> Interface::getDescription() const {
123 auto value = def->getValueAsString("description");
124 return value.empty() ? std::optional<StringRef>() : value;
125}
126
127// Return the interfaces extra class declaration code.
128std::optional<StringRef> Interface::getExtraClassDeclaration() const {
129 auto value = def->getValueAsString("extraClassDeclaration");
130 return value.empty() ? std::optional<StringRef>() : value;
131}
132
133// Return the traits extra class declaration code.
134std::optional<StringRef> Interface::getExtraTraitClassDeclaration() const {
135 auto value = def->getValueAsString("extraTraitClassDeclaration");
136 return value.empty() ? std::optional<StringRef>() : value;
137}
138
139// Return the shared extra class declaration code.
140std::optional<StringRef> Interface::getExtraSharedClassDeclaration() const {
141 auto value = def->getValueAsString("extraSharedClassDeclaration");
142 return value.empty() ? std::optional<StringRef>() : value;
143}
144
145std::optional<StringRef> Interface::getExtraClassOf() const {
146 auto value = def->getValueAsString("extraClassOf");
147 return value.empty() ? std::optional<StringRef>() : value;
148}
149
150// Return the body for this method if it has one.
151std::optional<StringRef> Interface::getVerify() const {
152 // Only OpInterface supports the verify method.
153 if (!isa<OpInterface>(this))
154 return std::nullopt;
155 auto value = def->getValueAsString("verify");
156 return value.empty() ? std::optional<StringRef>() : value;
157}
158
159bool Interface::verifyWithRegions() const {
160 return def->getValueAsBit("verifyWithRegions");
161}
162
163//===----------------------------------------------------------------------===//
164// AttrInterface
165//===----------------------------------------------------------------------===//
166
167bool AttrInterface::classof(const Interface *interface) {
168 return interface->getDef().isSubClassOf("AttrInterface");
169}
170
171//===----------------------------------------------------------------------===//
172// OpInterface
173//===----------------------------------------------------------------------===//
174
175bool OpInterface::classof(const Interface *interface) {
176 return interface->getDef().isSubClassOf("OpInterface");
177}
178
179//===----------------------------------------------------------------------===//
180// TypeInterface
181//===----------------------------------------------------------------------===//
182
183bool TypeInterface::classof(const Interface *interface) {
184 return interface->getDef().isSubClassOf("TypeInterface");
185}