Skip to content

Commit 7772991

Browse files
author
Robert Marsh
committed
Merge branch 'main' into rdmarsh/cpp/use-taint-configuration-dtt
Update for submodule pointer
2 parents 5aed82a + cb8c5e8 commit 7772991

File tree

358 files changed

+4135
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

358 files changed

+4135
-757
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,15 @@ private class SpecifiedDumpType extends DerivedDumpType, SpecifiedType {
304304
basePrefix = getBaseType().(DumpType).getDeclaratorPrefix() and
305305
if getBaseType().getUnspecifiedType() instanceof RoutineType
306306
then result = basePrefix
307-
else result = basePrefix + " " + getSpecifierString().trim()
307+
else result = basePrefix + " " + getSpecifierString()
308308
)
309309
}
310310

311311
override string getDeclaratorSuffixBeforeQualifiers() {
312312
exists(string baseSuffix |
313313
baseSuffix = getBaseType().(DumpType).getDeclaratorSuffixBeforeQualifiers() and
314314
if getBaseType().getUnspecifiedType() instanceof RoutineType
315-
then result = baseSuffix + " " + getSpecifierString().trim()
315+
then result = baseSuffix + " " + getSpecifierString()
316316
else result = baseSuffix
317317
)
318318
}

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,14 +1304,16 @@ class SpecifiedType extends DerivedType {
13041304
}
13051305

13061306
/**
1307+
* INTERNAL: Do not use.
1308+
*
13071309
* Gets all the specifiers of this type as a string in a fixed order (the order
13081310
* only depends on the specifiers, not on the source program). This is intended
13091311
* for debugging queries only and is an expensive operation.
13101312
*/
1311-
string getSpecifierString() { internalSpecString(this, result, 1) }
1313+
string getSpecifierString() { result = concat(this.getASpecifier().getName(), " ") }
13121314

13131315
override string explain() {
1314-
result = this.getSpecifierString() + "{" + this.getBaseType().explain() + "}"
1316+
result = this.getSpecifierString() + " {" + this.getBaseType().explain() + "}"
13151317
}
13161318

13171319
override predicate isDeeplyConst() {
@@ -1710,28 +1712,6 @@ class AutoType extends TemplateParameter {
17101712
}
17111713
}
17121714

1713-
//
1714-
// Internal implementation predicates
1715-
//
1716-
private predicate allSpecifiers(int i, string s) { s = rank[i](string t | specifiers(_, t) | t) }
1717-
1718-
private predicate internalSpecString(Type t, string res, int i) {
1719-
(
1720-
if allSpecifiers(i, t.getASpecifier().getName())
1721-
then
1722-
exists(string spec, string rest |
1723-
allSpecifiers(i, spec) and
1724-
res = spec + " " + rest and
1725-
internalSpecString(t, rest, i + 1)
1726-
)
1727-
else (
1728-
allSpecifiers(i, _) and internalSpecString(t, res, i + 1)
1729-
)
1730-
)
1731-
or
1732-
i = count(Specifier s) + 1 and res = ""
1733-
}
1734-
17351715
private predicate suppressUnusedThis(Type t) { any() }
17361716

17371717
/** A source code location referring to a type */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
| file://:0:0:0:0 | declaration of 1st parameter |
7777
| file://:0:0:0:0 | declaration of 1st parameter |
7878
| file://:0:0:0:0 | declared_constexpr |
79+
| file://:0:0:0:0 | declared_constinit |
7980
| file://:0:0:0:0 | decltype(nullptr) |
8081
| file://:0:0:0:0 | definition of fp_offset |
8182
| file://:0:0:0:0 | definition of gp_offset |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
| file://:0:0:0:0 | const __va_list_tag |
4747
| file://:0:0:0:0 | const __va_list_tag & |
4848
| file://:0:0:0:0 | declared_constexpr |
49+
| file://:0:0:0:0 | declared_constinit |
4950
| file://:0:0:0:0 | decltype(nullptr) |
5051
| file://:0:0:0:0 | definition of <error> |
5152
| file://:0:0:0:0 | definition of fp_offset |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
| file://:0:0:0:0 | declaration of 1st parameter |
107107
| file://:0:0:0:0 | declaration of 1st parameter |
108108
| file://:0:0:0:0 | declared_constexpr |
109+
| file://:0:0:0:0 | declared_constinit |
109110
| file://:0:0:0:0 | decltype(nullptr) |
110111
| file://:0:0:0:0 | definition of fp_offset |
111112
| file://:0:0:0:0 | definition of gp_offset |

