@@ -363,36 +363,50 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
363363 supprlist.addSuppression (std::move (s));
364364 }
365365
366- const auto reportErrorsFn = [&](const std::string& sourcefile, std::size_t fsFileId, const std::vector<ErrorMessage>& errors) -> bool {
366+ const auto getCfgs = [&](const std::string &sourcefile) {
367+ std::vector<std::string> cfgs;
368+ for (const FileSettings &fs : fileSettings) {
369+ if (fs.file .spath () == Path::simplifyPath (sourcefile))
370+ cfgs.push_back (fs.cfg );
371+ }
372+ if (cfgs.empty ())
373+ cfgs.emplace_back ();
374+ return cfgs;
375+ };
376+
377+ const auto reportErrorsFn = [&](const std::string &sourcefile, const std::vector<std::string> &cfgs, std::size_t fsFileId, const std::vector<ErrorMessage> &errors) -> bool {
367378 if (errors.empty ())
368379 return false ;
369380
370381 // TODO: what if sourcefile is empty?
371382
372- AnalyzerInformation analyzerInfo;
373- // FIXME: this is a horrible hack
374- // we need to "re-open" the file so we can add the unmatchedSuppression findings.
375- // we cannot keep it open conditionally because the whole program analysis reads the XML.
376- // re-ordering the code is also not an option because the unmatched suppression reporting needs to be run after all other checks.
377- analyzerInfo.reopen (settings.buildDir , sourcefile, /* cfgname*/ " " , fsFileId);
383+ for (const std::string &cfg : cfgs) {
384+ AnalyzerInformation analyzerInfo;
385+ // FIXME: this is a horrible hack
386+ // we need to "re-open" the file so we can add the unmatchedSuppression findings.
387+ // we cannot keep it open conditionally because the whole program analysis reads the XML.
388+ // re-ordering the code is also not an option because the unmatched suppression reporting needs to be run after all other checks.
389+ analyzerInfo.reopen (settings.buildDir , sourcefile, cfg, fsFileId);
378390
379- for (const auto & errmsg : errors) {
380- analyzerInfo.reportErr (errmsg);
381- errorLogger.reportErr (errmsg);
391+ for (const auto &errmsg : errors)
392+ analyzerInfo.reportErr (errmsg);
382393 }
394+
395+ for (const auto &errmsg : errors)
396+ errorLogger.reportErr (errmsg);
383397 return true ;
384398 };
385399
386400 bool err = false ;
387401
388402 for (auto i = files.cbegin (); i != files.cend (); ++i) {
389403 const std::vector<ErrorMessage> errors = getUnmatchedSuppressions (supprlist.getUnmatchedLocalSuppressions (*i), settings.unmatchedSuppressionFilters );
390- err |= reportErrorsFn (i->spath (), i->fsFileId (), errors);
404+ err |= reportErrorsFn (i->spath (), { " " }, i->fsFileId (), errors);
391405 }
392406
393407 for (auto i = fileSettings.cbegin (); i != fileSettings.cend (); ++i) {
394408 const std::vector<ErrorMessage> errors = getUnmatchedSuppressions (supprlist.getUnmatchedLocalSuppressions (i->file ), settings.unmatchedSuppressionFilters );
395- err |= reportErrorsFn (i->file .spath (), i->file .fsFileId (), errors);
409+ err |= reportErrorsFn (i->file .spath (), {i-> cfg }, i->file .fsFileId (), errors);
396410 }
397411
398412 if (settings.inlineSuppressions ) {
@@ -401,7 +415,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
401415 std::string sourcefile;
402416 if (!errmsg.callStack .empty ())
403417 sourcefile = errmsg.callStack .cbegin ()->getfile (false ); // TODO: simplify path?
404- err |= reportErrorsFn (sourcefile, 0 , {errmsg});
418+ err |= reportErrorsFn (sourcefile, getCfgs (sourcefile), 0 , {errmsg});
405419 }
406420 }
407421
@@ -410,7 +424,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
410424 std::string sourcefile;
411425 if (!errmsg.callStack .empty ())
412426 sourcefile = errmsg.callStack .cbegin ()->getfile (false ); // TODO: simplify path?
413- err |= reportErrorsFn (sourcefile, 0 , {errmsg});
427+ err |= reportErrorsFn (sourcefile, getCfgs (sourcefile), 0 , {errmsg});
414428 }
415429 return err;
416430}
@@ -750,4 +764,3 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
750764#endif
751765 return res;
752766}
753-
0 commit comments