summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2015-04-24 23:37:57 +0000
committerJustin Bogner <mail@justinbogner.com>2015-04-24 23:37:57 +0000
commite3654ce7abc781fed9fd42fffb1bec23ef05a070 (patch)
tree6c26cfde6a98112aa6196bc0178bdc9660ed6db6 /clang
parent8c384bbb3563a2a62fc19cf6044b1effd69e19db (diff)
downloadbcm5719-llvm-e3654ce7abc781fed9fd42fffb1bec23ef05a070.tar.gz
bcm5719-llvm-e3654ce7abc781fed9fd42fffb1bec23ef05a070.zip
InstrProf: Fix coverage maps for conditional operators
This fixes a crash when we're emitting coverage and a macro appears between two binary conditional operators, ie, "foo ?: MACRO ?: bar", and fixes the interaction of macros and conditional operators in general. llvm-svn: 235793
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CoverageMappingGen.cpp8
-rw-r--r--clang/test/CoverageMapping/macro-expressions.cpp16
2 files changed, 22 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index d26eceded3c..11b9478262a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -830,7 +830,13 @@ struct CounterCoverageMappingBuilder
Counter ParentCount = getRegion().getCounter();
Counter TrueCount = getRegionCounter(E);
- propagateCounts(TrueCount, E->getTrueExpr());
+ Visit(E->getCond());
+
+ if (!isa<BinaryConditionalOperator>(E)) {
+ extendRegion(E->getTrueExpr());
+ propagateCounts(TrueCount, E->getTrueExpr());
+ }
+ extendRegion(E->getFalseExpr());
propagateCounts(subtractCounters(ParentCount, TrueCount),
E->getFalseExpr());
}
diff --git a/clang/test/CoverageMapping/macro-expressions.cpp b/clang/test/CoverageMapping/macro-expressions.cpp
index 00e273bd783..1085ab02492 100644
--- a/clang/test/CoverageMapping/macro-expressions.cpp
+++ b/clang/test/CoverageMapping/macro-expressions.cpp
@@ -44,9 +44,20 @@ void foo(int i) {
// CHECK-NEXT: File 0, [[@LINE+1]]:42 -> [[@LINE+1]]:44 = #7
for (DECL(int, j) : ARR(int, 1, 2, 3)) {}
- // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = #8
+ // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = #0
// CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:23 -> [[@LINE+1]]:29 = #0
(void)(i ? PRIo64 : PRIu64);
+
+ // CHECK-NEXT: File 0, [[@LINE+5]]:14 -> [[@LINE+5]]:15 = #9
+ // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:22 = (#0 - #9)
+ // CHECK-NEXT: File 0, [[@LINE+3]]:22 -> [[@LINE+3]]:33 = (#0 - #9)
+ // CHECK-NEXT: File 0, [[@LINE+2]]:28 -> [[@LINE+2]]:29 = #10
+ // CHECK-NEXT: File 0, [[@LINE+1]]:32 -> [[@LINE+1]]:33 = ((#0 - #9) - #10)
+ (void)(i ? i : EXPR(i) ? i : 0);
+ // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:15 -> [[@LINE+3]]:19 = (#0 - #11)
+ // CHECK-NEXT: File 0, [[@LINE+2]]:19 -> [[@LINE+2]]:27 = (#0 - #11)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:26 -> [[@LINE+1]]:27 = ((#0 - #11) - #12)
+ (void)(i ?: EXPR(i) ?: 0);
}
// CHECK-NEXT: File {{[0-9]+}}, 3:17 -> 3:20 = #0
@@ -60,11 +71,14 @@ void foo(int i) {
// CHECK-NEXT: File {{[0-9]+}}, 4:18 -> 4:22 = (#0 + #6)
// CHECK-NEXT: File {{[0-9]+}}, 5:20 -> 5:23 = #0
// CHECK-NEXT: File {{[0-9]+}}, 9:25 -> 9:40 = #0
+// CHECK-NEXT: File {{[0-9]+}}, 12:16 -> 12:42 = #0
// CHECK-NEXT: Expansion,File {{[0-9]+}}, 12:16 -> 12:38 = #8
// CHECK-NEXT: File {{[0-9]+}}, 12:38 -> 12:42 = #8
// CHECK-NEXT: File {{[0-9]+}}, 13:16 -> 13:42 = #0
// CHECK-NEXT: Expansion,File {{[0-9]+}}, 13:16 -> 13:38 = (#0 - #8)
// CHECK-NEXT: File {{[0-9]+}}, 13:38 -> 13:42 = (#0 - #8)
+// CHECK-NEXT: File {{[0-9]+}}, 3:17 -> 3:20 = (#0 - #9)
+// CHECK-NEXT: File {{[0-9]+}}, 3:17 -> 3:20 = (#0 - #11)
// CHECK-NEXT: File {{[0-9]+}}, 11:32 -> 11:36 = #8
// CHECK-NEXT: File {{[0-9]+}}, 11:32 -> 11:36 = (#0 - #8)
OpenPOWER on IntegriCloud