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

Skip to content

Commit 55301b4

Browse files
authored
Merge pull request #3074 from matt-gretton-dann/codeql-c-extractor/50-char8_t
Add support for C++20's char8_t type.
2 parents 8a1d96b + a6947e0 commit 55301b4

File tree

16 files changed

+4110
-0
lines changed

16 files changed

+4110
-0
lines changed

cpp/ql/src/semmle/code/cpp/Type.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ private predicate isIntegralType(@builtintype type, int kind) {
376376
kind = 43
377377
or
378378
kind = 44
379+
or
380+
kind = 51
379381
)
380382
}
381383

@@ -463,6 +465,8 @@ private predicate integralTypeMapping(int original, int canonical, int unsigned,
463465
original = 43 and canonical = 43 and unsigned = -1 and signed = -1 // char16_t
464466
or
465467
original = 44 and canonical = 44 and unsigned = -1 and signed = -1 // char32_t
468+
or
469+
original = 51 and canonical = 51 and unsigned = -1 and signed = -1 // char8_t
466470
}
467471

468472
/**
@@ -993,6 +997,18 @@ class WideCharType extends IntegralType {
993997
override string getCanonicalQLClass() { result = "WideCharType" }
994998
}
995999

1000+
/**
1001+
* The C/C++ `char8_t` type. This is available starting with C++20.
1002+
* ```
1003+
* char8_t c8;
1004+
* ```
1005+
*/
1006+
class Char8Type extends IntegralType {
1007+
Char8Type() { builtintypes(underlyingElement(this), _, 51, _, _, _) }
1008+
1009+
override string getCanonicalQLClass() { result = "Char8Type" }
1010+
}
1011+
9961012
/**
9971013
* The C/C++ `char16_t` type. This is available starting with C11 and C++11.
9981014
* ```

cpp/ql/src/semmle/code/cpp/padding/Padding.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ abstract class Architecture extends string {
7474
or
7575
t instanceof WideCharType and result = wideCharSize()
7676
or
77+
t instanceof Char8Type and result = 8
78+
or
7779
t instanceof Char16Type and result = 16
7880
or
7981
t instanceof Char32Type and result = 32
@@ -155,6 +157,8 @@ abstract class Architecture extends string {
155157
or
156158
t instanceof WideCharType and result = wideCharSize()
157159
or
160+
t instanceof Char8Type and result = 8
161+
or
158162
t instanceof Char16Type and result = 16
159163
or
160164
t instanceof Char32Type and result = 32

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ enumconstants(
616616
| 48 = _Float64x
617617
| 49 = _Float128
618618
| 50 = _Float128x
619+
| 51 = char8_t
619620
;
620621
*/
621622
builtintypes(

cpp/ql/test/library-tests/clang_ms/element.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
| file://:0:0:0:0 | auto |
6262
| file://:0:0:0:0 | bool |
6363
| file://:0:0:0:0 | char |
64+
| file://:0:0:0:0 | char8_t |
6465
| file://:0:0:0:0 | char16_t |
6566
| file://:0:0:0:0 | char32_t |
6667
| file://:0:0:0:0 | const |

cpp/ql/test/library-tests/conditions/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
| file://:0:0:0:0 | auto |
3939
| file://:0:0:0:0 | bool |
4040
| file://:0:0:0:0 | char |
41+
| file://:0:0:0:0 | char8_t |
4142
| file://:0:0:0:0 | char16_t |
4243
| file://:0:0:0:0 | char32_t |
4344
| file://:0:0:0:0 | const |

cpp/ql/test/library-tests/templates/instantiations_functions/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
| file://:0:0:0:0 | auto |
5252
| file://:0:0:0:0 | bool |
5353
| file://:0:0:0:0 | char |
54+
| file://:0:0:0:0 | char8_t |
5455
| file://:0:0:0:0 | char16_t |
5556
| file://:0:0:0:0 | char32_t |
5657
| file://:0:0:0:0 | composite<int> & |

cpp/ql/test/library-tests/templates/type_instantiations/types.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
| file://:0:0:0:0 | auto |
2424
| file://:0:0:0:0 | bool |
2525
| file://:0:0:0:0 | char |
26+
| file://:0:0:0:0 | char8_t |
2627
| file://:0:0:0:0 | char16_t |
2728
| file://:0:0:0:0 | char32_t |
2829
| file://:0:0:0:0 | const __va_list_tag |

cpp/ql/test/library-tests/type_sizes/type_sizes.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
| file://:0:0:0:0 | auto | <none> |
4545
| file://:0:0:0:0 | bool | 1 |
4646
| file://:0:0:0:0 | char | 1 |
47+
| file://:0:0:0:0 | char8_t | 1 |
4748
| file://:0:0:0:0 | char16_t | 2 |
4849
| file://:0:0:0:0 | char32_t | 4 |
4950
| file://:0:0:0:0 | char * | 8 |

cpp/ql/test/library-tests/types/integral_types/integral_type.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
| 37 | signed __int128 | signed | -------- | explicitlySigned | ------------------ | ---------------- | 16 | 16 | unsigned __int128 | |
2121
| 43 | char16_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 2 | 2 | <no unsigned equivalent> | |
2222
| 44 | char32_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 4 | 4 | <no unsigned equivalent> | |
23+
| 51 | char8_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 1 | 1 | <no unsigned equivalent> | |

cpp/ql/test/library-tests/types/integral_types_ms/integral_type.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
| 37 | signed __int128 | signed | -------- | explicitlySigned | ------------------ | ---------------- | 16 | 16 | unsigned __int128 | |
2121
| 43 | char16_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 2 | 2 | <no unsigned equivalent> | |
2222
| 44 | char32_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 4 | 4 | <no unsigned equivalent> | |
23+
| 51 | char8_t | ------ | -------- | ---------------- | ------------------ | ---------------- | 1 | 1 | <no unsigned equivalent> | |

cpp/ql/test/library-tests/unnamed/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
| file://:0:0:0:0 | auto | Other |
3434
| file://:0:0:0:0 | bool | Other |
3535
| file://:0:0:0:0 | char | Other |
36+
| file://:0:0:0:0 | char8_t | Other |
3637
| file://:0:0:0:0 | char16_t | Other |
3738
| file://:0:0:0:0 | char32_t | Other |
3839
| file://:0:0:0:0 | const | Other |

cpp/ql/test/library-tests/unspecified_type/types/unspecified_type.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| file://:0:0:0:0 | auto | auto |
2525
| file://:0:0:0:0 | bool | bool |
2626
| file://:0:0:0:0 | char | char |
27+
| file://:0:0:0:0 | char8_t | char8_t |
2728
| file://:0:0:0:0 | char16_t | char16_t |
2829
| file://:0:0:0:0 | char32_t | char32_t |
2930
| file://:0:0:0:0 | const __va_list_tag | __va_list_tag |

cpp/ql/test/library-tests/variables/variables/types.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| auto | AutoType | | | | |
2828
| bool | BoolType | | | | |
2929
| char | MicrosoftInt8Type, PlainCharType | | | | |
30+
| char8_t | Char8Type | | | | |
3031
| char16_t | Char16Type | | | | |
3132
| char32_t | Char32Type | | | | |
3233
| char * | CharPointerType | | char | | |

0 commit comments

Comments
 (0)