-
Notifications
You must be signed in to change notification settings - Fork 70
Implement naming package, new IdentifierIntroduction.qll, unicode funcs. #950
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
Open
MichaelRFairhurst
wants to merge
4
commits into
main
Choose a base branch
from
michaelrfairhurst/implement-naming-package
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1c44315
Implement naming package, new IdentifierIntroduction.qll, unicode funcs.
MichaelRFairhurst 2adeaba
Fix tests, add missing changenote
MichaelRFairhurst 5a07066
Fix empty identifier in macros with empty parens
MichaelRFairhurst 752056e
Merge branch 'main' into michaelrfairhurst/implement-naming-package
mbaluda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
change_notes/2025-08-22-function-like-macro-param-name-bug-fixes.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - "Function-like macros" | ||
| - The parameter list of variadic macros previously included the ellipsis in name of the final parameter, potentially leading to incorrect analysis. This has been corrected. | ||
| - The parameter list of function-like macros with no parameters (i.e. `MACRO()`) was interpreted in a shared library as having a single parameter with an empty name. This does not seem to have had an impact on any existing queries, but has been fixed to correctly show no parameters. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import codeql.util.Numbers | ||
|
|
||
| /** | ||
| * Provides properties of a Unicode code point, where the property is of 'enumeration', 'catalog', | ||
| * or 'string-valued' type, however, the only supported property is `NFC_QC`. | ||
| * | ||
| * For example, `Block` is an enumeration property, `Line_Break` is a catalog property, and | ||
| * `Uppercase_Mapping` is a string-valued property. | ||
| * | ||
| * For boolean properties, see `unicodeHasBooleanProperty`, and for numeric properties, see | ||
| * `unicodeHasNumericProperty`. | ||
| */ | ||
| extensible predicate unicodeHasProperty(int codePoint, string propertyName, string propertyValue); | ||
|
|
||
| /** | ||
| * Holds when the Unicode code point's boolean property of the given name is true. | ||
| * | ||
| * For example, `Alphabetic` is a boolean property that can be true or false for a code point. | ||
| * | ||
| * For other types of properties, see `unicodeHasProperty`. | ||
| */ | ||
| extensible predicate unicodeHasBooleanProperty(int codePoint, string propertyName); | ||
|
|
||
| bindingset[input] | ||
| int unescapedCodePointAt(string input, int index) { | ||
| exists(string match | | ||
| match = input.regexpFind("(\\\\u[0-9a-fA-F]{4}|.)", index, _) and | ||
| if match.matches("\\u%") | ||
| then result = parseHexInt(match.substring(2, match.length())) | ||
| else result = match.codePointAt(0) | ||
| ) | ||
| } | ||
|
|
||
| bindingset[input] | ||
| string unescapeUnicode(string input) { | ||
| result = | ||
| concat(int code, int idx | | ||
| code = unescapedCodePointAt(input, idx) | ||
| | | ||
| code.toUnicode() order by idx | ||
| ) | ||
| } | ||
|
|
||
| bindingset[id] | ||
| predicate nonUax44IdentifierCodepoint(string id, int index) { | ||
| exists(int codePoint | | ||
| codePoint = id.codePointAt(index) and | ||
| ( | ||
| not unicodeHasBooleanProperty(codePoint, "XID_Start") and | ||
| not unicodeHasBooleanProperty(codePoint, "XID_Continue") | ||
| or | ||
| index = 0 and | ||
| not unicodeHasBooleanProperty(codePoint, "XID_Start") | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| bindingset[id] | ||
| predicate nonNfcNormalizedCodepoint(string id, int index, string noOrMaybe) { | ||
| exists(int codePoint | | ||
| codePoint = id.codePointAt(index) and | ||
| unicodeHasProperty(codePoint, "NFC_QC", noOrMaybe) and | ||
| noOrMaybe = ["N", "M"] | ||
| ) | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
cpp/common/src/codingstandards/cpp/exclusions/cpp/Naming2.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ | ||
| import cpp | ||
| import RuleMetadata | ||
| import codingstandards.cpp.exclusions.RuleMetadata | ||
|
|
||
| newtype Naming2Query = TPoorlyFormedIdentifierQuery() | ||
|
|
||
| predicate isNaming2QueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `poorlyFormedIdentifier` query | ||
| Naming2Package::poorlyFormedIdentifierQuery() and | ||
| queryId = | ||
| // `@id` for the `poorlyFormedIdentifier` query | ||
| "cpp/misra/poorly-formed-identifier" and | ||
| ruleId = "RULE-5-10-1" and | ||
| category = "required" | ||
| } | ||
|
|
||
| module Naming2Package { | ||
| Query poorlyFormedIdentifierQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `poorlyFormedIdentifier` query | ||
| TQueryCPP(TNaming2PackageQuery(TPoorlyFormedIdentifierQuery())) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states that this predicate provides properties of type 'enumeration', 'catalog', or 'string-valued', but then says "however, the only supported property is NFC_QC". This is confusing because it first suggests broad support and then limits it. Consider rephrasing to be more direct, such as: "Provides the NFC_QC property value for a Unicode code point. This is the only Unicode property currently supported."