r271308 - [Coverage] Fix crash on a switch partially covered by a macro (PR27948)

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Tue May 31 11:06:20 PDT 2016


Author: vedantk
Date: Tue May 31 13:06:19 2016
New Revision: 271308

URL: http://llvm.org/viewvc/llvm-project?rev=271308&view=rev
Log:
[Coverage] Fix crash on a switch partially covered by a macro (PR27948)

We have to handle file exits before and after visiting regions in the
switch body. Fixes PR27948.

Modified:
    cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
    cfe/trunk/test/CoverageMapping/switchmacro.c

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=271308&r1=271307&r2=271308&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Tue May 31 13:06:19 2016
@@ -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) {

Modified: cfe/trunk/test/CoverageMapping/switchmacro.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/switchmacro.c?rev=271308&r1=271307&r2=271308&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/switchmacro.c (original)
+++ cfe/trunk/test/CoverageMapping/switchmacro.c Tue May 31 13:06:19 2016
@@ -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;




More information about the cfe-commits mailing list