Skip to content

Commit 17c57dc

Browse files
authored
Merge pull request github#2971 from matt-gretton-dann/codeql-c-extractor/40-spaceship
C++20 Add DB Support for the <=> operator
2 parents eb7d809 + 3465c96 commit 17c57dc

File tree

11 files changed

+10354
-6517
lines changed

11 files changed

+10354
-6517
lines changed

cpp/ql/src/semmle/code/cpp/exprs/ArithmeticOperation.qll

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class UnaryMinusExpr extends UnaryArithmeticOperation, @arithnegexpr {
1616

1717
override string getCanonicalQLClass() { result = "UnaryMinusExpr" }
1818

19-
override int getPrecedence() { result = 15 }
19+
override int getPrecedence() { result = 16 }
2020
}
2121

2222
/**
@@ -30,7 +30,7 @@ class UnaryPlusExpr extends UnaryArithmeticOperation, @unaryplusexpr {
3030

3131
override string getCanonicalQLClass() { result = "UnaryPlusExpr" }
3232

33-
override int getPrecedence() { result = 15 }
33+
override int getPrecedence() { result = 16 }
3434
}
3535

3636
/**
@@ -109,7 +109,7 @@ class PrefixIncrExpr extends IncrementOperation, PrefixCrementOperation, @preinc
109109

110110
override string getCanonicalQLClass() { result = "PrefixIncrExpr" }
111111

112-
override int getPrecedence() { result = 15 }
112+
override int getPrecedence() { result = 16 }
113113
}
114114

115115
/**
@@ -125,7 +125,7 @@ class PrefixDecrExpr extends DecrementOperation, PrefixCrementOperation, @predec
125125

126126
override string getCanonicalQLClass() { result = "PrefixDecrExpr" }
127127

128-
override int getPrecedence() { result = 15 }
128+
override int getPrecedence() { result = 16 }
129129
}
130130

131131
/**
@@ -141,7 +141,7 @@ class PostfixIncrExpr extends IncrementOperation, PostfixCrementOperation, @post
141141

142142
override string getCanonicalQLClass() { result = "PostfixIncrExpr" }
143143

144-
override int getPrecedence() { result = 16 }
144+
override int getPrecedence() { result = 17 }
145145

146146
override string toString() { result = "... " + getOperator() }
147147
}
@@ -159,7 +159,7 @@ class PostfixDecrExpr extends DecrementOperation, PostfixCrementOperation, @post
159159

160160
override string getCanonicalQLClass() { result = "PostfixDecrExpr" }
161161

162-
override int getPrecedence() { result = 16 }
162+
override int getPrecedence() { result = 17 }
163163

164164
override string toString() { result = "... " + getOperator() }
165165
}
@@ -210,7 +210,7 @@ class AddExpr extends BinaryArithmeticOperation, @addexpr {
210210

211211
override string getCanonicalQLClass() { result = "AddExpr" }
212212

213-
override int getPrecedence() { result = 12 }
213+
override int getPrecedence() { result = 13 }
214214
}
215215

216216
/**
@@ -224,7 +224,7 @@ class SubExpr extends BinaryArithmeticOperation, @subexpr {
224224

225225
override string getCanonicalQLClass() { result = "SubExpr" }
226226

227-
override int getPrecedence() { result = 12 }
227+
override int getPrecedence() { result = 13 }
228228
}
229229

230230
/**
@@ -238,7 +238,7 @@ class MulExpr extends BinaryArithmeticOperation, @mulexpr {
238238

239239
override string getCanonicalQLClass() { result = "MulExpr" }
240240

241-
override int getPrecedence() { result = 13 }
241+
override int getPrecedence() { result = 14 }
242242
}
243243

244244
/**
@@ -252,7 +252,7 @@ class DivExpr extends BinaryArithmeticOperation, @divexpr {
252252

253253
override string getCanonicalQLClass() { result = "DivExpr" }
254254

255-
override int getPrecedence() { result = 13 }
255+
override int getPrecedence() { result = 14 }
256256
}
257257

258258
/**
@@ -266,7 +266,7 @@ class RemExpr extends BinaryArithmeticOperation, @remexpr {
266266

267267
override string getCanonicalQLClass() { result = "RemExpr" }
268268

269-
override int getPrecedence() { result = 13 }
269+
override int getPrecedence() { result = 14 }
270270
}
271271

272272
/**
@@ -283,7 +283,7 @@ class ImaginaryMulExpr extends BinaryArithmeticOperation, @jmulexpr {
283283

284284
override string getCanonicalQLClass() { result = "ImaginaryMulExpr" }
285285

286-
override int getPrecedence() { result = 13 }
286+
override int getPrecedence() { result = 14 }
287287
}
288288

289289
/**
@@ -300,7 +300,7 @@ class ImaginaryDivExpr extends BinaryArithmeticOperation, @jdivexpr {
300300

301301
override string getCanonicalQLClass() { result = "ImaginaryDivExpr" }
302302

303-
override int getPrecedence() { result = 13 }
303+
override int getPrecedence() { result = 14 }
304304
}
305305

306306
/**
@@ -318,7 +318,7 @@ class RealImaginaryAddExpr extends BinaryArithmeticOperation, @fjaddexpr {
318318

319319
override string getCanonicalQLClass() { result = "RealImaginaryAddExpr" }
320320

321-
override int getPrecedence() { result = 12 }
321+
override int getPrecedence() { result = 13 }
322322
}
323323

324324
/**
@@ -336,7 +336,7 @@ class ImaginaryRealAddExpr extends BinaryArithmeticOperation, @jfaddexpr {
336336

337337
override string getCanonicalQLClass() { result = "ImaginaryRealAddExpr" }
338338

339-
override int getPrecedence() { result = 12 }
339+
override int getPrecedence() { result = 13 }
340340
}
341341

342342
/**
@@ -354,7 +354,7 @@ class RealImaginarySubExpr extends BinaryArithmeticOperation, @fjsubexpr {
354354

355355
override string getCanonicalQLClass() { result = "RealImaginarySubExpr" }
356356

357-
override int getPrecedence() { result = 12 }
357+
override int getPrecedence() { result = 13 }
358358
}
359359

360360
/**
@@ -372,7 +372,7 @@ class ImaginaryRealSubExpr extends BinaryArithmeticOperation, @jfsubexpr {
372372

373373
override string getCanonicalQLClass() { result = "ImaginaryRealSubExpr" }
374374

375-
override int getPrecedence() { result = 12 }
375+
override int getPrecedence() { result = 13 }
376376
}
377377

378378
/**
@@ -416,7 +416,7 @@ class PointerAddExpr extends PointerArithmeticOperation, @paddexpr {
416416

417417
override string getCanonicalQLClass() { result = "PointerAddExpr" }
418418

419-
override int getPrecedence() { result = 12 }
419+
override int getPrecedence() { result = 13 }
420420
}
421421

422422
/**
@@ -431,7 +431,7 @@ class PointerSubExpr extends PointerArithmeticOperation, @psubexpr {
431431

432432
override string getCanonicalQLClass() { result = "PointerSubExpr" }
433433

434-
override int getPrecedence() { result = 12 }
434+
override int getPrecedence() { result = 13 }
435435
}
436436

437437
/**
@@ -446,5 +446,5 @@ class PointerDiffExpr extends PointerArithmeticOperation, @pdiffexpr {
446446

447447
override string getCanonicalQLClass() { result = "PointerDiffExpr" }
448448

449-
override int getPrecedence() { result = 12 }
449+
override int getPrecedence() { result = 13 }
450450
}

cpp/ql/src/semmle/code/cpp/exprs/BitwiseOperation.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class UnaryBitwiseOperation extends UnaryOperation, @un_bitwise_op_expr { }
1414
class ComplementExpr extends UnaryBitwiseOperation, @complementexpr {
1515
override string getOperator() { result = "~" }
1616

17-
override int getPrecedence() { result = 15 }
17+
override int getPrecedence() { result = 16 }
1818

1919
override string getCanonicalQLClass() { result = "ComplementExpr" }
2020
}
@@ -33,7 +33,7 @@ class BinaryBitwiseOperation extends BinaryOperation, @bin_bitwise_op_expr { }
3333
class LShiftExpr extends BinaryBitwiseOperation, @lshiftexpr {
3434
override string getOperator() { result = "<<" }
3535

36-
override int getPrecedence() { result = 11 }
36+
override int getPrecedence() { result = 12 }
3737

3838
override string getCanonicalQLClass() { result = "LShiftExpr" }
3939
}
@@ -47,7 +47,7 @@ class LShiftExpr extends BinaryBitwiseOperation, @lshiftexpr {
4747
class RShiftExpr extends BinaryBitwiseOperation, @rshiftexpr {
4848
override string getOperator() { result = ">>" }
4949

50-
override int getPrecedence() { result = 11 }
50+
override int getPrecedence() { result = 12 }
5151

5252
override string getCanonicalQLClass() { result = "RShiftExpr" }
5353
}

cpp/ql/src/semmle/code/cpp/exprs/Call.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract class Call extends Expr, NameQualifiableElement {
7474
*/
7575
abstract Function getTarget();
7676

