Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MISRA 10.3 improvements #7349

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Conversation

wienans
Copy link
Contributor

@wienans wienans commented Mar 3, 2025

Updated the check for misra 10.3 based on the misra examples https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite

also added the examples as tests

@wienans wienans force-pushed the feature/misra-10.3 branch from e507509 to 25afaed Compare March 8, 2025 12:45
@wienans
Copy link
Contributor Author

wienans commented Mar 9, 2025

@danmar actually handling this

static char * misra_11_8(const char *str) {
(void)misra_11_8_const(str); // no-warning
return (char *)str; // 11.8
}
i find actually hard. It generates the following token stream and currently generates a 10.3 Warning due to char and signed char essential type category mismatch.

    <token id="594add3b56b0" file="project/src/test.c" linenr="22" column="1" str="static" scope="594add381040" type="name"/>
    <token id="594add3b9740" file="project/src/test.c" linenr="22" column="8" str="char" scope="594add381040" type="name"/>
    <token id="594add3a5e00" file="project/src/test.c" linenr="22" column="13" str="*" scope="594add381040" type="op" isArithmeticalOp="true"/>
    <token id="594add382cf0" file="project/src/test.c" linenr="22" column="15" str="misra_11_8" scope="594add381040" type="name" function="594add34da70"/>
    <token id="594add32f260" file="project/src/test.c" linenr="22" column="25" str="(" scope="594add381040" link="594add3bc560" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-reference="None"/>
    <token id="594add3bc280" file="project/src/test.c" linenr="22" column="26" str="const" scope="594add381040" type="name"/>
    <token id="594add37b820" file="project/src/test.c" linenr="22" column="32" str="char" scope="594add381040" type="name"/>
    <token id="594add33f8e0" file="project/src/test.c" linenr="22" column="37" str="*" scope="594add381040" type="op" isArithmeticalOp="true"/>
    <token id="594add3bc3e0" file="project/src/test.c" linenr="22" column="38" str="str" scope="594add381040" type="name" varId="6" exprId="6" variable="594add337bb0" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-constness="1" valueType-reference="None"/>
    <token id="594add3bc560" file="project/src/test.c" linenr="22" column="41" str=")" scope="594add381040" link="594add32f260"/>
    <token id="594add3bc6e0" file="project/src/test.c" linenr="22" column="43" str="{" scope="594add389460" link="594add30c3d0"/>
    <token id="594add3bc750" file="project/src/test.c" linenr="23" column="5" str="return" scope="594add389460" type="name" astOperand1="594add32ef20" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-reference="None"/>
    <token id="594add32ef20" file="project/src/test.c" linenr="23" column="12" str="(" scope="594add389460" isCast="true" link="594add3bcaa0" exprId="1073741840" values="594add3b8c70" astParent="594add3bc750" astOperand1="594add30b1a0" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-reference="None"/>
    <token id="594add3bc7c0" file="project/src/test.c" linenr="23" column="13" str="char" scope="594add389460" type="name"/>
    <token id="594add3bc940" file="project/src/test.c" linenr="23" column="18" str="*" scope="594add389460" type="op" isArithmeticalOp="true"/>
    <token id="594add3bcaa0" file="project/src/test.c" linenr="23" column="19" str=")" scope="594add389460" link="594add32ef20"/>
    <token id="594add30b1a0" file="project/src/test.c" linenr="23" column="20" str="str" scope="594add389460" type="name" varId="6" exprId="6" variable="594add337bb0" astParent="594add32ef20" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-constness="1" valueType-reference="None"/>
    <token id="594add30b210" file="project/src/test.c" linenr="23" column="23" str=";" scope="594add389460"/>
    <token id="594add30c3d0" file="project/src/test.c" linenr="24" column="1" str="}" scope="594add389460" link="594add3bc6e0"/>

in case of the Cast we look at the actual cast type and chek if the valueType token is str="char" and doesn't have the signed and unsinged flags.
But the return token does not have this link (at least to my knowledge) to the type definition token to the return type given in the function definition. Currently i didn't find a good solution to handle this. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant