[llvm-bugs] [Bug 41666] New: [TableGen][RISCV] RISCVCompressInstEmitter.cpp - getReqFeatures - undefined behaviour
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Apr 29 15:53:52 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41666
Bug ID: 41666
Summary: [TableGen][RISCV] RISCVCompressInstEmitter.cpp -
getReqFeatures - undefined behaviour
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: RISC-V
Assignee: unassignedbugs at nondot.org
Reporter: llvm-dev at redking.me.uk
CC: asb at lowrisc.org, llvm-bugs at lists.llvm.org,
sabuasal at codeaurora.org
Blocks: 41655
Reported in https://www.viva64.com/en/b/0629/
static void getReqFeatures(std::map<StringRef, int> &FeaturesMap,
const std::vector<Record *> &ReqFeatures) {
for (auto &R : ReqFeatures) {
StringRef AsmCondString = R->getValueAsString("AssemblerCondString");
// AsmCondString has syntax [!]F(,[!]F)*
SmallVector<StringRef, 4> Ops;
SplitString(AsmCondString, Ops, ",");
assert(!Ops.empty() && "AssemblerCondString cannot be empty");
for (auto &Op : Ops) {
assert(!Op.empty() && "Empty operator");
if (FeaturesMap.find(Op) == FeaturesMap.end())
FeaturesMap[Op] = FeaturesMap.size();
}
}
}
FeaturesMap[Op] = FeaturesMap.size();
"If the Op element hasn't been found, the program creates a new element in the
map and assigns it the total number of elements in this map. You just don't
know if the size function will be called before or after adding the new
element."
Should this be something like:
if (FeaturesMap.find(Op) == FeaturesMap.end()) {
int NumFeatures = (int)FeaturesMap.size();
FeaturesMap[Op] = NumFeatures;
}
Referenced Bugs:
https://bugs.llvm.org/show_bug.cgi?id=41655
[Bug 41655] Finding Bugs in LLVM 8 with PVS-Studio
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190429/887b9c17/attachment-0001.html>
More information about the llvm-bugs
mailing list