cpp/ql/test/library-tests/unnamed/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 | char32_t | Other |
3939
| file://:0:0:0:0 | const | Other |
4040
| file://:0:0:0:0 | declared_constexpr | Other |
41+
| file://:0:0:0:0 | declared_constinit | Other |
4142
| file://:0:0:0:0 | decltype(nullptr) | Other |
4243
| file://:0:0:0:0 | definition of fp_offset | Other |
4344
| file://:0:0:0:0 | definition of gp_offset | Other |

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/IsPattern.cs

Lines changed: 2 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,9 @@
1-
using Microsoft.CodeAnalysis;
2-
using Microsoft.CodeAnalysis.CSharp.Syntax;
3-
using Microsoft.CodeAnalysis.CSharp;
1+
using Microsoft.CodeAnalysis.CSharp.Syntax;
42
using Semmle.Extraction.Kinds;
5-
using Semmle.Extraction.Entities;
63
using System.IO;
74

85
namespace Semmle.Extraction.CSharp.Entities.Expressions
96
{
10-
internal static class PatternExtensions
11-
{
12-
public static Expression CreatePattern(this Context cx, PatternSyntax syntax, IExpressionParentEntity parent, int child)
13-
{
14-
switch (syntax)
15-
{
16-
case ConstantPatternSyntax constantPattern:
17-
return Expression.Create(cx, constantPattern.Expression, parent, child);
18-
19-
case DeclarationPatternSyntax declPattern:
20-
// Creates a single local variable declaration.
21-
{
22-
if (declPattern.Designation is VariableDesignationSyntax designation)
23-
{
24-
if (cx.GetModel(syntax).GetDeclaredSymbol(designation) is ILocalSymbol symbol)
25-
{
26-
var type = Type.Create(cx, symbol.GetAnnotatedType());
27-
return VariableDeclaration.Create(cx, symbol, type, declPattern.Type, cx.Create(syntax.GetLocation()), false, parent, child);
28-
}
29-
if (designation is DiscardDesignationSyntax)
30-
{
31-
return Expressions.TypeAccess.Create(cx, declPattern.Type, parent, child);
32-
}
33-
throw new InternalError(designation, "Designation pattern not handled");
34-
}
35-
throw new InternalError(declPattern, "Declaration pattern not handled");
36-
}
37-
38-
case RecursivePatternSyntax recPattern:
39-
return new RecursivePattern(cx, recPattern, parent, child);
40-
41-
case VarPatternSyntax varPattern:
42-
switch (varPattern.Designation)
43-
{
44-
case ParenthesizedVariableDesignationSyntax parDesignation:
45-
return VariableDeclaration.CreateParenthesized(cx, varPattern, parDesignation, parent, child);
46-
case SingleVariableDesignationSyntax varDesignation:
47-
if (cx.GetModel(syntax).GetDeclaredSymbol(varDesignation) is ILocalSymbol symbol)
48-
{
49-
var type = Type.Create(cx, symbol.GetAnnotatedType());
50-
51-
return VariableDeclaration.Create(cx, symbol, type, null, cx.Create(syntax.GetLocation()), true, parent, child);
52-
}
53-
54-
throw new InternalError(varPattern, "Unable to get the declared symbol of the var pattern designation.");
55-
default:
56-
throw new InternalError("var pattern designation is unhandled");
57-
}
58-
59-
case DiscardPatternSyntax dp:
60-
return new Discard(cx, dp, parent, child);
61-
62-
default:
63-
throw new InternalError(syntax, "Pattern not handled");
64-
}
65-
}
66-
}
67-
68-
internal class PropertyPattern : Expression
69-
{
70-
internal PropertyPattern(Context cx, PropertyPatternClauseSyntax pp, IExpressionParentEntity parent, int child) :
71-
base(new ExpressionInfo(cx, Entities.NullType.Create(cx), cx.Create(pp.GetLocation()), ExprKind.PROPERTY_PATTERN, parent, child, false, null))
72-
{
73-
child = 0;
74-
var trapFile = cx.TrapWriter.Writer;
75-
foreach (var sub in pp.Subpatterns)
76-
{
77-
var p = cx.CreatePattern(sub.Pattern, this, child++);
78-
trapFile.exprorstmt_name(p, sub.NameColon.Name.ToString());
79-
}
80-
}
81-
}
82-
83-
internal class PositionalPattern : Expression
84-
{
85-
internal PositionalPattern(Context cx, PositionalPatternClauseSyntax posPc, IExpressionParentEntity parent, int child) :
86-
base(new ExpressionInfo(cx, Entities.NullType.Create(cx), cx.Create(posPc.GetLocation()), ExprKind.POSITIONAL_PATTERN, parent, child, false, null))
87-
{
88-
child = 0;
89-
foreach (var sub in posPc.Subpatterns)
90-
{
91-
cx.CreatePattern(sub.Pattern, this, child++);
92-
}
93-
}
94-
}
95-
96-
internal class RecursivePattern : Expression
97-
{
98-
/// <summary>
99-
/// Creates and populates a recursive pattern.
100-
/// </summary>
101-
/// <param name="cx">The extraction context.</param>
102-
/// <param name="syntax">The syntax node of the recursive pattern.</param>
103-
/// <param name="parent">The parent pattern/expression.</param>
104-
/// <param name="child">The child index of this pattern.</param>
105-
/// <param name="isTopLevel">If this pattern is in the top level of a case/is. In that case, the variable and type access are populated elsewhere.</param>
106-
public RecursivePattern(Context cx, RecursivePatternSyntax syntax, IExpressionParentEntity parent, int child) :
107-
base(new ExpressionInfo(cx, Entities.NullType.Create(cx), cx.Create(syntax.GetLocation()), ExprKind.RECURSIVE_PATTERN, parent, child, false, null))
108-
{
109-
// Extract the type access
110-
if (syntax.Type is TypeSyntax t)
111-
Expressions.TypeAccess.Create(cx, t, this, 1);
112-
113-
// Extract the local variable declaration
114-
if (syntax.Designation is VariableDesignationSyntax designation && cx.GetModel(syntax).GetDeclaredSymbol(designation) is ILocalSymbol symbol)
115-
{
116-
var type = Entities.Type.Create(cx, symbol.GetAnnotatedType());
117-
118-
VariableDeclaration.Create(cx, symbol, type, null, cx.Create(syntax.GetLocation()), false, this, 0);
119-
}
120-
121-
if (syntax.PositionalPatternClause is PositionalPatternClauseSyntax posPc)
122-
{
123-
new PositionalPattern(cx, posPc, this, 2);
124-
}
125-
126-
if (syntax.PropertyPatternClause is PropertyPatternClauseSyntax pc)
127-
{
128-
new PropertyPattern(cx, pc, this, 3);
129-
}
130-
}
131-
}
132-
1337
internal class IsPattern : Expression<IsPatternExpressionSyntax>
1348
{
1359
private IsPattern(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.IS))
@@ -139,7 +13,7 @@ private IsPattern(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.IS))
13913
protected override void PopulateExpression(TextWriter trapFile)
14014
{
14115
Create(cx, Syntax.Expression, this, 0);
142-
cx.CreatePattern(Syntax.Pattern, this, 1);
16+
Expressions.Pattern.Create(cx, Syntax.Pattern, this, 1);
14317
}
14418

