Skip to content

Commit 6400492

Browse files
committed
C++: Use a more declarative predicate name
1 parent 903f376 commit 6400492

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

cpp/ql/lib/semmle/code/cpp/internal/ExtractorVersion.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ string getExtractorCodeQLVersion() { extractor_version(result, _) }
88

99
/** Get the extractor frontend version */
1010
string getExtractorFrontendVersion() { extractor_version(_, result) }
11+
12+
predicate isExtractorFrontendVersion65OrHigher() {
13+
// Version numbers we not included in the database before 6.5.
14+
exists(getExtractorCodeQLVersion())
15+
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ predicate ignoreLoad(Expr expr) {
363363
expr instanceof FunctionAccess
364364
or
365365
// The load is duplicated from the operand.
366-
exists(getExtractorFrontendVersion()) and expr instanceof ParenthesisExpr
366+
isExtractorFrontendVersion65OrHigher() and expr instanceof ParenthesisExpr
367367
or
368368
// The load is duplicated from the right operand.
369-
exists(getExtractorFrontendVersion()) and expr instanceof CommaExpr
369+
isExtractorFrontendVersion65OrHigher() and expr instanceof CommaExpr
370370
or
371371
expr.(PointerDereferenceExpr).getOperand().getFullyConverted().getType().getUnspecifiedType()
372372
instanceof FunctionPointerType

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ class TranslatedPrefixCrementOperation extends TranslatedCrementOperation {
652652
override Instruction getResult() {
653653
// The following distinction is needed to work around extractor limitations
654654
// in old versions of the extractor.
655-
if expr.isPRValueCategory() and not exists(getExtractorFrontendVersion())
655+
if expr.isPRValueCategory() and not isExtractorFrontendVersion65OrHigher()
656656
then
657657
// If this is C, then the result of a prefix crement is a prvalue for the
658658
// new value assigned to the operand. If this is C++, then the result is
@@ -1509,7 +1509,7 @@ class TranslatedAssignExpr extends TranslatedNonConstantExpr {
15091509
final override Instruction getResult() {
15101510
// The following distinction is needed to work around extractor limitations
15111511
// in old versions of the extractor.
1512-
if expr.isPRValueCategory() and not exists(getExtractorFrontendVersion())
1512+
if expr.isPRValueCategory() and not isExtractorFrontendVersion65OrHigher()
15131513
then
15141514
// If this is C, then the result of an assignment is a prvalue for the new
15151515
// value assigned to the left operand. If this is C++, then the result is
@@ -1649,7 +1649,7 @@ class TranslatedAssignOperation extends TranslatedNonConstantExpr {
16491649
final override Instruction getResult() {
16501650
// The following distinction is needed to work around extractor limitations
16511651
// in old versions of the extractor.
1652-
if expr.isPRValueCategory() and not exists(getExtractorFrontendVersion())
1652+
if expr.isPRValueCategory() and not isExtractorFrontendVersion65OrHigher()
16531653
then
16541654
// If this is C, then the result of an assignment is a prvalue for the new
16551655
// value assigned to the left operand. If this is C++, then the result is
@@ -2198,7 +2198,7 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
21982198
not this.elseIsVoid() and tag = ConditionValueFalseStoreTag()
21992199
) and
22002200
opcode instanceof Opcode::Store and
2201-
if exists(getExtractorFrontendVersion())
2201+
if isExtractorFrontendVersion65OrHigher()
22022202
then
22032203
not expr.hasLValueToRValueConversion() and
22042204
resultType = this.getResultType()
@@ -2207,7 +2207,7 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
22072207
resultType = getTypeForPRValue(expr.getType())
22082208
else resultType = this.getResultType()
22092209
or
2210-
(not expr.hasLValueToRValueConversion() or not exists(getExtractorFrontendVersion())) and
2210+
(not expr.hasLValueToRValueConversion() or not isExtractorFrontendVersion65OrHigher()) and
22112211
tag = ConditionValueResultLoadTag() and
22122212
opcode instanceof Opcode::Load and
22132213
resultType = this.getResultType()
@@ -2237,7 +2237,7 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
22372237
)
22382238
or
22392239
tag = ConditionValueResultTempAddressTag() and
2240-
if exists(getExtractorFrontendVersion())
2240+
if isExtractorFrontendVersion65OrHigher()
22412241
then
22422242
not expr.hasLValueToRValueConversion() and
22432243
result = this.getInstruction(ConditionValueResultLoadTag())
@@ -2246,7 +2246,7 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
22462246
result = this.getParent().getChildSuccessor(this)
22472247
else result = this.getInstruction(ConditionValueResultLoadTag())
22482248
or
2249-
(not expr.hasLValueToRValueConversion() or not exists(getExtractorFrontendVersion())) and
2249+
(not expr.hasLValueToRValueConversion() or not isExtractorFrontendVersion65OrHigher()) and
22502250
tag = ConditionValueResultLoadTag() and
22512251
result = this.getParent().getChildSuccessor(this)
22522252
)
@@ -2275,7 +2275,7 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
22752275
result = this.getElse().getResult()
22762276
)
22772277
or
2278-
(not expr.hasLValueToRValueConversion() or not exists(getExtractorFrontendVersion())) and
2278+
(not expr.hasLValueToRValueConversion() or not isExtractorFrontendVersion65OrHigher()) and
22792279
tag = ConditionValueResultLoadTag() and
22802280
operandTag instanceof AddressOperandTag and
22812281
result = this.getInstruction(ConditionValueResultTempAddressTag())
@@ -2285,7 +2285,7 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
22852285
final override predicate hasTempVariable(TempVariableTag tag, CppType type) {
22862286
not this.resultIsVoid() and
22872287
tag = ConditionValueTempVar() and
2288-
if exists(getExtractorFrontendVersion())
2288+
if isExtractorFrontendVersion65OrHigher()
22892289
then
22902290
not expr.hasLValueToRValueConversion() and
22912291
type = this.getResultType()
@@ -2307,7 +2307,7 @@ abstract class TranslatedConditionalExpr extends TranslatedNonConstantExpr {
23072307

23082308
final override Instruction getResult() {
23092309
not this.resultIsVoid() and
2310-
if exists(getExtractorFrontendVersion())
2310+
if isExtractorFrontendVersion65OrHigher()
23112311
then
23122312
expr.hasLValueToRValueConversion() and
23132313
result = this.getInstruction(ConditionValueResultTempAddressTag())
@@ -3277,14 +3277,14 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
32773277
(
32783278
not expr.isPRValueCategory() // is C++
32793279
or
3280-
exists(getExtractorFrontendVersion())
3280+
isExtractorFrontendVersion65OrHigher()
32813281
)
32823282
or
32833283
expr instanceof PrefixCrementOperation and
32843284
(
32853285
not expr.isPRValueCategory() // is C++
32863286
or
3287-
exists(getExtractorFrontendVersion())
3287+
isExtractorFrontendVersion65OrHigher()
32883288
)
32893289
or
32903290
// Because the load is on the `e` in `e++`.

0 commit comments

Comments
 (0)