Bug Summary

File:tools/sanstats/sanstats.cpp
Warning:line 35, column 24
The result of the '<<' expression is undefined

Annotated Source Code

1//===- sanstats.cpp - Sanitizer statistics dumper -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tool dumps statistics information from files in the format produced
11// by clang's -fsanitize-stats feature.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/DebugInfo/Symbolize/Symbolize.h"
16#include "llvm/Support/CommandLine.h"
17#include "llvm/Support/ErrorOr.h"
18#include "llvm/Support/MemoryBuffer.h"
19#include "llvm/Transforms/Utils/SanitizerStats.h"
20#include <stdint.h>
21
22using namespace llvm;
23
24static cl::opt<std::string> ClInputFile(cl::Positional, cl::Required,
25 cl::desc("<filename>"));
26
27static cl::opt<bool> ClDemangle("demangle", cl::init(false),
28 cl::desc("Print demangled function name."));
29
30inline uint64_t KindFromData(uint64_t Data, char SizeofPtr) {
31 return Data >> (SizeofPtr * 8 - kSanitizerStatKindBits);
32}
33
34inline uint64_t CountFromData(uint64_t Data, char SizeofPtr) {
35 return Data & ((1ull << (SizeofPtr * 8 - kSanitizerStatKindBits)) - 1);
30
The result of the '<<' expression is undefined
36}
37
38uint64_t ReadLE(char Size, const char *Begin, const char *End) {
39 uint64_t Result = 0;
40 char Pos = 0;
41 while (Begin < End && Pos != Size) {
42 Result |= uint64_t(uint8_t(*Begin)) << (Pos * 8);
43 ++Begin;
44 ++Pos;
45 }
46 return Result;
47}
48
49const char *ReadModule(char SizeofPtr, const char *Begin, const char *End) {
50 const char *FilenameBegin = Begin;
51 while (Begin != End && *Begin)
18
Loop condition is false. Execution continues on line 53
52 ++Begin;
53 if (Begin == End)
19
Taking false branch
54 return nullptr;
55 StringRef Filename(FilenameBegin, Begin - FilenameBegin);
56
57 ++Begin;
58 if (Begin == End)
20
Taking false branch
59 return nullptr;
60
61 symbolize::LLVMSymbolizer::Options SymbolizerOptions;
62 SymbolizerOptions.Demangle = ClDemangle;
63 SymbolizerOptions.UseSymbolTable = true;
64 symbolize::LLVMSymbolizer Symbolizer(SymbolizerOptions);
65
66 while (1) {
21
Loop condition is true. Entering loop body
67 uint64_t Addr = ReadLE(SizeofPtr, Begin, End);
68 Begin += SizeofPtr;
69 uint64_t Data = ReadLE(SizeofPtr, Begin, End);
70 Begin += SizeofPtr;
71
72 if (Begin > End)
22
Taking false branch
73 return nullptr;
74 if (Addr == 0 && Data == 0)
23
Assuming 'Data' is not equal to 0
24
Taking false branch
75 return Begin;
76 if (Begin == End)
25
Taking false branch
77 return nullptr;
78
79 if (Expected<DILineInfo> LineInfo =
26
Taking false branch
80 Symbolizer.symbolizeCode(Filename, Addr)) {
81 llvm::outs() << LineInfo->FileName << ':' << LineInfo->Line << ' '
82 << LineInfo->FunctionName << ' ';
83 } else {
84 logAllUnhandledErrors(LineInfo.takeError(), llvm::outs(), "<error> ");
85 }
86
87 switch (KindFromData(Data, SizeofPtr)) {
27
Control jumps to the 'default' case at line 103
88 case SanStat_CFI_VCall:
89 llvm::outs() << "cfi-vcall";
90 break;
91 case SanStat_CFI_NVCall:
92 llvm::outs() << "cfi-nvcall";
93 break;
94 case SanStat_CFI_DerivedCast:
95 llvm::outs() << "cfi-derived-cast";
96 break;
97 case SanStat_CFI_UnrelatedCast:
98 llvm::outs() << "cfi-unrelated-cast";
99 break;
100 case SanStat_CFI_ICall:
101 llvm::outs() << "cfi-icall";
102 break;
103 default:
104 llvm::outs() << "<unknown>";
105 break;
28
Execution continues on line 108
106 }
107
108 llvm::outs() << " " << CountFromData(Data, SizeofPtr) << '\n';
29
Calling 'CountFromData'
109 }
110}
111
112int main(int argc, char **argv) {
113 cl::ParseCommandLineOptions(argc, argv,
114 "Sanitizer Statistics Processing Tool");
115
116 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
117 MemoryBuffer::getFile(ClInputFile, -1, false);
118 if (!MBOrErr) {
1
Taking false branch
119 errs() << argv[0] << ": " << ClInputFile << ": "
120 << MBOrErr.getError().message() << '\n';
121 return 1;
122 }
123 std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
124 const char *Begin = MB->getBufferStart(), *End = MB->getBufferEnd();
125 if (Begin == End) {
2
Assuming 'Begin' is not equal to 'End'
3
Taking false branch
126 errs() << argv[0] << ": " << ClInputFile << ": short read\n";
127 return 1;
128 }
129 char SizeofPtr = *Begin++;
130 while (Begin != End) {
4
Loop condition is true. Entering loop body
7
Assuming 'Begin' is not equal to 'End'
8
Loop condition is true. Entering loop body
11
Assuming 'Begin' is not equal to 'End'
12
Loop condition is true. Entering loop body
15
Assuming 'Begin' is not equal to 'End'
16
Loop condition is true. Entering loop body
131 Begin = ReadModule(SizeofPtr, Begin, End);
17
Calling 'ReadModule'
132 if (Begin == nullptr) {
5
Assuming the condition is false
6
Taking false branch
9
Assuming the condition is false
10
Taking false branch
13
Assuming the condition is false
14
Taking false branch
133 errs() << argv[0] << ": " << ClInputFile << ": short read\n";
134 return 1;
135 }
136 assert(Begin <= End)((Begin <= End) ? static_cast<void> (0) : __assert_fail
("Begin <= End", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn303373/tools/sanstats/sanstats.cpp"
, 136, __PRETTY_FUNCTION__))
;
137 }
138}