14519
public static Expression Create(ExpressionNodeInfo info) => new IsPattern(info).TryPopulate();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.CSharp.Syntax;
3+
using Microsoft.CodeAnalysis.CSharp;
4+
using Semmle.Extraction.Entities;
5+
6+
namespace Semmle.Extraction.CSharp.Entities.Expressions
7+
{
8+
public static class Pattern
9+
{
10+
internal static Expression Create(Context cx, PatternSyntax syntax, IExpressionParentEntity parent, int child)
11+
{
12+
switch (syntax)
13+
{
14+
case ConstantPatternSyntax constantPattern:
15+
return Expression.Create(cx, constantPattern.Expression, parent, child);
16+
17+
case DeclarationPatternSyntax declPattern:
18+
// Creates a single local variable declaration.
19+
{
20+
if (declPattern.Designation is VariableDesignationSyntax designation)
21+
{
22+
if (cx.GetModel(syntax).GetDeclaredSymbol(designation) is ILocalSymbol symbol)
23+
{
24+
var type = Type.Create(cx, symbol.GetAnnotatedType());
25+
return VariableDeclaration.Create(cx, symbol, type, declPattern.Type, cx.Create(syntax.GetLocation()), false, parent, child);
26+
}
27+
if (designation is DiscardDesignationSyntax)
28+
{
29+
return Expressions.TypeAccess.Create(cx, declPattern.Type, parent, child);
30+
}
31+
throw new InternalError(designation, "Designation pattern not handled");
32+
}
33+
throw new InternalError(declPattern, "Declaration pattern not handled");
34+
}
35+
36+
case RecursivePatternSyntax recPattern:
37+
return new RecursivePattern(cx, recPattern, parent, child);
38+
39+
case VarPatternSyntax varPattern:
40+
switch (varPattern.Designation)
41+
{
42+
case ParenthesizedVariableDesignationSyntax parDesignation:
43+
return VariableDeclaration.CreateParenthesized(cx, varPattern, parDesignation, parent, child);
44+
case SingleVariableDesignationSyntax varDesignation:
45+
if (cx.GetModel(syntax).GetDeclaredSymbol(varDesignation) is ILocalSymbol symbol)
46+
{
47+
var type = Type.Create(cx, symbol.GetAnnotatedType());
48+
49+
return VariableDeclaration.Create(cx, symbol, type, null, cx.Create(syntax.GetLocation()), true, parent, child);
50+
}
51+
52+
throw new InternalError(varPattern, "Unable to get the declared symbol of the var pattern designation.");
53+
case DiscardDesignationSyntax discard:
54+
return new Expressions.Discard(cx, discard, parent, child);
55+
default:
56+
throw new InternalError("var pattern designation is unhandled");
57+
}
58+
59+
case DiscardPatternSyntax dp:
60+
return new Discard(cx, dp, parent, child);
61+
62+
default:
63+
throw new InternalError(syntax, "Pattern not handled");
64+
}
65+
}
66+
}
67+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.CodeAnalysis.CSharp.Syntax;
2+
using Semmle.Extraction.Kinds;
3+
using Semmle.Extraction.Entities;
4+
5+
namespace Semmle.Extraction.CSharp.Entities.Expressions
6+
{
7+
internal class PositionalPattern : Expression
8+
{
9+
internal PositionalPattern(Context cx, PositionalPatternClauseSyntax posPc, IExpressionParentEntity parent, int child) :
10+
base(new ExpressionInfo(cx, Entities.NullType.Create(cx), cx.Create(posPc.GetLocation()), ExprKind.POSITIONAL_PATTERN, parent, child, false, null))
11+
{
12+
child = 0;
13+
foreach (var sub in posPc.Subpatterns)
14+
{
15+
Expressions.Pattern.Create(cx, sub.Pattern, this, child++);
16+
}
17+
}
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.CodeAnalysis.CSharp.Syntax;
2+
using Semmle.Extraction.Kinds;
3+
using Semmle.Extraction.Entities;
4+
5+
namespace Semmle.Extraction.CSharp.Entities.Expressions
6+
{
7+
internal class PropertyPattern : Expression
8+
{
9+
internal PropertyPattern(Context cx, PropertyPatternClauseSyntax pp, IExpressionParentEntity parent, int child) :
10+
base(new ExpressionInfo(cx, Entities.NullType.Create(cx), cx.Create(pp.GetLocation()), ExprKind.PROPERTY_PATTERN, parent, child, false, null))
11+
{
12+
child = 0;
13+
var trapFile = cx.TrapWriter.Writer;
14+
foreach (var sub in pp.Subpatterns)
15+
{
16+
var p = Expressions.Pattern.Create(cx, sub.Pattern, this, child++);
17+
trapFile.exprorstmt_name(p, sub.NameColon.Name.ToString());
18+
}
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)