Skip to content

[refactor] Rework analyzer labeling - #5127

Merged
bruntib merged 2 commits into
Ericsson:masterfrom
gulyasgergely902:rework-analyzer-labeling
Nov 25, 2026
Merged

bruntib merged 2 commits into
Ericsson:masterfrom
gulyasgergely902:rework-analyzer-labeling

Conversation

@gulyasgergely902

@gulyasgergely902 gulyasgergely902 commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

fixes CODECHKR-7068

This change reworks how checker labels are working inside CodeChecker.

The guideline files are now separated from the rules. Each type of rule (CWE, Sei-Cert, OWASP, etc.) have a separate file collecting all the rules the given type has. Every rule has its ID and optionally its title and URL. The guideline files are now only serves as a collection of rule IDs.

Label files also got reworked: containing less data for any given checker, guideline definitions are discarded and now derived from the rule ID based on which guideline contains the given rule. Every rule is now added by rule:<rule_name>. Profiles are also reworked, the generic profiles (default, sensitive and extreme) are now contained in eachother meaning only the smallest set must be defined and the checker will automatically be in every broader set. E.g. if a checker must be in sensitive and extreme, only sensitive has to be defined, it will be in extreme automatically.

This change was made to prevent user mistakes when editing labelling, guidelines or rules. Every component (rules, guidelines, labels) has its own source of truth now which makes easier the further development.

@gulyasgergely902 gulyasgergely902 added this to the release 6.30.0 milestone Oct 5, 2026
@gulyasgergely902
gulyasgergely902 force-pushed the rework-analyzer-labeling branch 4 times, most recently from dc342dd to 57bad77 Compare October 7, 2026 09:41

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the failing test cases.

@gulyasgergely902
gulyasgergely902 force-pushed the rework-analyzer-labeling branch 6 times, most recently from 89eeb14 to d309a0b Compare October 14, 2026 08:34

@barnabasdomozi barnabasdomozi left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention all the breaking changes in the commit message.
As an example:

CodeChecker analyze ./compile_commands.json -e sei-cert-c:str34-c -o ./report_dir

worked before this patch but now it throws an error:

The sei-cert-c namespace is not known. Please selectone of these existing namespace options: checker, prefix, label-tool-skip, severity, guideline, doc_url, blacklist, rule, profile, description.

Additionally, update docs/analyzer/user_guide.md which still references the old way of working.

It would also be useful to add documentation about how label, guideline and rule files relate to each other, and also what each file contains.

Comment thread codechecker_common/guidelines.py Outdated
return dict(self.__rule_details.get(
rule_id, {"title": "", "rule_url": ""}))

def guideline_titles(self) -> dict[str, str]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this guideline_titles function is not used anywhere. Why was it added?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to do something with my git, I've accidentally left in functions and parts that are not needed. Thanks for the heads up, removed them.

Comment thread codechecker_common/guidelines.py Outdated
return {name: meta.get("title", "")
for name, meta in self.__guideline_meta.items()}

def guideline_urls(self) -> dict[str, str]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guideline_urls function is also not used anywhere. Why was it implemented?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as with guideline_titles.

Comment thread codechecker_common/guidelines.py Outdated
for name, meta in self.__guideline_meta.items()}

return guideline_rules
def all_guidelines(self) -> Iterable[str]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function returns a list, why does it have a return type of Iterable? Several places where this function is called, the return value is converted to a list anyway e.g.:

  • analyzer/codechecker_analyzer/cli/checkers.py, line 206
  • codechecker_common/checker_labels.py line 409

Seems like unnecessary type conversions to me.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Comment thread codechecker_common/guidelines.py Outdated
"""
guideline_files = map(
lambda f: os.path.join(guidelines_dir, f),
filter(lambda f: f.endswith('.yaml') or f.endswith('.yml'),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All YAML files in the repository have extension .yaml. I think we should have a standard file extension for guidelines and not allow ones that have a .yml extension for some odd reason.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no difference between the two extensions. If we agree on using one over the other, we can make it, so it only accepts that.

Comment thread codechecker_common/guidelines.py Outdated
if rule_id in self.__rule_details:
return dict(self.__rule_details[rule_id])

return {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a raw dictionary when returning structured data is prone to errors and harder to reason about. Consider using a dataclass instead.

Comment thread codechecker_common/guidelines.py Outdated
Return the rules of a guideline as a mapping from rule id to its
details (title, url).
"""
return self.__all_rules[guideline_name]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does not check whether guideline_name is in the dictionary. Since self.__all_rules is a defaultdict, non-existing keys could be inserted to it.

