Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for C++20's char8_t type. #3074

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cpp/ql/src/semmle/code/cpp/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ private predicate isIntegralType(@builtintype type, int kind) {
kind = 43
or
kind = 44
or
kind = 51
)
}

Expand Down Expand Up @@ -463,6 +465,8 @@ private predicate integralTypeMapping(int original, int canonical, int unsigned,
original = 43 and canonical = 43 and unsigned = -1 and signed = -1 // char16_t
or
original = 44 and canonical = 44 and unsigned = -1 and signed = -1 // char32_t
or
original = 51 and canonical = 51 and unsigned = -1 and signed = -1 // char8_t
}

/**
Expand Down Expand Up @@ -993,6 +997,18 @@ class WideCharType extends IntegralType {
override string getCanonicalQLClass() { result = "WideCharType" }
}

/**
* The C/C++ `char8_t` type. This is available starting with C++20.
* ```
* char8_t c8;
* ```
*/
class Char8Type extends IntegralType {
Char8Type() { builtintypes(underlyingElement(this), _, 51, _, _, _) }

override string getCanonicalQLClass() { result = "Char8Type" }
}

/**
* The C/C++ `char16_t` type. This is available starting with C11 and C++11.
* ```
Expand Down
4 changes: 4 additions & 0 deletions cpp/ql/src/semmle/code/cpp/padding/Padding.qll
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ abstract class Architecture extends string {
or
t instanceof WideCharType and result = wideCharSize()
or
t instanceof Char8Type and result = 8
or
t instanceof Char16Type and result = 16
or
t instanceof Char32Type and result = 32
Expand Down Expand Up @@ -155,6 +157,8 @@ abstract class Architecture extends string {
or
t instanceof WideCharType and result = wideCharSize()
or
t instanceof Char8Type and result = 8
or
t instanceof Char16Type and result = 16
or
t instanceof Char32Type and result = 32
Expand Down
1 change: 1 addition & 0 deletions cpp/ql/src/semmlecode.cpp.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ enumconstants(
| 48 = _Float64x
| 49 = _Float128
| 50 = _Float128x
| 51 = char8_t
;
*/
builtintypes(
Expand Down
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/clang_ms/element.expected
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
| file://:0:0:0:0 | auto |
| file://:0:0:0:0 | bool |
| file://:0:0:0:0 | char |
| file://:0:0:0:0 | char8_t |
| file://:0:0:0:0 | char16_t |
| file://:0:0:0:0 | char32_t |
| file://:0:0:0:0 | const |
Expand Down
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/conditions/elements.expected
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
| file://:0:0:0:0 | auto |
| file://:0:0:0:0 | bool |
| file://:0:0:0:0 | char |
| file://:0:0:0:0 | char8_t |
| file://:0:0:0:0 | char16_t |
| file://:0:0:0:0 | char32_t |
| file://:0:0:0:0 | const |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
| file://:0:0:0:0 | auto |
| file://:0:0:0:0 | bool |
| file://:0:0:0:0 | char |
| file://:0:0:0:0 | char8_t |
| file://:0:0:0:0 | char16_t |
| file://:0:0:0:0 | char32_t |
| file://:0:0:0:0 | composite<int> & |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| file://:0:0:0:0 | auto |
| file://:0:0:0:0 | bool |
| file://:0:0:0:0 | char |
| file://:0:0:0:0 | char8_t |
| file://:0:0:0:0 | char16_t |
| file://:0:0:0:0 | char32_t |
| file://:0:0:0:0 | const __va_list_tag |
Expand Down
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/type_sizes/type_sizes.expected
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
| file://:0:0:0:0 | auto | <none> |
| file://:0:0:0:0 | bool | 1 |
| file://:0:0:0:0 | char | 1 |
| file://:0:0:0:0 | char8_t | 1 |
| file://:0:0:0:0 | char16_t | 2 |
| file://:0:0:0:0 | char32_t | 4 |
| file://:0:0:0:0 | char * | 8 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
| 37 | signed __int128 | signed | -------- | explicitlySigned | ------------------ | ---------------- | 16 | 16 | unsigned __int128 | |
| 43 | char16_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 2 | 2 | <no unsigned equivalent> | |
| 44 | char32_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 4 | 4 | <no unsigned equivalent> | |
| 51 | char8_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 1 | 1 | <no unsigned equivalent> | |
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
| 37 | signed __int128 | signed | -------- | explicitlySigned | ------------------ | ---------------- | 16 | 16 | unsigned __int128 | |
| 43 | char16_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 2 | 2 | <no unsigned equivalent> | |
| 44 | char32_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 4 | 4 | <no unsigned equivalent> | |
| 51 | char8_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 1 | 1 | <no unsigned equivalent> | |
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/unnamed/elements.expected
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
| file://:0:0:0:0 | auto | Other |
| file://:0:0:0:0 | bool | Other |
| file://:0:0:0:0 | char | Other |
| file://:0:0:0:0 | char8_t | Other |
| file://:0:0:0:0 | char16_t | Other |
| file://:0:0:0:0 | char32_t | Other |
| file://:0:0:0:0 | const | Other |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
| file://:0:0:0:0 | auto | auto |
| file://:0:0:0:0 | bool | bool |
| file://:0:0:0:0 | char | char |
| file://:0:0:0:0 | char8_t | char8_t |
| file://:0:0:0:0 | char16_t | char16_t |
| file://:0:0:0:0 | char32_t | char32_t |
| file://:0:0:0:0 | const __va_list_tag | __va_list_tag |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| auto | AutoType | | | | |
| bool | BoolType | | | | |
| char | MicrosoftInt8Type, PlainCharType | | | | |
| char8_t | Char8Type | | | | |
| char16_t | Char16Type | | | | |
| char32_t | Char32Type | | | | |
| char * | CharPointerType | | char | | |
Expand Down
Loading