Skip to content

Commit 744b073

Browse files
Version 1.4.26 More design checks and error reports added
1 parent a23942d commit 744b073

File tree

7 files changed

+57
-24
lines changed

7 files changed

+57
-24
lines changed

sc_tool/lib/sc_tool/SCToolFrontendAction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ Object* getOuterArray(SCDesign& designDB, Object* memberObj)
112112
return arrayObj;
113113
}
114114

115-
const std::string SCElabASTConsumer::TOOL_VERSION = "1.4.25";
116-
const std::string SCElabASTConsumer::TOOL_DATE = "26 May,2022";
115+
const std::string SCElabASTConsumer::TOOL_VERSION = "1.4.26";
116+
const std::string SCElabASTConsumer::TOOL_DATE = "27 May,2022";
117117

118118
void SCElabASTConsumer::HandleTranslationUnit(clang::ASTContext &astCtx)
119119
{

sc_tool/lib/sc_tool/cfg/ScTraverseCommon.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ const clang::DoStmt* sc::getDoWhileTerm(AdjBlock block)
8989
bool sc::isDoWhileEmpty(const clang::DoStmt* stmt)
9090
{
9191
const Stmt* doBody = stmt->getBody();
92-
SCT_TOOL_ASSERT (doBody, "No body statement in do...while loop");
92+
if (!doBody) {
93+
SCT_INTERNAL_ERROR (stmt->getBeginLoc(),
94+
"No body statement in do...while loop");
95+
}
9396

9497
if (auto doBodyComp = dyn_cast<CompoundStmt>(doBody)) {
9598
if (doBodyComp->body_empty()) {
@@ -270,7 +273,7 @@ unsigned sc::getPredsNumber(AdjBlock block)
270273
if (auto binstmt = dyn_cast<BinaryOperator>(term) ) {
271274
BinaryOperatorKind opcode = binstmt->getOpcode();
272275
SCT_TOOL_ASSERT (opcode == BO_LOr || opcode == BO_LAnd,
273-
"Incorrect operator");
276+
"getPredsNumber : Incorrect operator");
274277
continue;
275278
}
276279
}

sc_tool/lib/sc_tool/cfg/ScTraverseConst.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ void ScTraverseConst::parseCall(CallExpr* expr, SValue& val)
398398
// Get function/method
399399
// Get function name and type
400400
FunctionDecl* funcDecl = expr->getDirectCallee();
401-
SCT_TOOL_ASSERT (funcDecl, "No function found for call expression");
401+
if (!funcDecl) {
402+
ScDiag::reportScDiag(expr->getBeginLoc(),
403+
ScDiag::SYNTH_INCORRECT_FUNC_CALL) << "---";
404+
}
405+
402406
string fname = funcDecl->getNameAsString();
403407
auto nsname = getNamespaceAsStr(funcDecl);
404408

@@ -457,8 +461,11 @@ void ScTraverseConst::parseCall(CallExpr* expr, SValue& val)
457461
cout << "-------------------------------------" << endl;
458462
}
459463

460-
SCT_TOOL_ASSERT (isUserCallExpr(expr), "Incorrect user defined function");
461-
464+
if (!isUserCallExpr(expr)) {
465+
ScDiag::reportScDiag(expr->getBeginLoc(),
466+
ScDiag::SYNTH_INCORRECT_FUNC_CALL) << fname;
467+
}
468+
462469
if (nsname && *nsname == "std") {
463470
ScDiag::reportScDiag(expr->getBeginLoc(),
464471
ScDiag::CPP_UNKNOWN_STD_FUNC) << fname;
@@ -526,15 +533,18 @@ void ScTraverseConst::parseMemberCall(CXXMemberCallExpr* expr, SValue& tval,
526533
cout << "-------------------------------------" << endl;
527534
}
528535

529-
SCT_TOOL_ASSERT (isUserCallExpr(expr), "Incorrect user defined method");
536+
if (!isUserCallExpr(expr)) {
537+
ScDiag::reportScDiag(expr->getBeginLoc(),
538+
ScDiag::SYNTH_INCORRECT_FUNC_CALL) << fname;
539+
}
530540

531541
// Get record from variable/dynamic object
532542
SValue ttval = getRecordFromState(tval, ArrayUnkwnMode::amFirstElement);
533543

534544
// Allowed parent kinds
535545
if (!ttval.isArray() && !ttval.isRecord() && !ttval.isVariable()) {
536546
ScDiag::reportScDiag(expr->getSourceRange().getBegin(),
537-
ScDiag::SYNTH_INCORRECT_RECORD);
547+
ScDiag::SYNTH_INCORRECT_RECORD) << tval << ttval;
538548
ttval = NO_VALUE;
539549
}
540550

sc_tool/lib/sc_tool/cfg/ScTraverseProc.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ void ScTraverseProc::parseCall(CallExpr* expr, SValue& val)
276276
// Get function/method
277277
// Get function name and type
278278
FunctionDecl* funcDecl = expr->getDirectCallee();
279-
SCT_TOOL_ASSERT (funcDecl, "No function found for call expression");
279+
if (!funcDecl) {
280+
ScDiag::reportScDiag(expr->getBeginLoc(),
281+
ScDiag::SYNTH_INCORRECT_FUNC_CALL) << "---";
282+
}
280283

281284
string fname = funcDecl->getNameAsString();
282285
QualType retType = funcDecl->getReturnType();
@@ -440,8 +443,8 @@ void ScTraverseProc::parseMemberCall(CXXMemberCallExpr* expr, SValue& tval,
440443

441444
// This value *this must be a kind of record
442445
if (!ttval.isRecord()) {
443-
cout << "parseMemberCall tval " << tval << ", ttval " << ttval << endl;
444-
SCT_TOOL_ASSERT (false, "This expression is not record value");
446+
ScDiag::reportScDiag(expr->getBeginLoc(),
447+
ScDiag::SYNTH_INCORRECT_RECORD) << tval << ttval;
445448
}
446449

447450
// Call with cast this object to specific class with "::",
@@ -985,8 +988,11 @@ void ScTraverseProc::run()
985988
if (i != constReplacedFunc.end()) {
986989
auto callExpr = dyn_cast<CallExpr>(i->second);
987990
auto funcDecl = callExpr->getDirectCallee();
988-
SCT_TOOL_ASSERT(funcDecl, "No function declaration found");
989-
991+
if (!funcDecl) {
992+
ScDiag::reportScDiag(callExpr->getBeginLoc(),
993+
ScDiag::SYNTH_INCORRECT_FUNC_CALL) << "---";
994+
}
995+
990996
string s = "Call of "+funcDecl->getNameAsString()+"()";
991997
scopeGraph->addComment(currStmt, s);
992998
}

sc_tool/lib/sc_tool/diag/ScToolDiagnostic.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class ScDiag {
205205
SYNTH_LITER_OVERFLOW = 233,
206206
SYNTH_RECORD_CTOR_NONEMPTY = 234,
207207
CPP_DEFINED_LOCAL_PARAM = 235,
208+
SYNTH_INCORRECT_FUNC_CALL = 236,
208209

209210
SC_FATAL_ELAB_TYPES_NS = 300,
210211
SC_WARN_ELAB_UNSUPPORTED_TYPE,
@@ -512,7 +513,7 @@ class ScDiag {
512513

513514
idFormatMap[SYNTH_INCORRECT_RECORD] =
514515
{clang::DiagnosticIDs::Error,
515-
"No record object found for member call (not sc_interface inheritor or not statically determined)"};
516+
"No record object found for member call : %0 %1"};
516517

517518
idFormatMap[SYNTH_NONTRIVIAL_COPY] =
518519
{clang::DiagnosticIDs::Fatal,
@@ -718,6 +719,9 @@ class ScDiag {
718719
{clang::DiagnosticIDs::Error,
719720
"Member variable used before initialization (re-defined localparam) : %0"};
720721

722+
idFormatMap[SYNTH_INCORRECT_FUNC_CALL] =
723+
{clang::DiagnosticIDs::Error,
724+
"Incorrect user defined method or function : %0"};
721725

722726
// Elaboration
723727
idFormatMap[SC_FATAL_ELAB_TYPES_NS] =

sc_tool/lib/sc_tool/expr/ScParseExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,8 @@ void ScParseExpr::parseExpr(clang::MemberExpr* expr, SValue& val)
913913

914914
// Allowed parent kinds
915915
if (!ttval.isArray() && !ttval.isRecord() && !ttval.isVariable()) {
916-
ScDiag::reportScDiag(expr->getBeginLoc(), ScDiag::SYNTH_INCORRECT_RECORD);
916+
ScDiag::reportScDiag(expr->getBeginLoc(),
917+
ScDiag::SYNTH_INCORRECT_RECORD) << tval << ttval;
917918
}
918919

919920
ValueDecl* decl = expr->getMemberDecl();

sc_tool/lib/sc_tool/expr/ScParseExprValue.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void ScParseExprValue::parseExpr(CXXConstructExpr* expr, SValue& val)
662662
<< expr->getType();
663663
}
664664
} else {
665-
SCT_TOOL_ASSERT (false, "Unexpected argument number");
665+
SCT_INTERNAL_ERROR (expr->getBeginLoc(), "Unexpected argument number");
666666
}
667667

668668
// Create SC type single object value
@@ -965,7 +965,10 @@ void ScParseExprValue::parseImplExplCast(CastExpr* expr, SValue& rval,
965965
if (val.isInteger()) {
966966
QualType type = expr->getType();
967967
auto typeInfo = getIntTraits(type, true);
968-
SCT_TOOL_ASSERT (typeInfo, "No integral type width extracted");
968+
if (!typeInfo) {
969+
SCT_INTERNAL_ERROR (expr->getBeginLoc(),
970+
"No integral type width extracted");
971+
}
969972
size_t width = typeInfo.getValue().first;
970973
bool isUnsigned = typeInfo.getValue().second;
971974

@@ -1011,9 +1014,8 @@ void ScParseExprValue::parseExpr(ExplicitCastExpr* expr, SValue& rval, SValue& v
10111014
ScDiag::SYNTH_LVALUE_BIT_CAST);
10121015
} else {
10131016
cout << "Cast kind " << expr->getCastKindName(castKind) << endl;
1014-
expr->getBeginLoc().dump(sm);
1015-
expr->dumpColor();
1016-
SCT_TOOL_ASSERT (false, "Unsupported cast kind in ExplicitCastExpr");
1017+
SCT_INTERNAL_ERROR (expr->getBeginLoc(),
1018+
"Unsupported cast kind in ExplicitCastExpr");
10171019
}
10181020
}
10191021
} else
@@ -1579,6 +1581,7 @@ void ScParseExprValue::parseCompoundAssignStmt(CompoundAssignOperator* stmt,
15791581
if (opcode == BO_XorAssign) {
15801582
res = val1 ^ val2;
15811583
} else {
1584+
cout << "Opcode " << opcode << endl;
15821585
SCT_TOOL_ASSERT (false, "parseCompAssign : Unknown integer opcode");
15831586
}
15841587

@@ -2206,7 +2209,7 @@ void ScParseExprValue::parseMemberCall(CXXMemberCallExpr* callExpr, SValue& tval
22062209
val = ttval;
22072210

22082211
} else {
2209-
SCT_TOOL_ASSERT (false, "Unknown cast");
2212+
SCT_INTERNAL_ERROR (callExpr->getBeginLoc(), "Unknown cast");
22102213
}
22112214
}
22122215
} else
@@ -2279,7 +2282,10 @@ void ScParseExprValue::parseMemberCall(CXXMemberCallExpr* callExpr, SValue& tval
22792282
if (val.isInteger()) {
22802283
QualType type = callExpr->getType();
22812284
auto typeInfo = getIntTraits(type, true);
2282-
SCT_TOOL_ASSERT (typeInfo, "No integral type width extracted");
2285+
if (!typeInfo) {
2286+
SCT_INTERNAL_ERROR (callExpr->getBeginLoc(),
2287+
"No integral type width extracted");
2288+
}
22832289
size_t width = typeInfo.getValue().first;
22842290
bool isUnsigned = typeInfo.getValue().second;
22852291

@@ -2714,6 +2720,7 @@ void ScParseExprValue::parseOperatorCall(CXXOperatorCallExpr* expr, SValue& val)
27142720
if (opcode == OO_Pipe) {
27152721
res = val1 | val2;
27162722
} else {
2723+
cout << "Opcode " << opcode << endl;
27172724
SCT_TOOL_ASSERT (false, "Unknown opcode for SC type operator");
27182725
}
27192726

@@ -2833,6 +2840,7 @@ void ScParseExprValue::parseOperatorCall(CXXOperatorCallExpr* expr, SValue& val)
28332840
if (opcode == OO_CaretEqual) {
28342841
res = val1 ^ val2;
28352842
} else {
2843+
cout << "Opcode " << opcode << endl;
28362844
SCT_TOOL_ASSERT (false, "Unknown opcode for SC type operator");
28372845
}
28382846

@@ -2915,7 +2923,8 @@ void ScParseExprValue::parseReturnStmt(ReturnStmt* stmt, SValue& val)
29152923
if (returnValue.isUnknown()) {
29162924
// Do nothing
29172925
} else {
2918-
SCT_TOOL_ASSERT (false, "Unexpected kind of return variable value");
2926+
SCT_INTERNAL_ERROR (stmt->getBeginLoc(),
2927+
"Unexpected kind of return variable value");
29192928
}
29202929

29212930
if (returnStmtFunc) {

0 commit comments

Comments
 (0)