Skip to content

Commit 9f1c7c4

Browse files
committed
C#: Remove assertion splitting.
1 parent f305a38 commit 9f1c7c4

File tree

1 file changed

+2
-134
lines changed
  • csharp/ql/lib/semmle/code/csharp/controlflow/internal

1 file changed

+2
-134
lines changed

csharp/ql/lib/semmle/code/csharp/controlflow/internal/Splitting.qll

Lines changed: 2 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@ private module Cached {
2424
cached
2525
newtype TSplitKind =
2626
TInitializerSplitKind() or
27-
TConditionalCompletionSplitKind() or
28-
TAssertionSplitKind()
27+
TConditionalCompletionSplitKind()
2928

3029
cached
3130
newtype TSplit =
3231
TInitializerSplit(Constructor c) { InitializerSplitting::constructorInitializes(c, _) } or
33-
TConditionalCompletionSplit(ConditionalCompletion c) or
34-
TAssertionSplit(AssertionSplitting::Assertion a, int i, boolean success) {
35-
exists(a.getExpr(i)) and
36-
success in [false, true]
37-
}
32+
TConditionalCompletionSplit(ConditionalCompletion c)
3833
}
3934

4035
import Cached
@@ -320,130 +315,3 @@ module ConditionalCompletionSplitting {
320315

321316
int getNextListOrder() { result = InitializerSplitting::getNextListOrder() + 1 }
322317
}
323-
324-
module AssertionSplitting {
325-
import semmle.code.csharp.commons.Assertions
326-
private import semmle.code.csharp.ExprOrStmtParent
327-
328-
private AstNode getAnAssertionDescendant(Assertion a) {
329-
result = a
330-
or
331-
result = getAnAssertionDescendant(a).getAChild()
332-
}
333-
334-
/**
335-
* A split for assertions. For example, in
336-
*
337-
* ```csharp
338-
* void M(int i)
339-
* {
340-
* Debug.Assert(i >= 0);
341-
* System.Console.WriteLine("i is positive")
342-
* }
343-
* ```
344-
*
345-
* we record whether `i >= 0` evaluates to `true` or `false`, and restrict the
346-
* edges out of the assertion accordingly.
347-
*/
348-
class AssertionSplit extends Split, TAssertionSplit {
349-
Assertion a;
350-
boolean success;
351-
int i;
352-
353-
AssertionSplit() { this = TAssertionSplit(a, i, success) }
354-
355-
/** Gets the assertion. */
356-
Assertion getAssertion() { result = a }
357-
358-
/** Holds if this split represents a successful assertion. */
359-
predicate isSuccess() { success = true }
360-
361-
override string toString() {
362-
success = true and result = "assertion success"
363-
or
364-
success = false and result = "assertion failure"
365-
}
366-
}
367-
368-
private class AssertionSplitKind extends SplitKind, TAssertionSplitKind {
369-
override int getListOrder() { result = ConditionalCompletionSplitting::getNextListOrder() }
370-
371-
override predicate isEnabled(AstNode cfe) { this.appliesTo(cfe) }
372-
373-
override string toString() { result = "Assertion" }
374-
}
375-
376-
int getNextListOrder() { result = ConditionalCompletionSplitting::getNextListOrder() + 1 }
377-
378-
private class AssertionSplitImpl extends SplitImpl instanceof AssertionSplit {
379-
Assertion a;
380-
boolean success;
381-
int i;
382-
383-
AssertionSplitImpl() { this = TAssertionSplit(a, i, success) }
384-
385-
override AssertionSplitKind getKind() { any() }
386-
387-
override predicate hasEntry(AstNode pred, AstNode succ, Completion c) {
388-
exists(AssertMethod m |
389-
last(a.getExpr(i), pred, c) and
390-
succ(pred, succ, c) and
391-
m = a.getAssertMethod() and
392-
// The assertion only succeeds when all asserted arguments succeeded, so
393-
// we only enter a "success" state after the last argument has succeeded.
394-
//
395-
// The split is only entered if we are not already in a "failing" state
396-
// for one of the previous arguments, which ensures that the "success"
397-
// state is only entered when all arguments succeed. This also means
398-
// that if multiple arguments fail, then the first failing argument
399-
// will determine the exception being thrown by the assertion.
400-
if success = true then i = max(int j | exists(a.getExpr(j))) else any()
401-
|
402-
exists(boolean b | i = m.(BooleanAssertMethod).getAnAssertionIndex(b) |
403-
c instanceof TrueCompletion and success = b
404-
or
405-
c instanceof FalseCompletion and success = b.booleanNot()
406-
)
407-
or
408-
exists(boolean b | i = m.(NullnessAssertMethod).getAnAssertionIndex(b) |
409-
c.(NullnessCompletion).isNull() and success = b
410-
or
411-
c.(NullnessCompletion).isNonNull() and success = b.booleanNot()
412-
)
413-
)
414-
}
415-
416-
override predicate hasEntryScope(CfgScope scope, AstNode first) { none() }
417-
418-
override predicate hasExit(AstNode pred, AstNode succ, Completion c) {
419-
this.appliesTo(pred) and
420-
pred = a and
421-
succ(pred, succ, c) and
422-
(
423-
success = true and
424-
c instanceof NormalCompletion
425-
or
426-
success = false and
427-
c = assertionCompletion(a, i)
428-
)
429-
}
430-
431-
override predicate hasExitScope(CfgScope scope, AstNode last, Completion c) {
432-
this.appliesTo(last) and
433-
last = a and
434-
scopeLast(scope, last, c) and
435-
(
436-
success = true and
437-
c instanceof NormalCompletion
438-
or
439-
success = false and
440-
c = assertionCompletion(a, i)
441-
)
442-
}
443-
444-
override predicate hasSuccessor(AstNode pred, AstNode succ, Completion c) {
445-
this.appliesSucc(pred, succ, c) and
446-
succ = getAnAssertionDescendant(a)
447-
}
448-
}
449-
}

0 commit comments

Comments
 (0)