77-
override int getPrecedence() { result = 16 }
77+
override int getPrecedence() { result = 17 }
7878

7979
override string toString() { none() }
8080

cpp/ql/src/semmle/code/cpp/exprs/Cast.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CStyleCast extends Cast, @c_style_cast {
8484

8585
override string getCanonicalQLClass() { result = "CStyleCast" }
8686

87-
override int getPrecedence() { result = 15 }
87+
override int getPrecedence() { result = 16 }
8888
}
8989

9090
/**
@@ -103,7 +103,7 @@ class StaticCast extends Cast, @static_cast {
103103

104104
override string getCanonicalQLClass() { result = "StaticCast" }
105105

106-
override int getPrecedence() { result = 16 }
106+
override int getPrecedence() { result = 17 }
107107
}
108108

109109
/**
@@ -121,7 +121,7 @@ class ConstCast extends Cast, @const_cast {
121121

122122
override string getCanonicalQLClass() { result = "ConstCast" }
123123

124-
override int getPrecedence() { result = 16 }
124+
override int getPrecedence() { result = 17 }
125125
}
126126

127127
/**
@@ -139,7 +139,7 @@ class ReinterpretCast extends Cast, @reinterpret_cast {
139139

140140
override string getCanonicalQLClass() { result = "ReinterpretCast" }
141141

142-
override int getPrecedence() { result = 16 }
142+
override int getPrecedence() { result = 17 }
143143
}
144144

145145
private predicate isArithmeticOrEnum(Type type) {
@@ -608,7 +608,7 @@ class PrvalueAdjustmentConversion extends Cast {
608608
class DynamicCast extends Cast, @dynamic_cast {
609609
override string toString() { result = "dynamic_cast<" + this.getType().getName() + ">..." }
610610

611-
override int getPrecedence() { result = 16 }
611+
override int getPrecedence() { result = 17 }
612612

613613
override string getCanonicalQLClass() { result = "DynamicCast" }
614614

@@ -631,7 +631,7 @@ class UuidofOperator extends Expr, @uuidof {
631631
else result = "__uuidof(0)"
632632
}
633633

634-
override int getPrecedence() { result = 15 }
634+
override int getPrecedence() { result = 16 }
635635

636636
/** Gets the contained type. */
637637
Type getTypeOperand() { uuidof_bind(underlyingElement(this), unresolveElement(result)) }
@@ -669,7 +669,7 @@ class TypeidOperator extends Expr, @type_id {
669669

670670
override string toString() { result = "typeid ..." }
671671

672-
override int getPrecedence() { result = 16 }
672+
override int getPrecedence() { result = 17 }
673673

674674
override predicate mayBeImpure() { this.getExpr().mayBeImpure() }
675675

@@ -700,7 +700,7 @@ class SizeofPackOperator extends Expr, @sizeof_pack {
700700
* A C/C++ sizeof expression.
701701
*/
702702
abstract class SizeofOperator extends Expr, @runtime_sizeof {
703-
override int getPrecedence() { result = 15 }
703+
override int getPrecedence() { result = 16 }
704704
}
705705

706706
/**
@@ -763,7 +763,7 @@ class SizeofTypeOperator extends SizeofOperator {
763763
* A C++11 `alignof` expression.
764764
*/
765765
abstract class AlignofOperator extends Expr, @runtime_alignof {
766-
override int getPrecedence() { result = 15 }
766+
override int getPrecedence() { result = 16 }
767767
}
768768

769769
/**

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ class AddressOfExpr extends UnaryOperation, @address_of {
642642

643643
override string getOperator() { result = "&" }
644644

645-
override int getPrecedence() { result = 15 }
645+
override int getPrecedence() { result = 16 }
646646

647647
override predicate mayBeImpure() { this.getOperand().mayBeImpure() }
648648

@@ -664,7 +664,7 @@ class ReferenceToExpr extends Conversion, @reference_to {
664664

665665
override string getCanonicalQLClass() { result = "ReferenceToExpr" }
666666

667-
override int getPrecedence() { result = 15 }
667+
override int getPrecedence() { result = 16 }
668668
}
669669

670670
/**
@@ -687,7 +687,7 @@ class PointerDereferenceExpr extends UnaryOperation, @indirect {
687687

688688
override string getOperator() { result = "*" }
689689

690-
override int getPrecedence() { result = 15 }
690+
override int getPrecedence() { result = 16 }
691691

692692
override predicate mayBeImpure() {
693693
this.getChild(0).mayBeImpure() or
@@ -721,7 +721,7 @@ class ReferenceDereferenceExpr extends Conversion, @ref_indirect {
721721
* A C++ `new` or `new[]` expression.
722722
*/
723723
class NewOrNewArrayExpr extends Expr, @any_new_expr {
724-
override int getPrecedence() { result = 15 }
724+
override int getPrecedence() { result = 16 }
725725

726726
/**
727727
* Gets the `operator new` or `operator new[]` that allocates storage.
@@ -898,7 +898,7 @@ class DeleteExpr extends Expr, @delete_expr {
898898

899899
override string getCanonicalQLClass() { result = "DeleteExpr" }
900900

901-
override int getPrecedence() { result = 15 }
901+
override int getPrecedence() { result = 16 }
902902

903903
/**
904904
* Gets the compile-time type of the object being deleted.
@@ -972,7 +972,7 @@ class DeleteArrayExpr extends Expr, @delete_array_expr {
972972

973973
override string getCanonicalQLClass() { result = "DeleteArrayExpr" }
974974

975-
override int getPrecedence() { result = 15 }
975+
override int getPrecedence() { result = 16 }
976976

977977
/**
978978
* Gets the element type of the array being deleted.
@@ -1216,3 +1216,18 @@ private predicate constantTemplateLiteral(Expr e) {
12161216
or
12171217
constantTemplateLiteral(e.(Cast).getExpr())
12181218
}
1219+
1220+
/**
1221+
* A C++ three-way comparison operation, also known as the _spaceship
1222+
* operation_. This is specific to C++20 and later.
1223+
* ```
1224+
* auto c = (a <=> b);
1225+
* ```
1226+
*/
1227+
class SpaceshipExpr extends BinaryOperation, @spaceshipexpr {
1228+
override string getCanonicalQLClass() { result = "SpaceshipExpr" }
1229+
1230+
override int getPrecedence() { result = 11 }
1231+
1232+
override string getOperator() { result = "<=>" }
1233+
}

cpp/ql/src/semmle/code/cpp/exprs/LogicalOperation.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class NotExpr extends UnaryLogicalOperation, @notexpr {
1616

1717
override string getCanonicalQLClass() { result = "NotExpr" }
1818

19-
override int getPrecedence() { result = 15 }
19+
override int getPrecedence() { result = 16 }
2020
}
2121

2222
/**

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ funbind(
12311231
| @ltexpr
12321232
| @geexpr
12331233
| @leexpr
1234+
| @spaceshipexpr
12341235
;
12351236

12361237
@bin_bitwise_op_expr = @lshiftexpr
@@ -1636,6 +1637,7 @@ case @expr.kind of
16361637
| 323 = @vec_fill
16371638
| 324 = @builtinconvertvector
16381639
| 325 = @builtincomplex
1640+
| 326 = @spaceshipexpr
16391641
;
16401642

16411643
new_allocated_type(

0 commit comments

Comments
 (0)