Skip to content

Commit 2517371

Browse files
authored
Merge pull request github#8933 from MathiasVP/revert-globals
C++: Revert github#8515
2 parents db85679 + 75c1e56 commit 2517371

Some content is hidden

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

44 files changed

+76
-553
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ class Expr extends StmtParent, @expr {
4949
/** Gets the enclosing variable of this expression, if any. */
5050
Variable getEnclosingVariable() { result = exprEnclosingElement(this) }
5151

52-
/** Gets the enclosing variable or function of this expression. */
53-
Declaration getEnclosingDeclaration() { result = exprEnclosingElement(this) }
54-
5552
/** Gets a child of this expression. */
5653
Expr getAChild() { exists(int n | result = this.getChild(n)) }
5754

cpp/ql/lib/semmle/code/cpp/ir/implementation/IRConfiguration.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class IRConfiguration extends TIRConfiguration {
1616
/**
1717
* Holds if IR should be created for function `func`. By default, holds for all functions.
1818
*/
19-
predicate shouldCreateIRForFunction(Language::Declaration func) { any() }
19+
predicate shouldCreateIRForFunction(Language::Function func) { any() }
2020

2121
/**
2222
* Holds if the strings used as part of an IR dump should be generated for function `func`.
@@ -25,7 +25,7 @@ class IRConfiguration extends TIRConfiguration {
2525
* of debug strings for IR that will not be dumped. We still generate the actual IR for these
2626
* functions, however, to preserve the results of any interprocedural analysis.
2727
*/
28-
predicate shouldEvaluateDebugStringsForFunction(Language::Declaration func) { any() }
28+
predicate shouldEvaluateDebugStringsForFunction(Language::Function func) { any() }
2929
}
3030

3131
private newtype TIREscapeAnalysisConfiguration = MkIREscapeAnalysisConfiguration()

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/IRBlock.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class IRBlockBase extends TIRBlock {
9797
/**
9898
* Gets the `Function` that contains this block.
9999
*/
100-
final Language::Declaration getEnclosingFunction() {
100+
final Language::Function getEnclosingFunction() {
101101
result = getFirstInstruction(this).getEnclosingFunction()
102102
}
103103
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class Instruction extends Construction::TStageInstruction {
194194
/**
195195
* Gets the function that contains this instruction.
196196
*/
197-
final Language::Declaration getEnclosingFunction() {
197+
final Language::Function getEnclosingFunction() {
198198
result = this.getEnclosingIRFunction().getFunction()
199199
}
200200

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ class PrintIRConfiguration extends TPrintIRConfiguration {
2626
* Holds if the IR for `func` should be printed. By default, holds for all
2727
* functions.
2828
*/
29-
predicate shouldPrintFunction(Language::Declaration decl) { any() }
29+
predicate shouldPrintFunction(Language::Function func) { any() }
3030
}
3131

3232
/**
3333
* Override of `IRConfiguration` to only evaluate debug strings for the functions that are to be dumped.
3434
*/
3535
private class FilteredIRConfiguration extends IRConfiguration {
36-
override predicate shouldEvaluateDebugStringsForFunction(Language::Declaration func) {
36+
override predicate shouldEvaluateDebugStringsForFunction(Language::Function func) {
3737
shouldPrintFunction(func)
3838
}
3939
}
4040

41-
private predicate shouldPrintFunction(Language::Declaration decl) {
42-
exists(PrintIRConfiguration config | config.shouldPrintFunction(decl))
41+
private predicate shouldPrintFunction(Language::Function func) {
42+
exists(PrintIRConfiguration config | config.shouldPrintFunction(func))
4343
}
4444

4545
private string getAdditionalInstructionProperty(Instruction instr, string key) {

cpp/ql/lib/semmle/code/cpp/ir/implementation/internal/IRFunctionBase.qll

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,23 @@
55
private import IRFunctionBaseInternal
66

77
private newtype TIRFunction =
8-
TFunctionIRFunction(Language::Function func) { IRConstruction::Raw::functionHasIR(func) } or
9-
TVarInitIRFunction(Language::GlobalVariable var) { IRConstruction::Raw::varHasIRFunc(var) }
8+
MkIRFunction(Language::Function func) { IRConstruction::Raw::functionHasIR(func) }
109

1110
/**
1211
* The IR for a function. This base class contains only the predicates that are the same between all
1312
* phases of the IR. Each instantiation of `IRFunction` extends this class.
1413
*/
1514
class IRFunctionBase extends TIRFunction {
16-
Language::Declaration decl;
15+
Language::Function func;
1716

18-
IRFunctionBase() {
19-
this = TFunctionIRFunction(decl)
20-
or
21-
this = TVarInitIRFunction(decl)
22-
}
17+
IRFunctionBase() { this = MkIRFunction(func) }
2318

2419
/** Gets a textual representation of this element. */
25-
final string toString() { result = "IR: " + decl.toString() }
20+
final string toString() { result = "IR: " + func.toString() }
2621

2722
/** Gets the function whose IR is represented. */
28-
final Language::Declaration getFunction() { result = decl }
23+
final Language::Function getFunction() { result = func }
2924

3025
/** Gets the location of the function. */
31-
final Language::Location getLocation() { result = decl.getLocation() }
26+
final Language::Location getLocation() { result = func.getLocation() }
3227
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/IRBlock.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class IRBlockBase extends TIRBlock {
9797
/**
9898
* Gets the `Function` that contains this block.
9999
*/
100-
final Language::Declaration getEnclosingFunction() {
100+
final Language::Function getEnclosingFunction() {
101101
result = getFirstInstruction(this).getEnclosingFunction()
102102
}
103103
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class Instruction extends Construction::TStageInstruction {
194194
/**
195195
* Gets the function that contains this instruction.
196196
*/
197-
final Language::Declaration getEnclosingFunction() {
197+
final Language::Function getEnclosingFunction() {
198198
result = this.getEnclosingIRFunction().getFunction()
199199
}
200200

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ class PrintIRConfiguration extends TPrintIRConfiguration {
2626
* Holds if the IR for `func` should be printed. By default, holds for all
2727
* functions.
2828
*/
29-
predicate shouldPrintFunction(Language::Declaration decl) { any() }
29+
predicate shouldPrintFunction(Language::Function func) { any() }
3030
}
3131

3232
/**
3333
* Override of `IRConfiguration` to only evaluate debug strings for the functions that are to be dumped.
3434
*/
3535
private class FilteredIRConfiguration extends IRConfiguration {
36-
override predicate shouldEvaluateDebugStringsForFunction(Language::Declaration func) {
36+
override predicate shouldEvaluateDebugStringsForFunction(Language::Function func) {
3737
shouldPrintFunction(func)
3838
}
3939
}
4040

41-
private predicate shouldPrintFunction(Language::Declaration decl) {
42-
exists(PrintIRConfiguration config | config.shouldPrintFunction(decl))
41+
private predicate shouldPrintFunction(Language::Function func) {
42+
exists(PrintIRConfiguration config | config.shouldPrintFunction(func))
4343
}
4444

4545
private string getAdditionalInstructionProperty(Instruction instr, string key) {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ module Raw {
3535
cached
3636
predicate functionHasIR(Function func) { exists(getTranslatedFunction(func)) }
3737

38-
cached
39-
predicate varHasIRFunc(GlobalOrNamespaceVariable var) { any() } // TODO: restrict?
40-
4138
cached
4239
predicate hasInstruction(TranslatedElement element, InstructionTag tag) {
4340
element.hasInstruction(_, tag, _)
@@ -49,18 +46,18 @@ module Raw {
4946
}
5047

5148
cached
52-
predicate hasTempVariable(Declaration decl, Locatable ast, TempVariableTag tag, CppType type) {
49+
predicate hasTempVariable(Function func, Locatable ast, TempVariableTag tag, CppType type) {
5350
exists(TranslatedElement element |
5451
element.getAst() = ast and
55-
decl = element.getFunction() and
52+
func = element.getFunction() and
5653
element.hasTempVariable(tag, type)
5754
)
5855
}
5956

6057
cached
61-
predicate hasStringLiteral(Declaration decl, Locatable ast, CppType type, StringLiteral literal) {
58+
predicate hasStringLiteral(Function func, Locatable ast, CppType type, StringLiteral literal) {
6259
literal = ast and
63-
literal.getEnclosingDeclaration() = decl and
60+
literal.getEnclosingFunction() = func and
6461
getTypeForPRValue(literal.getType()) = type
6562
}
6663

0 commit comments

Comments
 (0)