C++: restrict global variable IR generation

This commit is contained in:
Robert Marsh
2022-05-03 16:50:53 -04:00
parent 7818dafecc
commit 33910a85b9
9 changed files with 10 additions and 31 deletions

View File

@@ -37,7 +37,14 @@ module Raw {
predicate functionHasIR(Function func) { exists(getTranslatedFunction(func)) }
cached
predicate varHasIRFunc(GlobalOrNamespaceVariable var) { any() } // TODO: restrict?
predicate varHasIRFunc(GlobalOrNamespaceVariable var) {
var.hasInitializer() and
(
not var.getType().isDeeplyConst()
or
var.getInitializer().getExpr() instanceof StringLiteral
)
}
cached
predicate hasInstruction(TranslatedElement element, InstructionTag tag) {

View File

@@ -119,7 +119,7 @@ private predicate ignoreExprOnly(Expr expr) {
exists(NewOrNewArrayExpr new | expr = new.getAllocatorCall().getArgument(0))
or
not translateFunction(expr.getEnclosingFunction()) and
not expr.getEnclosingVariable() instanceof GlobalOrNamespaceVariable
not Raw::varHasIRFunc(expr.getEnclosingVariable())
or
// We do not yet translate destructors properly, so for now we ignore the
// destructor call. We do, however, translate the expression being
@@ -665,7 +665,7 @@ newtype TTranslatedElement =
} or
// The side effect that initializes newly-allocated memory.
TTranslatedAllocationSideEffect(AllocationExpr expr) { not ignoreSideEffects(expr) } or
TTranslatedGlobalOrNamespaceVarInit(GlobalOrNamespaceVariable var) { var.hasInitializer() }
TTranslatedGlobalOrNamespaceVarInit(GlobalOrNamespaceVariable var) { Raw::varHasIRFunc(var) }
/**
* Gets the index of the first explicitly initialized element in `initList`

View File

@@ -8470,11 +8470,6 @@
| ir.cpp:1821:16:1821:16 | ChiPartial | partial:m1821_5 |
| ir.cpp:1821:16:1821:16 | ChiTotal | total:m1821_2 |
| ir.cpp:1821:16:1821:16 | StoreValue | r1821_4 |
| ir.cpp:1823:11:1823:18 | Address | &:r1823_3 |
| ir.cpp:1823:11:1823:18 | SideEffect | ~m1823_6 |
| ir.cpp:1823:22:1823:22 | ChiPartial | partial:m1823_5 |
| ir.cpp:1823:22:1823:22 | ChiTotal | total:m1823_2 |
| ir.cpp:1823:22:1823:22 | StoreValue | r1823_4 |
| ir.cpp:1825:18:1825:25 | Address | &:r1825_3 |
| ir.cpp:1825:18:1825:25 | Arg(this) | this:r1825_3 |
| ir.cpp:1825:18:1825:25 | SideEffect | ~m1825_10 |

View File

@@ -9744,17 +9744,6 @@ ir.cpp:
# 1821| v1821_7(void) = AliasedUse : ~m?
# 1821| v1821_8(void) = ExitFunction :
# 1823| int const global_3
# 1823| Block 0
# 1823| v1823_1(void) = EnterFunction :
# 1823| mu1823_2(unknown) = AliasedDefinition :
# 1823| r1823_3(glval<int>) = VariableAddress[global_3] :
# 1823| r1823_4(int) = Constant[2] :
# 1823| mu1823_5(int) = Store[global_3] : &:r1823_3, r1823_4
# 1823| v1823_6(void) = ReturnVoid :
# 1823| v1823_7(void) = AliasedUse : ~m?
# 1823| v1823_8(void) = ExitFunction :
# 1825| constructor_only global_4
# 1825| Block 0
# 1825| v1825_1(void) = EnterFunction :

View File

@@ -1234,8 +1234,6 @@ ssa.cpp:
# 268| v268_14(void) = AliasedUse : ~m269_7
# 268| v268_15(void) = ExitFunction :
# 274| Point* pp
# 275| void EscapedButNotConflated(bool, Point, int)
# 275| Block 0
# 275| v275_1(void) = EnterFunction :

View File

@@ -1229,8 +1229,6 @@ ssa.cpp:
# 268| v268_14(void) = AliasedUse : ~m269_7
# 268| v268_15(void) = ExitFunction :
# 274| Point* pp
# 275| void EscapedButNotConflated(bool, Point, int)
# 275| Block 0
# 275| v275_1(void) = EnterFunction :

View File

@@ -1140,8 +1140,6 @@ ssa.cpp:
# 268| v268_13(void) = AliasedUse : ~m?
# 268| v268_14(void) = ExitFunction :
# 274| Point* pp
# 275| void EscapedButNotConflated(bool, Point, int)
# 275| Block 0
# 275| v275_1(void) = EnterFunction :

View File

@@ -1140,8 +1140,6 @@ ssa.cpp:
# 268| v268_13(void) = AliasedUse : ~m?
# 268| v268_14(void) = ExitFunction :
# 274| Point* pp
# 275| void EscapedButNotConflated(bool, Point, int)
# 275| Block 0
# 275| v275_1(void) = EnterFunction :

View File

@@ -941,10 +941,6 @@ test.cpp:
# 124| v124_13(void) = AliasedUse : m124_3
# 124| v124_14(void) = ExitFunction :
# 132| A* global_a
# 133| int global_n
# 135| void test_read_global_same()
# 135| Block 0
# 135| v135_1(void) = EnterFunction :