This is especially concerning because the server calls this from getGuidelineRules, therefore, clients can insert arbitrary keys to this dictionary using the Thrift API.

My suggestion is to NOT use defaultdict for self.__all_rules to avoid bugs like this in the future.

Comment thread codechecker_common/guidelines.py Outdated
guideline_files: Iterable[str]
) -> defaultdict[str, dict[str, dict[str, str]]]:
guidelines_dir: str
) -> tuple[defaultdict[str, dict[str, dict[str, str]]],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use typed dataclasses as I mentioned before for structured data.
The return type actually shows how hard this is to follow right now: tuple[defaultdict[str, dict[str, dict[str, str]]], dict[str, dict[str, str]]]

return args.guideline
# "<guideline>:<rule>" form -> query by the rule only, since the guideline
# is derived from the rule in memory.
_, rule = args.guideline.split(':', 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, dropping the guideline part means two things:

  • we are NOT checking whether the specified guideline exists
  • we are NOT checking if the rule is actually part of the guideline

Is that intentional?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not intentional; I forgot to add the checks to check either the guideline existence or if the rule actually in the given one.

@gulyasgergely902
gulyasgergely902 force-pushed the rework-analyzer-labeling branch 5 times, most recently from 6f00765 to 6b6fc34 Compare October 22, 2026 12:38

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it seems there are still backward compatibility issues:

  • checkers --label <guideline:rule> not working
    Example:
    CodeChecker checkers --label sei-cert-c:str34-c

    In previous version:

    bugprone-signed-char-misuse
      Status: enabled
      Analyzer: clang-tidy
    ...
    

    Now:

    [INFO 2026-10-26 16:40:26] - No checkers with the given label found.
    
  • checkers --details missing <guideline:rule> labels and also some profiles
    Example:
    CodeChecker checkers --details | grep -FA 25 "unix.cstring.NullArg"

    Previously:

    unix.cstring.NullArg
      Status: enabled
      Analyzer: clangsa
      Description: Check for null pointers being passed as arguments to C string functions
      Labels:
        cwe-top-25-2024:cwe-476
        cwe-top-25-2025:cwe-476
        cwe-vulnerabilities:cwe-476
        doc_url:https://clang.llvm.org/docs/analyzer/checkers.html#unix-cstring-nullarg-c
        guideline:cwe-top-25-2024
        guideline:cwe-top-25-2025
        guideline:cwe-vulnerabilities
        guideline:memory-safety
        guideline:sei-cert-c
        guideline:sei-cert-cpp
        memory-safety:cwe-476
        profile:default
        profile:extreme
        profile:security
        profile:sensitive
        sei-cert-c:exp34-c
        sei-cert-cpp:exp34-c
        severity:HIGH
    

    Now:

    unix.cstring.NullArg
      Status: enabled
      Analyzer: clangsa
      Description: Check for null pointers being passed as arguments to C string functions
      Labels:
        doc_url:https://clang.llvm.org/docs/analyzer/checkers.html#unix-cstring-nullarg-c
        guideline:cwe-top-25-2024
        guideline:cwe-top-25-2025
        guideline:cwe-vulnerabilities
        guideline:memory-safety
        guideline:sei-cert-c
        guideline:sei-cert-cpp
        profile:default
        profile:security
        rule:cwe-476
        rule:exp34-c
        severity:HIGH
    

    Now, it no longer lists labels:

    • sei-cert-c:exp34-c
    • sei-cert-cpp:exp34-c
    • memory-safety:cwe-476
    • etc.
    • profile:extreme
    • profile:sensitive

url=rules[rule].rule_url,
checkers=checkers,
level=rules[rule].get("level", "")
level=""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why level is now always returned as an empty string?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Level is a not used field currently for rules. The real question here is are we going to use it in the future? If not then the whole level field could be removed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the level field is still used in web GUI: src/components/Statistics/Guideline/GuidelineStatistics.vue, lines 247 and 318 but I'm not sure why.
It can be worth a look why it is still used there.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the idea was behind this level parameter. How about this: I restore the mentioned line above to get the actual variable instead of setting it to an empty string and then we could go after it to check what the original intention was with it.

# may belong to multiple guidelines.
guideline_rule_map: dict = {}
if all_guideline_names:
guideline_rules = client.getGuidelineRules([

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the server now also sends the <guideline>:<rule> labels, modifying the client-side code should not be necessary. Moreover, this new implementation now has an extra API call: client.getGuidelineRules().

# was not part of the released API. It is excluded here so the
# returned set stays byte-for-byte compatible with older clients;
# it is still used below to derive the legacy guideline labels.
checker_labels_set = {f'{key}:{value}' for key, value in pairs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these pieces of backward incompatible fixes should belong to the CheckerLabels class, not to the report server implementation.

# getCheckerLabels keeps its output compatible with older clients: the
# internal "rule" labels are excluded, while the legacy transitive
# profile tiers and "<guideline>:<rule>" labels are reconstructed.
div_zero_labels = {f'{key}:{value}' for key, value in label_pairs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this code is the copy of what is written in the report server class. In test files, the original implementation being tested should be imported and not copy pasted.
This also relates to my other point, that this code should be moved out from the report server class.

Comment thread codechecker_common/checker_labels.py Outdated

return expanded

def __derived_guidelines(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems only __augment_labels calls this __derived_guidelines function.
I think these two could be merged, that would make the code more easier to read.

dkrupp
dkrupp previously requested changes Oct 26, 2026

@dkrupp dkrupp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, this change looks very good.

I have just a few minor comments.

I cross-tested this PR with the 6.29.0 version by querying the checkers for the default, sensitive profiles, sei-cert-c guidelines and various label queries and all seem to return similar results. Also tested "CodeChecker analyze" with profile/guideline selection. Looks like that it selects the correct checkers.

Comment thread config/rules/sei-cert-rules.yaml Outdated
title: ''
rule_url: https://cmu-sei.github.io/secure-coding-standards/sei-cert-cpp-coding-standard/rules/miscellaneous-msc/msc53-cpp/
- rule_id: msc54-cpp
title: A signal handler must be a plain old function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the title from sei-cert rules for consistency and for copyright reasons.


# Collect the guidelines that appear for the queried checkers. A checker's
# guidelines are derived on the server from its "rule:<rule_id>" labels.
all_guideline_names = set()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the checker coverage command line query work wit the new server and old clients. In other words, is the change backward compatible with old clients?

@gulyasgergely902 gulyasgergely902 Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is yet to be tested but since the output has not changed, it should be. I've tested the new server with old client (released 6.29.0) and it worked.

@gulyasgergely902
gulyasgergely902 force-pushed the rework-analyzer-labeling branch 4 times, most recently from e48ac25 to 8b8d029 Compare October 28, 2026 12:51

@bruntib bruntib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvement, it really makes the "database" of checker labels much more maintainable.

However, I have a few comments. Almost all of these comments want to express that the public interface of CheckerLabels class shouldn't change, and this should be the single source of all label information. I don't think, it's a good approach that implicit information is introduced, like the invisible "rule" label. The goal of the CheckerLabels class is that the client code doesn't have to have any extra knowledge about the implementation details of guideline handling. How should I decide whether I need to use labels_of_checker() or visible_labels_of_checker()?

Comment thread codechecker_common/guidelines.py Outdated
@dataclass
class Guideline:
"""A named grouping of rules, mapping rule id to its Rule descriptor."""
guideline_id: str

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would follow a naming convention where the member names don't contain the class name:

guideline = Guideline()

guideline.guideline_id
# vs
guideline.id

This comment applies to Rule.rule_id and Rule.rule_url, too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can accept this, renamed them to only be id, url.

Comment on lines +216 to +218
guidelines = analyzer_context.get_context().guideline
if identifier_namespace in guidelines.all_guidelines():
identifier_namespace = "rule"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume, this section is here because of --guideline <guideline>:<rule> flag. But how can this format reach this point? The --guideline flag should be transformed to the equivalent --label <guideline>:<rule> at an earlier stage.


A guideline is derived in memory from the "rule:<rule_id>" labels of a
checker, so a whole-guideline query is expressed as a "guideline:<name>"
label and a single-rule query as a "rule:<rule_id>" label.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier we didn't have a rule:<rule_id> label. Why do we introduce it instead of <guideline>:<rule_id>? I think, this PR shouldn't change the current behavior.


return result

def profiles_containing(self, profile: str) -> list[str]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a private function.
Note: Neither this function nor __expand_query_profiles() handle transitivity of the "contains" relation. We need to remember that if a new profile is added that contains a previous profile, then its transitively contained profiles have to be added to the config file, too. Do we want to enforce it with a test case? Or should it be possible to add a new profile that contains "sensitive", but doesn't contain "default"?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to create a test case. This current solution makes it easier in terms of code simplicity. And yes, it is also possible this way to add a profile which only contains parts of the current ones.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither this function nor __expand_query_profiles() handle transitivity of the "contains" relation. We need to remember that if a new profile is added that contains a previous profile, then its transitively contained profiles have to be added to the config file, too.

I think we should prefer simpler implementation instead of resolving the transitivity in code.
Also, we rarely introduce new profiles and it's as easy as editing a few fields in description.json:

 "profile-containment": {
    "extreme": [
      "sensitive",
      "default"
    ],
    "sensitive": [
      "default"
    ]
  }

So the current design looks fine to me.

Comment thread codechecker_common/checker_labels.py Outdated

return expanded

def __augment_labels(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that rule shouldn't be introduced as a key. If we have labels in the form <guideline>:<rule_id>, then this function is not necessary.

Comment thread codechecker_common/checker_labels.py Outdated
"""
# Guidelines are derived from rules, so their values come from the
# Guidelines object rather than from raw labels.
if label == 'guideline' and self.__guidelines is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.__guidelines shouldn't be optional.

rows = list(map(lambda x: (x,), cl.labels()))
# Present each guideline name as a label and hide the internal "rule"
# label, matching the released output.
guidelines = analyzer_context.get_context().guideline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the CheckerLabels should be the single source of truth.


rows = list(map(lambda x: (x,), cl.occurring_values(args.label)))
# A guideline name as the label lists its rule ids.
guidelines = analyzer_context.get_context().guideline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the CheckerLabels should be the single source of truth.

checker.checkerId, analyzer_name))))
labels.append(sorted(
f'{key}:{value}' for key, value in
checker_labels.visible_labels_of_checker(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary interface change in CheckerLabels.

self.checker_labels_dir, guidelines)
div_zero_labels = {
f'{key}:{value}' for key, value in
local_checker_labels.visible_labels_of_checker(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary interface change in CheckerLabels.

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly fine to me, but I left a few comments.

Also, as mentioned before, it would nice to have some markdown documentation about the guideline, rule files, what they contain, how they relate to each other, that the profile containment is derived from descriptions.json etc.

Comment thread codechecker_common/guidelines.py Resolved
Comment thread codechecker_common/guidelines.py Resolved
Comment thread codechecker_common/checker_labels.py Resolved

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one comment regarding the level field.

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems some checkers are missing the rule:exp34-c label which was added by this commit: c771c5c1a

Regarding the level field, we should add a FIXME comment to the Rule dataclass that it's currently unused.

@barnabasdomozi barnabasdomozi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This change reworks how checker labels are working inside CodeChecker.

The guideline files are now separated from the rules. Each type of rule
(CWE, Sei-Cert, OWASP, etc.) have a separate file collecting all the rules
the given type has. Every rule has its ID and optionally its title and URL.
The guideline files are now only serves as a collection of rule IDs.

Label files also got reworked: containing less data for any given checker,
guideline definitions are discarded and now derived from the rule ID based
on which guideline contains the given rule. Every rule is now added by
`rule:<rule_name>`. Profiles are also reworked, the generic profiles (default,
sensitive and extreme) are now contained in eachother meaning only the
smallest set must be defined and the checker will automatically be in every
broader set. E.g. if a checker must be in sensitive and extreme, only sensitive
has to be defined, it will be in extreme automatically.

This change was made to prevent user mistakes when editing labelling, guidelines
or rules. Every component (rules, guidelines, labels) has its own source of truth
now which makes easier the further development.
Rework the docs for labels to describe the actual state of the labels.
Comment thread codechecker_common/checker_labels.py Outdated
else:
normalized.append(label)

return list(dict.fromkeys(normalized))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of transforming normalized to dict keys and back to a list again?

@bruntib
bruntib dismissed dkrupp’s stale review November 25, 2026 23:34

Suggested changes have been implemented.

@bruntib
bruntib merged commit 550fa94 into Ericsson:master Nov 25, 2026
11 of 13 checks passed
@gulyasgergely902
gulyasgergely902 deleted the rework-analyzer-labeling branch November 26, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants