@@ -146,6 +146,10 @@ private Sentence CurrentSentence
146146 /// </summary>
147147 private List < Sentence > AllSentences ;
148148
149+ /// <summary>
150+ /// Stores all node statements encountered during building. The associated bool indicates
151+ /// whether the statement is reachable or not, <see cref="DetectUnreachableCode" />.
152+ /// </summary>
149153 private Dictionary < Node , bool > AllStatements ;
150154
151155 /// <summary>
@@ -1348,21 +1352,18 @@ private void DetectUnreachableCode()
13481352 if ( ! statement . Value )
13491353 {
13501354 //Statement is unreachable, collect block
1351- var block = this . CurrentProgramCfgBuilder . Cfg . BlockFor [ statement . Key ] ;
1352- unreachableBlocks . Add ( block . Index ) ;
1353- }
1354- }
1355-
1356- //Create warnings on first instruction of every unreachable block
1357- //TODO We should report unreachable ranges instead, waiting for #1846 to be solved first...
1358- foreach ( var unreachableBlockIndex in unreachableBlocks )
1359- {
1360- var unreachableBlock = this . CurrentProgramCfgBuilder . Cfg . AllBlocks [ unreachableBlockIndex ] ;
1361- this . CurrentProgramCfgBuilder . Cfg . AddUnreachableBlock ( unreachableBlock ) ;
1355+ var unreachableBlock = this . CurrentProgramCfgBuilder . Cfg . BlockFor [ statement . Key ] ;
1356+ if ( unreachableBlocks . Add ( unreachableBlock . Index ) )
1357+ {
1358+ this . CurrentProgramCfgBuilder . Cfg . AddUnreachableBlock ( unreachableBlock ) ;
13621359
1363- var firstInstruction = unreachableBlock . Instructions . First . Value ;
1364- var diagnostic = new Diagnostic ( MessageCode . Warning , firstInstruction . CodeElement . Position ( ) , "Unreachable code detected" ) ;
1365- AddDiagnostic ( diagnostic ) ;
1360+ //Create warning on first instruction of unreachable block
1361+ //TODO We should report unreachable ranges instead, waiting for #1846 to be solved first...
1362+ var firstInstruction = unreachableBlock . Instructions . First . Value ;
1363+ var diagnostic = new Diagnostic ( MessageCode . Warning , firstInstruction . CodeElement . Position ( ) , "Unreachable code detected" ) ;
1364+ AddDiagnostic ( diagnostic ) ;
1365+ }
1366+ }
13661367 }
13671368
13681369 this . CurrentProgramCfgBuilder . AllStatements = null ;
0 commit comments