From e0c001cbf6021ae5bf488457bbd2b6118b9aedc1 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 31 May 2016 18:06:19 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271308 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CoverageMappingGen.cpp | 8 ++++++-- test/CoverageMapping/switchmacro.c | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index d3fd19c174..4650001f80 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/lib/CodeGen/CoverageMappingGen.cpp @@ -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) { diff --git a/test/CoverageMapping/switchmacro.c b/test/CoverageMapping/switchmacro.c index f2943b8ae4..f83d26fd16 100644 --- a/test/CoverageMapping/switchmacro.c +++ b/test/CoverageMapping/switchmacro.c @@ -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; -- 2.40.0