clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ItaniumCXXABI.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include/clang/AST -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../include -I /usr/src/gnu/usr.bin/clang/libclangAST/obj -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/lib/AST/ItaniumCXXABI.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | #include "CXXABI.h" |
| 20 | #include "clang/AST/ASTContext.h" |
| 21 | #include "clang/AST/DeclCXX.h" |
| 22 | #include "clang/AST/Mangle.h" |
| 23 | #include "clang/AST/MangleNumberingContext.h" |
| 24 | #include "clang/AST/RecordLayout.h" |
| 25 | #include "clang/AST/Type.h" |
| 26 | #include "clang/Basic/TargetInfo.h" |
| 27 | #include "llvm/ADT/FoldingSet.h" |
| 28 | #include "llvm/ADT/iterator.h" |
| 29 | |
| 30 | using namespace clang; |
| 31 | |
| 32 | namespace { |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | static const IdentifierInfo *findAnonymousUnionVarDeclName(const VarDecl& VD) { |
| 45 | const RecordType *RT = VD.getType()->getAs<RecordType>(); |
| 5 | | Assuming the object is not a 'RecordType' | |
|
| 6 | | 'RT' initialized to a null pointer value | |
|
| 46 | assert(RT && "type of VarDecl is expected to be RecordType."); |
| 47 | assert(RT->getDecl()->isUnion() && "RecordType is expected to be a union."); |
| 48 | if (const FieldDecl *FD = RT->getDecl()->findFirstNamedDataMember()) { |
| 7 | | Called C++ object pointer is null |
|
| 49 | return FD->getIdentifier(); |
| 50 | } |
| 51 | |
| 52 | return nullptr; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | struct DecompositionDeclName { |
| 57 | using BindingArray = ArrayRef<const BindingDecl*>; |
| 58 | |
| 59 | |
| 60 | BindingArray Bindings; |
| 61 | |
| 62 | |
| 63 | struct Iterator |
| 64 | : llvm::iterator_adaptor_base<Iterator, BindingArray::const_iterator, |
| 65 | std::random_access_iterator_tag, |
| 66 | const IdentifierInfo *> { |
| 67 | Iterator(BindingArray::const_iterator It) : iterator_adaptor_base(It) {} |
| 68 | const IdentifierInfo *operator*() const { |
| 69 | return (*this->I)->getIdentifier(); |
| 70 | } |
| 71 | }; |
| 72 | Iterator begin() const { return Iterator(Bindings.begin()); } |
| 73 | Iterator end() const { return Iterator(Bindings.end()); } |
| 74 | }; |
| 75 | } |
| 76 | |
| 77 | namespace llvm { |
| 78 | template<typename T> bool isDenseMapKeyEmpty(T V) { |
| 79 | return llvm::DenseMapInfo<T>::isEqual( |
| 80 | V, llvm::DenseMapInfo<T>::getEmptyKey()); |
| 81 | } |
| 82 | template<typename T> bool isDenseMapKeyTombstone(T V) { |
| 83 | return llvm::DenseMapInfo<T>::isEqual( |
| 84 | V, llvm::DenseMapInfo<T>::getTombstoneKey()); |
| 85 | } |
| 86 | |
| 87 | template<typename T> |
| 88 | Optional<bool> areDenseMapKeysEqualSpecialValues(T LHS, T RHS) { |
| 89 | bool LHSEmpty = isDenseMapKeyEmpty(LHS); |
| 90 | bool RHSEmpty = isDenseMapKeyEmpty(RHS); |
| 91 | if (LHSEmpty || RHSEmpty) |
| 92 | return LHSEmpty && RHSEmpty; |
| 93 | |
| 94 | bool LHSTombstone = isDenseMapKeyTombstone(LHS); |
| 95 | bool RHSTombstone = isDenseMapKeyTombstone(RHS); |
| 96 | if (LHSTombstone || RHSTombstone) |
| 97 | return LHSTombstone && RHSTombstone; |
| 98 | |
| 99 | return None; |
| 100 | } |
| 101 | |
| 102 | template<> |
| 103 | struct DenseMapInfo<DecompositionDeclName> { |
| 104 | using ArrayInfo = llvm::DenseMapInfo<ArrayRef<const BindingDecl*>>; |
| 105 | static DecompositionDeclName getEmptyKey() { |
| 106 | return {ArrayInfo::getEmptyKey()}; |
| 107 | } |
| 108 | static DecompositionDeclName getTombstoneKey() { |
| 109 | return {ArrayInfo::getTombstoneKey()}; |
| 110 | } |
| 111 | static unsigned getHashValue(DecompositionDeclName Key) { |
| 112 | assert(!isEqual(Key, getEmptyKey()) && !isEqual(Key, getTombstoneKey())); |
| 113 | return llvm::hash_combine_range(Key.begin(), Key.end()); |
| 114 | } |
| 115 | static bool isEqual(DecompositionDeclName LHS, DecompositionDeclName RHS) { |
| 116 | if (Optional<bool> Result = areDenseMapKeysEqualSpecialValues( |
| 117 | LHS.Bindings, RHS.Bindings)) |
| 118 | return *Result; |
| 119 | |
| 120 | return LHS.Bindings.size() == RHS.Bindings.size() && |
| 121 | std::equal(LHS.begin(), LHS.end(), RHS.begin()); |
| 122 | } |
| 123 | }; |
| 124 | } |
| 125 | |
| 126 | namespace { |
| 127 | |
| 128 | |
| 129 | |
| 130 | class ItaniumNumberingContext : public MangleNumberingContext { |
| 131 | ItaniumMangleContext *Mangler; |
| 132 | llvm::StringMap<unsigned> LambdaManglingNumbers; |
| 133 | unsigned BlockManglingNumber = 0; |
| 134 | llvm::DenseMap<const IdentifierInfo *, unsigned> VarManglingNumbers; |
| 135 | llvm::DenseMap<const IdentifierInfo *, unsigned> TagManglingNumbers; |
| 136 | llvm::DenseMap<DecompositionDeclName, unsigned> |
| 137 | DecompsitionDeclManglingNumbers; |
| 138 | |
| 139 | public: |
| 140 | ItaniumNumberingContext(ItaniumMangleContext *Mangler) : Mangler(Mangler) {} |
| 141 | |
| 142 | unsigned getManglingNumber(const CXXMethodDecl *CallOperator) override { |
| 143 | const CXXRecordDecl *Lambda = CallOperator->getParent(); |
| 144 | assert(Lambda->isLambda()); |
| 145 | |
| 146 | |
| 147 | |
| 148 | llvm::SmallString<128> LambdaSig; |
| 149 | llvm::raw_svector_ostream Out(LambdaSig); |
| 150 | Mangler->mangleLambdaSig(Lambda, Out); |
| 151 | |
| 152 | return ++LambdaManglingNumbers[LambdaSig]; |
| 153 | } |
| 154 | |
| 155 | unsigned getManglingNumber(const BlockDecl *BD) override { |
| 156 | return ++BlockManglingNumber; |
| 157 | } |
| 158 | |
| 159 | unsigned getStaticLocalNumber(const VarDecl *VD) override { |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | unsigned getManglingNumber(const VarDecl *VD, unsigned) override { |
| 165 | if (auto *DD = dyn_cast<DecompositionDecl>(VD)) { |
| 1 | Assuming 'VD' is not a 'DecompositionDecl' | |
|
| |
| 166 | DecompositionDeclName Name{DD->bindings()}; |
| 167 | return ++DecompsitionDeclManglingNumbers[Name]; |
| 168 | } |
| 169 | |
| 170 | const IdentifierInfo *Identifier = VD->getIdentifier(); |
| 171 | if (!Identifier) { |
| |
| 172 | |
| 173 | |
| 174 | Identifier = findAnonymousUnionVarDeclName(*VD); |
| 4 | | Calling 'findAnonymousUnionVarDeclName' | |
|
| 175 | } |
| 176 | return ++VarManglingNumbers[Identifier]; |
| 177 | } |
| 178 | |
| 179 | unsigned getManglingNumber(const TagDecl *TD, unsigned) override { |
| 180 | return ++TagManglingNumbers[TD->getIdentifier()]; |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | class ItaniumCXXABI : public CXXABI { |
| 185 | private: |
| 186 | std::unique_ptr<MangleContext> Mangler; |
| 187 | protected: |
| 188 | ASTContext &Context; |
| 189 | public: |
| 190 | ItaniumCXXABI(ASTContext &Ctx) |
| 191 | : Mangler(Ctx.createMangleContext()), Context(Ctx) {} |
| 192 | |
| 193 | MemberPointerInfo |
| 194 | getMemberPointerInfo(const MemberPointerType *MPT) const override { |
| 195 | const TargetInfo &Target = Context.getTargetInfo(); |
| 196 | TargetInfo::IntType PtrDiff = Target.getPtrDiffType(0); |
| 197 | MemberPointerInfo MPI; |
| 198 | MPI.Width = Target.getTypeWidth(PtrDiff); |
| 199 | MPI.Align = Target.getTypeAlign(PtrDiff); |
| 200 | MPI.HasPadding = false; |
| 201 | if (MPT->isMemberFunctionPointer()) |
| 202 | MPI.Width *= 2; |
| 203 | return MPI; |
| 204 | } |
| 205 | |
| 206 | CallingConv getDefaultMethodCallConv(bool isVariadic) const override { |
| 207 | const llvm::Triple &T = Context.getTargetInfo().getTriple(); |
| 208 | if (!isVariadic && T.isWindowsGNUEnvironment() && |
| 209 | T.getArch() == llvm::Triple::x86) |
| 210 | return CC_X86ThisCall; |
| 211 | return Context.getTargetInfo().getDefaultCallingConv(); |
| 212 | } |
| 213 | |
| 214 | |
| 215 | |
| 216 | bool isNearlyEmpty(const CXXRecordDecl *RD) const override { |
| 217 | |
| 218 | |
| 219 | if (!RD->isDynamicClass()) |
| 220 | return false; |
| 221 | |
| 222 | const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); |
| 223 | CharUnits PointerSize = |
| 224 | Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); |
| 225 | return Layout.getNonVirtualSize() == PointerSize; |
| 226 | } |
| 227 | |
| 228 | const CXXConstructorDecl * |
| 229 | getCopyConstructorForExceptionObject(CXXRecordDecl *RD) override { |
| 230 | return nullptr; |
| 231 | } |
| 232 | |
| 233 | void addCopyConstructorForExceptionObject(CXXRecordDecl *RD, |
| 234 | CXXConstructorDecl *CD) override {} |
| 235 | |
| 236 | void addTypedefNameForUnnamedTagDecl(TagDecl *TD, |
| 237 | TypedefNameDecl *DD) override {} |
| 238 | |
| 239 | TypedefNameDecl *getTypedefNameForUnnamedTagDecl(const TagDecl *TD) override { |
| 240 | return nullptr; |
| 241 | } |
| 242 | |
| 243 | void addDeclaratorForUnnamedTagDecl(TagDecl *TD, |
| 244 | DeclaratorDecl *DD) override {} |
| 245 | |
| 246 | DeclaratorDecl *getDeclaratorForUnnamedTagDecl(const TagDecl *TD) override { |
| 247 | return nullptr; |
| 248 | } |
| 249 | |
| 250 | std::unique_ptr<MangleNumberingContext> |
| 251 | createMangleNumberingContext() const override { |
| 252 | return std::make_unique<ItaniumNumberingContext>( |
| 253 | cast<ItaniumMangleContext>(Mangler.get())); |
| 254 | } |
| 255 | }; |
| 256 | } |
| 257 | |
| 258 | CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) { |
| 259 | return new ItaniumCXXABI(Ctx); |
| 260 | } |
| 261 | |
| 262 | std::unique_ptr<MangleNumberingContext> |
| 263 | clang::createItaniumNumberingContext(MangleContext *Mangler) { |
| 264 | return std::make_unique<ItaniumNumberingContext>( |
| 265 | cast<ItaniumMangleContext>(Mangler)); |
| 266 | } |