Bug Summary

File:build/source/llvm/lib/ObjCopy/XCOFF/XCOFFWriter.cpp
Warning:line 105, column 3
Value stored to 'Ptr' is never read

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 XCOFFWriter.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 _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/ObjCopy -I /build/source/llvm/lib/ObjCopy -I include -I /build/source/llvm/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/llvm/lib/ObjCopy/XCOFF/XCOFFWriter.cpp
1//===- XCOFFWriter.cpp ----------------------------------------------------===//
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 "llvm/Support/Errc.h"
10#include "XCOFFWriter.h"
11
12namespace llvm {
13namespace objcopy {
14namespace xcoff {
15
16using namespace object;
17
18void XCOFFWriter::finalizeHeaders() {
19 // File header.
20 FileSize += sizeof(XCOFFFileHeader32);
21 // Optional file header.
22 FileSize += Obj.FileHeader.AuxHeaderSize;
23 // Section headers.
24 FileSize += sizeof(XCOFFSectionHeader32) * Obj.Sections.size();
25}
26
27void XCOFFWriter::finalizeSections() {
28 for (const Section &Sec : Obj.Sections) {
29 // Section data.
30 FileSize += Sec.Contents.size();
31 // Relocations.
32 FileSize +=
33 Sec.SectionHeader.NumberOfRelocations * sizeof(XCOFFRelocation32);
34 }
35}
36
37void XCOFFWriter::finalizeSymbolStringTable() {
38 assert(Obj.FileHeader.SymbolTableOffset >= FileSize)(static_cast <bool> (Obj.FileHeader.SymbolTableOffset >=
FileSize) ? void (0) : __assert_fail ("Obj.FileHeader.SymbolTableOffset >= FileSize"
, "llvm/lib/ObjCopy/XCOFF/XCOFFWriter.cpp", 38, __extension__
__PRETTY_FUNCTION__))
;
39 FileSize = Obj.FileHeader.SymbolTableOffset;
40 // Symbols and auxiliary entries.
41 FileSize +=
42 Obj.FileHeader.NumberOfSymTableEntries * XCOFF::SymbolTableEntrySize;
43 // String table.
44 FileSize += Obj.StringTable.size();
45}
46
47void XCOFFWriter::finalize() {
48 FileSize = 0;
49 finalizeHeaders();
50 finalizeSections();
51 finalizeSymbolStringTable();
52}
53
54void XCOFFWriter::writeHeaders() {
55 // Write the file header.
56 uint8_t *Ptr = reinterpret_cast<uint8_t *>(Buf->getBufferStart());
57 memcpy(Ptr, &Obj.FileHeader, sizeof(XCOFFFileHeader32));
58 Ptr += sizeof(XCOFFFileHeader32);
59
60 // Write the optional header.
61 if (Obj.FileHeader.AuxHeaderSize) {
62 memcpy(Ptr, &Obj.OptionalFileHeader, Obj.FileHeader.AuxHeaderSize);
63 Ptr += Obj.FileHeader.AuxHeaderSize;
64 }
65
66 // Write section headers.
67 for (const Section &Sec : Obj.Sections) {
68 memcpy(Ptr, &Sec.SectionHeader, sizeof(XCOFFSectionHeader32));
69 Ptr += sizeof(XCOFFSectionHeader32);
70 }
71}
72
73void XCOFFWriter::writeSections() {
74 // Write section data.
75 for (const Section &Sec : Obj.Sections) {
76 uint8_t *Ptr = reinterpret_cast<uint8_t *>(Buf->getBufferStart()) +
77 Sec.SectionHeader.FileOffsetToRawData;
78 Ptr = std::copy(Sec.Contents.begin(), Sec.Contents.end(), Ptr);
79 }
80
81 // Write relocations.
82 for (const Section &Sec : Obj.Sections) {
83 uint8_t *Ptr = reinterpret_cast<uint8_t *>(Buf->getBufferStart()) +
84 Sec.SectionHeader.FileOffsetToRelocationInfo;
85 for (const XCOFFRelocation32 &Rel : Sec.Relocations) {
86 memcpy(Ptr, &Rel, sizeof(XCOFFRelocation32));
87 Ptr += sizeof(XCOFFRelocation32);
88 }
89 }
90}
91
92void XCOFFWriter::writeSymbolStringTable() {
93 // Write symbols.
94 uint8_t *Ptr = reinterpret_cast<uint8_t *>(Buf->getBufferStart()) +
95 Obj.FileHeader.SymbolTableOffset;
96 for (const Symbol &Sym : Obj.Symbols) {
97 memcpy(Ptr, &Sym.Sym, XCOFF::SymbolTableEntrySize);
98 Ptr += XCOFF::SymbolTableEntrySize;
99 // Auxiliary symbols.
100 memcpy(Ptr, Sym.AuxSymbolEntries.data(), Sym.AuxSymbolEntries.size());
101 Ptr += Sym.AuxSymbolEntries.size();
102 }
103 // Write the string table.
104 memcpy(Ptr, Obj.StringTable.data(), Obj.StringTable.size());
105 Ptr += Obj.StringTable.size();
Value stored to 'Ptr' is never read
106}
107
108Error XCOFFWriter::write() {
109 finalize();
110 Buf = WritableMemoryBuffer::getNewMemBuffer(FileSize);
111 if (!Buf)
112 return createStringError(errc::not_enough_memory,
113 "failed to allocate memory buffer of " +
114 Twine::utohexstr(FileSize) + " bytes");
115
116 writeHeaders();
117 writeSections();
118 writeSymbolStringTable();
119 Out.write(Buf->getBufferStart(), Buf->getBufferSize());
120 return Error::success();
121}
122
123} // end namespace xcoff
124} // end namespace objcopy
125} // end namespace llvm