Skip to content

Commit 31f3504

Browse files
committed
C++: Remove this bad materialization:
``` Evaluated relational algebra for predicate _CppType#d1355c92::CppType::hasUnspecifiedType#2#dispred#fff_10#join_rhs_SsaInternals#50208335::DefO__#shared@ec353boa with tuple counts: 459594 ~0% {2} r1 = JOIN _IRVariable#e9bf30b2::IRVariable::getAst#0#dispred#ff_Parameter#ed81dd8f::Parameter#f#shared WITH SsaInternalsCommon#3c4fa02d::BaseIRVariable::getIRVariable#0#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Lhs.1 'arg1', Rhs.1 461383 ~2% {3} r2 = JOIN r1 WITH Variable#7a968d4e::Variable::getUnspecifiedType#0#dispred#ff ON FIRST 1 OUTPUT Lhs.0 'arg1', Lhs.1, Rhs.1 477945 ~6% {4} r3 = JOIN r2 WITH Variable#7a968d4e::Variable::getUnspecifiedType#0#dispred#ff ON FIRST 1 OUTPUT Lhs.2, Lhs.0 'arg1', Lhs.1, Rhs.1 346338 ~2% {4} r4 = JOIN r3 WITH SsaInternalsCommon#3c4fa02d::Indirection::getNumberOfIndirections#0#dispred#ff ON FIRST 1 OUTPUT Lhs.3, Lhs.1 'arg1', Lhs.2, Rhs.1 'arg2' 178593374 ~0% {4} r5 = JOIN r4 WITH CppType#d1355c92::CppType::hasUnspecifiedType#2#dispred#fff_10#join_rhs ON FIRST 1 OUTPUT Lhs.2, Lhs.1 'arg1', Lhs.3 'arg2', Rhs.1 'arg3' 934806228 ~0% {4} r6 = JOIN r5 WITH SsaInternals#50208335::DefOrUse::getSourceVariable#0#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1 'arg0', Lhs.1 'arg1', Lhs.2 'arg2', Lhs.3 'arg3' return r6 Tuple counts for _DataFlowPrivate#fbdd7bd7::InstructionNode0#class#ff_SsaInternals#50208335::Def#ff_SsaInternals#5020__#antijoin_rhs/4@305d42l5 after 25.6s: 180185672 ~0% {4} r1 = JOIN _CppType#d1355c92::CppType::hasUnspecifiedType#2#dispred#fff_10#join_rhs_SsaInternals#50208335::DefO__#shared WITH SsaInternals#50208335::Def#ff ON FIRST 1 OUTPUT Lhs.0 'arg3', Lhs.1 'arg0', Lhs.2 'arg1', Lhs.3 'arg2' 180185672 ~0% {5} r2 = JOIN r1 WITH SsaInternals#50208335::Def::getValue#0#dispred#ff ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'arg0', Lhs.2 'arg1', Lhs.3 'arg2', Lhs.0 'arg3' 180185672 ~0% {5} r3 = JOIN r2 WITH DataFlowPrivate#fbdd7bd7::InstructionNode0#class#ff ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'arg0', Lhs.2 'arg1', Lhs.3 'arg2', Lhs.4 'arg3' 178459578 ~1% {4} r4 = JOIN r3 WITH project#Instruction#577b6a83::InitializeParameterInstruction#ff ON FIRST 1 OUTPUT Lhs.1 'arg0', Lhs.2 'arg1', Lhs.3 'arg2', Lhs.4 'arg3' return r4 Tuple counts for SsaInternals#7b362d2f::TFinalParameterUse#dom#ff/2@9ff4dbcg after 7.9s: 180185672 ~1% {4} r1 = JOIN _CppType#d1355c92::CppType::hasUnspecifiedType#2#dispred#fff_10#join_rhs_SsaInternals#50208335::DefO__#shared WITH SsaInternals#50208335::Def#ff ON FIRST 1 OUTPUT Lhs.1 'p', Lhs.2, Lhs.3, Lhs.0 1726094 ~0% {4} r2 = r1 AND NOT _DataFlowPrivate#fbdd7bd7::InstructionNode0#class#ff_SsaInternals#50208335::Def#ff_SsaInternals#5020__#antijoin_rhs(Lhs.0 'p', Lhs.1, Lhs.2, Lhs.3) 1726094 ~54% {4} r3 = SCAN r2 OUTPUT In.0 'p', In.1, In.2, 1 1769636 ~54% {5} r4 = JOIN r3 WITH PRIMITIVE range#bbf ON Lhs.3,Lhs.1 1769636 ~45% {4} r5 = SCAN r4 OUTPUT In.2, (In.4 'indirectionIndex' + 1), In.0 'p', In.4 'indirectionIndex' 591253 ~11541% {2} r6 = JOIN r5 WITH SsaInternalsCommon#3c4fa02d::isModifiableAtImpl#2#ff ON FIRST 2 OUTPUT Lhs.2 'p', Lhs.3 'indirectionIndex' 1769636 ~52% {4} r7 = SCAN r4 OUTPUT In.2, In.0 'p', In.4 'indirectionIndex', (In.4 'indirectionIndex' + 1) 1724893 ~41% {5} r8 = JOIN r7 WITH CppType#d1355c92::CppType::hasType#2#dispred#fff ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'p', Lhs.0, Lhs.2 'indirectionIndex', Lhs.3 1718843 ~46% {5} r9 = JOIN r8 WITH Type#2e8eb3ef::Type::stripType#0#dispred#ff ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'p', Lhs.2, Lhs.3 'indirectionIndex', Lhs.4 8608 ~0% {5} r10 = JOIN r9 WITH SmartPointer#917721ba::SmartPtr#f ON FIRST 1 OUTPUT Lhs.1 'p', Lhs.2, Lhs.3 'indirectionIndex', Lhs.4, Lhs.0 8608 ~0% {5} r11 = r10 AND NOT PointerWrapper#7cc81d2d::PointerWrapper::pointsToConst#0#dispred#f(Lhs.4) 8608 ~4986% {2} r12 = SCAN r11 OUTPUT In.0 'p', In.2 'indirectionIndex' 599861 ~11711% {2} r13 = r6 UNION r12 return r13 ```
1 parent 354a12c commit 31f3504

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,21 @@ private newtype TDefOrUseImpl =
169169
// Avoid creating parameter nodes if there is no definitions of the variable other than the initializaion.
170170
exists(SsaInternals0::Def def |
171171
def.getSourceVariable().getBaseVariable().(BaseIRVariable).getIRVariable().getAst() = p and
172-
not def.getValue().asInstruction() instanceof InitializeParameterInstruction
173-
) and
174-
// If the type is modifiable
175-
exists(CppType cppType |
176-
cppType.hasUnspecifiedType(p.getUnspecifiedType(), _) and
177-
isModifiableAt(cppType, indirectionIndex + 1)
178-
) and
179-
exists(Indirection indirection |
180-
indirection.getType() = p.getUnspecifiedType() and
181-
indirectionIndex = [1 .. indirection.getNumberOfIndirections()]
172+
not def.getValue().asInstruction() instanceof InitializeParameterInstruction and
173+
unspecifiedTypeIsModifiableAt(p.getUnspecifiedType(), indirectionIndex)
182174
)
183175
}
184176

177+
private predicate unspecifiedTypeIsModifiableAt(Type unspecified, int indirectionIndex) {
178+
indirectionIndex = [1 .. getIndirectionForUnspecifiedType(unspecified).getNumberOfIndirections()] and
179+
exists(CppType cppType |
180+
cppType.hasUnspecifiedType(unspecified, _) and
181+
isModifiableAt(cppType, indirectionIndex + 1)
182+
)
183+
}
184+
185+
private Indirection getIndirectionForUnspecifiedType(Type t) { result.getType() = t }
186+
185187
abstract private class DefOrUseImpl extends TDefOrUseImpl {
186188
/** Gets a textual representation of this element. */
187189
abstract string toString();

0 commit comments

Comments
 (0)