virtual PathGenerationScheme getGenerationScheme() const { return Minimal; }
virtual bool supportsLogicalOpControlFlow() const { return false; }
virtual bool supportsAllBlockEdges() const { return false; }
+ virtual bool useVerboseDescription() const { return true; }
};
//===----------------------------------------------------------------------===//
class BugReport {
protected:
BugType& BT;
+ std::string ShortDescription;
std::string Description;
const ExplodedNode<GRState> *EndNode;
SourceRange R;
BugReport(BugType& bt, const char* desc, const ExplodedNode<GRState> *n)
: BT(bt), Description(desc), EndNode(n) {}
+
+ BugReport(BugType& bt, const char* shortDesc, const char* desc,
+ const ExplodedNode<GRState> *n)
+ : BT(bt), ShortDescription(shortDesc), Description(desc), EndNode(n) {}
+
virtual ~BugReport();
Stmt* getStmt(BugReporter& BR) const;
const std::string& getDescription() const { return Description; }
+
+ const std::string& getShortDescription() const {
+ return ShortDescription.empty() ? Description : ShortDescription;
+ }
// FIXME: Is this needed?
virtual std::pair<const char**,const char**> getExtraDescriptiveText() {
RangedBugReport(BugType& D, const char* description, ExplodedNode<GRState> *n)
: BugReport(D, description, n) {}
+ RangedBugReport(BugType& D, const char *shortDescription,
+ const char *description, ExplodedNode<GRState> *n)
+ : BugReport(D, shortDescription, description, n) {}
+
~RangedBugReport();
// FIXME: Move this out of line.
void BugReporter::FlushReport(BugReportEquivClass& EQ) {
assert(!EQ.Reports.empty());
BugReport &R = **EQ.begin();
+ PathDiagnosticClient* PD = getPathDiagnosticClient();
// FIXME: Make sure we use the 'R' for the path that was actually used.
// Probably doesn't make a difference in practice.
BugType& BT = R.getBugType();
- llvm::OwningPtr<PathDiagnostic> D(new PathDiagnostic(R.getBugType().getName(),
- R.getDescription(),
- BT.getCategory()));
+ llvm::OwningPtr<PathDiagnostic>
+ D(new PathDiagnostic(R.getBugType().getName(),
+ PD->useVerboseDescription()
+ ? R.getDescription() : R.getShortDescription(),
+ BT.getCategory()));
+
GeneratePathDiagnostic(*D.get(), EQ);
// Get the meta data.
for (const char** s = Meta.first; s != Meta.second; ++s) D->addMeta(*s);
// Emit a summary diagnostic to the regular Diagnostics engine.
- PathDiagnosticClient* PD = getPathDiagnosticClient();
const SourceRange *Beg = 0, *End = 0;
R.getRanges(*this, Beg, End);
Diagnostic& Diag = getDiagnostic();
"variable-length array (VLA) '"
<< VD->getNameAsString() << "' evaluates to ";
- if (Eng.getStateManager().GetSVal(N->getState(), SizeExpr).isUndef())
+ bool isUndefined = Eng.getStateManager().GetSVal(N->getState(),
+ SizeExpr).isUndef();
+
+ if (isUndefined)
os << "an undefined or garbage value.";
else
os << "0. VLAs with no elements have undefined behavior.";
-
- RangedBugReport *report = new RangedBugReport(*this, os.str().c_str(), N);
+
+ std::string shortBuf;
+ llvm::raw_string_ostream os_short(shortBuf);
+ os_short << "Variable-length array '" << VD->getNameAsString() << "' "
+ << (isUndefined ? " garbage value for array size"
+ : " has zero elements (undefined behavior)");
+
+ RangedBugReport *report = new RangedBugReport(*this,
+ os_short.str().c_str(),
+ os.str().c_str(), N);
report->addRange(SizeExpr->getSourceRange());
BR.EmitReport(report);
}
PathGenerationScheme getGenerationScheme() const { return Extensive; }
bool supportsLogicalOpControlFlow() const { return true; }
bool supportsAllBlockEdges() const { return true; }
+ virtual bool useVerboseDescription() const { return false; }
};
} // end anonymous namespace