]> granicus.if.org Git - clang/commitdiff
[Coverage] Fix crash on a switch partially covered by a macro (PR27948)
authorVedant Kumar <vsk@apple.com>
Tue, 31 May 2016 18:06:19 +0000 (18:06 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 31 May 2016 18:06:19 +0000 (18:06 +0000)
We have to handle file exits before and after visiting regions in the
switch body. Fixes PR27948.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271308 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CoverageMappingGen.cpp
test/CoverageMapping/switchmacro.c

index d3fd19c174591ee6e5b716cec68c089917c993f4..4650001f80d30cbbe32ca7f906e4111cd255afd9 100644 (file)
@@ -783,8 +783,10 @@ struct CounterCoverageMappingBuilder
           Visit(Child);
         popRegions(Index);
       }
-    } else
+    } else {
+      handleFileExit(getStart(Body));
       propagateCounts(Counter::getZero(), Body);
+    }
     BreakContinue BC = BreakContinueStack.pop_back_val();
 
     if (!BreakContinueStack.empty())
@@ -792,7 +794,9 @@ struct CounterCoverageMappingBuilder
           BreakContinueStack.back().ContinueCount, BC.ContinueCount);
 
     Counter ExitCount = getRegionCounter(S);
-    pushRegion(ExitCount, getStart(S), getEnd(S));
+    SourceLocation ExitLoc = getEnd(S);
+    pushRegion(ExitCount, getStart(S), ExitLoc);
+    handleFileExit(ExitLoc);
   }
 
   void VisitSwitchCase(const SwitchCase *S) {
index f2943b8ae4413ae1e346a37a49658269c71ed269..f83d26fd1688a6739e2a765b53357b7ee49b3336 100644 (file)
@@ -32,6 +32,14 @@ default: ;
   END
 }
 
+// PR27948 - Crash when handling a switch partially covered by a macro
+// CHECK: baz
+#define START2 switch (0) default:
+void baz() {
+  for (;;)
+    START2 return; // CHECK: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1 (Expanded file = 1)
+}
+
 int main(int argc, const char *argv[]) {
   foo(3);
   return 0;