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: unassignedb...@nondot.org
          Reporter: llvm-...@redking.me.uk
                CC: a...@lowrisc.org, llvm-bugs@lists.llvm.org,
                    sabua...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to