Bug Summary

File:build/source/mlir/lib/TableGen/Interfaces.cpp
Warning:line 78, 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-16/lib/clang/16 -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 MLIR_CUDA_CONVERSIONS_ENABLED=1 -D MLIR_ROCM_CONVERSIONS_ENABLED=1 -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/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 1673561342 -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-01-13-042150-16221-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/StringExtras.h"
11#include "llvm/Support/FormatVariadic.h"
12#include "llvm/TableGen/Error.h"
13#include "llvm/TableGen/Record.h"
14
15using namespace mlir;
16using namespace mlir::tblgen;
17
18//===----------------------------------------------------------------------===//
19// InterfaceMethod
20//===----------------------------------------------------------------------===//
21
22InterfaceMethod::InterfaceMethod(const llvm::Record *def) : def(def) {
23 llvm::DagInit *args = def->getValueAsDag("arguments");
24 for (unsigned i = 0, e = args->getNumArgs(); i != e; ++i) {
25 arguments.push_back(
26 {llvm::cast<llvm::StringInit>(args->getArg(i))->getValue(),
27 args->getArgNameStr(i)});
28 }
29}
30
31StringRef InterfaceMethod::getReturnType() const {
32 return def->getValueAsString("returnType");
33}
34
35// Return the name of this method.
36StringRef InterfaceMethod::getName() const {
37 return def->getValueAsString("name");
38}
39
40// Return if this method is static.
41bool InterfaceMethod::isStatic() const {
42 return def->isSubClassOf("StaticInterfaceMethod");
43}
44
45// Return the body for this method if it has one.
46std::optional<StringRef> InterfaceMethod::getBody() const {
47 auto value = def->getValueAsString("body");
48 return value.empty() ? std::optional<StringRef>() : value;
49}
50
51// Return the default implementation for this method if it has one.
52std::optional<StringRef> InterfaceMethod::getDefaultImplementation() const {
53 auto value = def->getValueAsString("defaultBody");
54 return value.empty() ? std::optional<StringRef>() : value;
55}
56
57// Return the description of this method if it has one.
58std::optional<StringRef> InterfaceMethod::getDescription() const {
59 auto value = def->getValueAsString("description");
60 return value.empty() ? std::optional<StringRef>() : value;
61}
62
63ArrayRef<InterfaceMethod::Argument> InterfaceMethod::getArguments() const {
64 return arguments;
65}
66
67bool InterfaceMethod::arg_empty() const { return arguments.empty(); }
68
69//===----------------------------------------------------------------------===//
70// Interface
71//===----------------------------------------------------------------------===//
72
73Interface::Interface(const llvm::Record *def) : def(def) {
74 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", 75, __extension__ __PRETTY_FUNCTION__
))
1
Assuming the condition is true
2
'?' condition is true
75 "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", 75, __extension__ __PRETTY_FUNCTION__
))
;
76
77 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
78 for (llvm::Init *init : listInit->getValues())
5
Called C++ object pointer is null
79 methods.emplace_back(cast<llvm::DefInit>(init)->getDef());
80}
81
82// Return the name of this interface.
83StringRef Interface::getName() const {
84 return def->getValueAsString("cppInterfaceName");
85}
86
87// Return the C++ namespace of this interface.
88StringRef Interface::getCppNamespace() const {
89 return def->getValueAsString("cppNamespace");
90}
91
92// Return the methods of this interface.
93ArrayRef<InterfaceMethod> Interface::getMethods() const { return methods; }
94
95// Return the description of this method if it has one.
96std::optional<StringRef> Interface::getDescription() const {
97 auto value = def->getValueAsString("description");
98 return value.empty() ? std::optional<StringRef>() : value;
99}
100
101// Return the interfaces extra class declaration code.
102std::optional<StringRef> Interface::getExtraClassDeclaration() const {
103 auto value = def->getValueAsString("extraClassDeclaration");
104 return value.empty() ? std::optional<StringRef>() : value;
105}
106
107// Return the traits extra class declaration code.
108std::optional<StringRef> Interface::getExtraTraitClassDeclaration() const {
109 auto value = def->getValueAsString("extraTraitClassDeclaration");
110 return value.empty() ? std::optional<StringRef>() : value;
111}
112
113// Return the shared extra class declaration code.
114std::optional<StringRef> Interface::getExtraSharedClassDeclaration() const {
115 auto value = def->getValueAsString("extraSharedClassDeclaration");
116 return value.empty() ? std::optional<StringRef>() : value;
117}
118
119// Return the body for this method if it has one.
120std::optional<StringRef> Interface::getVerify() const {
121 // Only OpInterface supports the verify method.
122 if (!isa<OpInterface>(this))
123 return std::nullopt;
124 auto value = def->getValueAsString("verify");
125 return value.empty() ? std::optional<StringRef>() : value;
126}
127
128bool Interface::verifyWithRegions() const {
129 return def->getValueAsBit("verifyWithRegions");
130}
131
132//===----------------------------------------------------------------------===//
133// AttrInterface
134//===----------------------------------------------------------------------===//
135
136bool AttrInterface::classof(const Interface *interface) {
137 return interface->getDef().isSubClassOf("AttrInterface");
138}
139
140//===----------------------------------------------------------------------===//
141// OpInterface
142//===----------------------------------------------------------------------===//
143
144bool OpInterface::classof(const Interface *interface) {
145 return interface->getDef().isSubClassOf("OpInterface");
146}
147
148//===----------------------------------------------------------------------===//
149// TypeInterface
150//===----------------------------------------------------------------------===//
151
152bool TypeInterface::classof(const Interface *interface) {
153 return interface->getDef().isSubClassOf("TypeInterface");
154}