Skip to content

Commit e2363b0

Browse files
callumfarerlavaee
authored andcommitted
[NFC][Offload] Fix possible edge cases in offload-tblgen (llvm#146511)
Fix a couple of unhandled edge cases in offload-tblgen that were found by static analysis * `LineStart` may wrap around to 0 when processing multi-line strings. The value is not actually being used in that case, but still better to explicitly handle it * Possible unchecked nullptr when processing parameter flags
1 parent bfbf9c8 commit e2363b0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

offload/tools/offload-tblgen/APIGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ static std::string MakeComment(StringRef in) {
3434
}
3535
out += std::string("/// ") +
3636
in.substr(LineStart, LineBreak - LineStart).str() + "\n";
37-
LineStart = LineBreak + 1;
37+
if (LineBreak != std::string::npos)
38+
LineStart = LineBreak + 1;
3839
}
3940

4041
return out;

offload/tools/offload-tblgen/RecordTypes.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,15 @@ class ParamRec {
157157
bool isHandleType() const { return getType().ends_with("_handle_t"); }
158158
bool isFptrType() const { return getType().ends_with("_cb_t"); }
159159
StringRef getDesc() const { return rec->getValueAsString("desc"); }
160-
bool isIn() const { return dyn_cast<BitInit>(flags->getBit(0))->getValue(); }
161-
bool isOut() const { return dyn_cast<BitInit>(flags->getBit(1))->getValue(); }
162-
bool isOpt() const { return dyn_cast<BitInit>(flags->getBit(2))->getValue(); }
160+
bool getFlagBit(unsigned int Bit) const {
161+
if (auto *BitValue = dyn_cast<BitInit>(flags->getBit(Bit)))
162+
return BitValue->getValue();
163+
assert(false && "Parameter flags has no default or set value");
164+
return false;
165+
}
166+
bool isIn() const { return getFlagBit(0); }
167+
bool isOut() const { return getFlagBit(1); }
168+
bool isOpt() const { return getFlagBit(2); }
163169

164170
const Record *getRec() const { return rec; }
165171
std::optional<std::pair<StringRef, StringRef>> getRange() const {

0 commit comments

Comments
 (0)