Bug Summary

File:build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.cpp
Warning:line 193, column 37
The result of the left shift is undefined due to shifting by '32', which is greater or equal to the width of type 'uint32_t'

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 PPCMachineFunctionInfo.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/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/Target/PowerPC -I /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/llvm/lib/Target/PowerPC -I include -I /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/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-16/lib/clang/16.0.0/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/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -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/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -ferror-limit 19 -fvisibility=hidden -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-2022-10-03-140002-15933-1 -x c++ /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.cpp
1//===-- PPCMachineFunctionInfo.cpp - Private data used for PowerPC --------===//
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 "PPCMachineFunctionInfo.h"
10#include "llvm/ADT/Twine.h"
11#include "llvm/BinaryFormat/XCOFF.h"
12#include "llvm/IR/DataLayout.h"
13#include "llvm/MC/MCContext.h"
14#include "llvm/Support/CommandLine.h"
15
16using namespace llvm;
17static cl::opt<bool> PPCDisableNonVolatileCR(
18 "ppc-disable-non-volatile-cr",
19 cl::desc("Disable the use of non-volatile CR register fields"),
20 cl::init(false), cl::Hidden);
21
22void PPCFunctionInfo::anchor() {}
23PPCFunctionInfo::PPCFunctionInfo(const MachineFunction &MF)
24 : DisableNonVolatileCR(PPCDisableNonVolatileCR) {}
25
26MachineFunctionInfo *
27PPCFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
28 const DenseMap<MachineBasicBlock *, MachineBasicBlock *>
29 &Src2DstMBB) const {
30 return DestMF.cloneInfo<PPCFunctionInfo>(*this);
31}
32
33MCSymbol *PPCFunctionInfo::getPICOffsetSymbol(MachineFunction &MF) const {
34 const DataLayout &DL = MF.getDataLayout();
35 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
36 Twine(MF.getFunctionNumber()) +
37 "$poff");
38}
39
40MCSymbol *PPCFunctionInfo::getGlobalEPSymbol(MachineFunction &MF) const {
41 const DataLayout &DL = MF.getDataLayout();
42 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
43 "func_gep" +
44 Twine(MF.getFunctionNumber()));
45}
46
47MCSymbol *PPCFunctionInfo::getLocalEPSymbol(MachineFunction &MF) const {
48 const DataLayout &DL = MF.getDataLayout();
49 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
50 "func_lep" +
51 Twine(MF.getFunctionNumber()));
52}
53
54MCSymbol *PPCFunctionInfo::getTOCOffsetSymbol(MachineFunction &MF) const {
55 const DataLayout &DL = MF.getDataLayout();
56 return MF.getContext().getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
57 "func_toc" +
58 Twine(MF.getFunctionNumber()));
59}
60
61bool PPCFunctionInfo::isLiveInSExt(Register VReg) const {
62 for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
63 if (LiveIn.first == VReg)
64 return LiveIn.second.isSExt();
65 return false;
66}
67
68bool PPCFunctionInfo::isLiveInZExt(Register VReg) const {
69 for (const std::pair<Register, ISD::ArgFlagsTy> &LiveIn : LiveInAttrs)
70 if (LiveIn.first == VReg)
71 return LiveIn.second.isZExt();
72 return false;
73}
74
75void PPCFunctionInfo::appendParameterType(ParamType Type) {
76
77 ParamtersType.push_back(Type);
78 switch (Type) {
79 case FixedType:
80 ++FixedParmsNum;
81 return;
82 case ShortFloatingPoint:
83 case LongFloatingPoint:
84 ++FloatingParmsNum;
85 return;
86 case VectorChar:
87 case VectorShort:
88 case VectorInt:
89 case VectorFloat:
90 ++VectorParmsNum;
91 return;
92 }
93 llvm_unreachable("Error ParamType type.")::llvm::llvm_unreachable_internal("Error ParamType type.", "llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.cpp"
, 93)
;
94}
95
96uint32_t PPCFunctionInfo::getVecExtParmsType() const {
97
98 uint32_t VectExtParamInfo = 0;
99 unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
100 int Bits = 0;
101
102 if (!hasVectorParms())
103 return 0;
104
105 for (const auto &Elt : ParamtersType) {
106 switch (Elt) {
107 case VectorChar:
108 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
109 VectExtParamInfo |=
110 XCOFF::TracebackTable::ParmTypeIsVectorCharBit >> ShiftBits;
111 Bits += XCOFF::TracebackTable::WidthOfParamType;
112 break;
113 case VectorShort:
114 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
115 VectExtParamInfo |=
116 XCOFF::TracebackTable::ParmTypeIsVectorShortBit >> ShiftBits;
117 Bits += XCOFF::TracebackTable::WidthOfParamType;
118 break;
119 case VectorInt:
120 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
121 VectExtParamInfo |=
122 XCOFF::TracebackTable::ParmTypeIsVectorIntBit >> ShiftBits;
123 Bits += XCOFF::TracebackTable::WidthOfParamType;
124 break;
125 case VectorFloat:
126 VectExtParamInfo <<= XCOFF::TracebackTable::WidthOfParamType;
127 VectExtParamInfo |=
128 XCOFF::TracebackTable::ParmTypeIsVectorFloatBit >> ShiftBits;
129 Bits += XCOFF::TracebackTable::WidthOfParamType;
130 break;
131 default:
132 break;
133 }
134
135 // There are only 32bits in the VectExtParamInfo.
136 if (Bits >= 32)
137 break;
138 }
139 return Bits < 32 ? VectExtParamInfo << (32 - Bits) : VectExtParamInfo;
140}
141
142uint32_t PPCFunctionInfo::getParmsType() const {
143 uint32_t ParamsTypeInfo = 0;
144 unsigned ShiftBits = 32 - XCOFF::TracebackTable::WidthOfParamType;
145
146 int Bits = 0;
147 for (const auto &Elt : ParamtersType) {
1
Assuming '__begin1' is equal to '__end1'
148
149 if (Bits > 31 || (Bits > 30 && (Elt != FixedType || hasVectorParms())))
150 break;
151
152 switch (Elt) {
153 case FixedType:
154 if (hasVectorParms()) {
155 //'00' ==> fixed parameter if HasVectorParms is true.
156 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
157 ParamsTypeInfo |=
158 XCOFF::TracebackTable::ParmTypeIsFixedBits >> ShiftBits;
159 Bits += XCOFF::TracebackTable::WidthOfParamType;
160 } else {
161 //'0' ==> fixed parameter if HasVectorParms is false.
162 ParamsTypeInfo <<= 1;
163 ++Bits;
164 }
165 break;
166 case ShortFloatingPoint:
167 // '10'b => floating point short parameter.
168 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
169 ParamsTypeInfo |=
170 XCOFF::TracebackTable::ParmTypeIsFloatingBits >> ShiftBits;
171 Bits += XCOFF::TracebackTable::WidthOfParamType;
172 break;
173 case LongFloatingPoint:
174 // '11'b => floating point long parameter.
175 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
176 ParamsTypeInfo |=
177 XCOFF::TracebackTable::ParmTypeIsDoubleBits >> ShiftBits;
178 Bits += XCOFF::TracebackTable::WidthOfParamType;
179 break;
180 case VectorChar:
181 case VectorShort:
182 case VectorInt:
183 case VectorFloat:
184 // '01' ==> vector parameter
185 ParamsTypeInfo <<= XCOFF::TracebackTable::WidthOfParamType;
186 ParamsTypeInfo |=
187 XCOFF::TracebackTable::ParmTypeIsVectorBits >> ShiftBits;
188 Bits += XCOFF::TracebackTable::WidthOfParamType;
189 break;
190 }
191 }
192
193 return Bits
1.1
'Bits' is < 32
< 32 ? ParamsTypeInfo << (32 - Bits) : ParamsTypeInfo;
2
'?' condition is true
3
The result of the left shift is undefined due to shifting by '32', which is greater or equal to the width of type 'uint32_t'
194}